如何使修改此css [已关闭]

fnatzsnv  于 2022-12-15  发布在  其他
关注(0)|答案(2)|浏览(120)

**已关闭。**此问题需要debugging details。当前不接受答案。

编辑问题以包含desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答问题。
6天前关闭。
这篇文章是编辑和提交审查2天前。
Improve this question
我正在考虑使用[这段css][1],但是我不希望文本这么快就换行。我希望它占据图像宽度的80%。我需要修改什么才能做到这一点?
超文本标记语言:

<h3>Hover over the image to see the effect.</h3>

<div class="container">
  <img src="https://walter.trakt.tv/images/movies/000/472/401/fanarts/thumb/ae10b31b1f.jpg.webp" alt="Avatar" class="image" style="width:100%">
  <div class="textbox">
    <div class="text">Each Christmas Eve, the Ghost of Christmas Present selects one dark soul to be reformed by a visit from three spirits. But this season, he picked the wrong Scrooge. Clint Briggs turns the tables on his ghostly host until Present finds himself reexamining his own past, present and future.</div>
  </div>
</div>

CSS:

.container {
  position: relative;
  width: 500px;
}

.image {
  opacity: 1;
  display: block;
  width: 100%;
  height: auto;
  transition: .5s ease;
  backface-visibility: hidden;
}

.textbox {
  transition: .5s ease;
  opacity: 0;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  text-align: center;
}

.container:hover .image {
  opacity: 0.3;
}

.container:hover .textbox {
  opacity: 1;
}

.text {
  background-color: #04AA5D;
  color: white;
  font-size: 15px;
  padding: 10px 10px;
}
toe95027

toe950271#

只需修改('. textbox')类的width属性。这将导致文本区域占用图像上更多的空间,并且不会很快换行。如果你尝试在fiddle中测试它,只需确保在修改后点击左上角的'run'命令即可。

.textbox {
      transition: .5s ease;
      opacity: 0;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      -ms-transform: translate(-50%, -50%);
      text-align: center;
      width: 80%;
    }
jc3wubiy

jc3wubiy2#

width: 80%添加到文本框css

.container {
  position: relative;
  width: 500px;
}

.image {
  opacity: 1;
  display: block;
  width: 100%;
  height: auto;
  transition: .5s ease;
  backface-visibility: hidden;
}

.textbox {
  width: 80%;
  transition: .5s ease;
  opacity: 0;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  text-align: center;
}

.container:hover .image {
  opacity: 0.3;
}

.container:hover .textbox {
  opacity: 1;
}

.text {
  background-color: #04AA5D;
  color: white;
  font-size: 15px;
  padding: 10px 10px;
}
<h3>Hover over the image to see the effect.</h3>

<div class="container">
  <img src="https://walter.trakt.tv/images/movies/000/472/401/fanarts/thumb/ae10b31b1f.jpg.webp" alt="Avatar" class="image" style="width:100%">
  <div class="textbox">
    <div class="text">Each Christmas Eve, the Ghost of Christmas Present selects one dark soul to be reformed by a visit from three spirits. But this season, he picked the wrong Scrooge. Clint Briggs turns the tables on his ghostly host until Present finds himself reexamining his own past, present and future.</div>
  </div>
</div>

相关问题