HTML,CSS将div放在左边而不是右边的相对元素

时间:2017-04-04 19:07:19

标签: html css

我有这段代码:



#wrap {
  position: relative;
  width: auto;
  background: silver;
  border: 1px solid grey;
}

#text {
  position: absolute;
  width: 25%;
  right: 0;
  top: 0;
  bottom: 0;
  background: black;
  opacity: 0.5;
  filter: alpha(opacity=50);
}

<div>
  <div id="wrap">
    <img class="fit-img" src="~/Content/img/Assets/image.jpg">
    <div id="text"></div>
  </div>
</div>
&#13;
&#13;
&#13;

我需要在左侧放置ID为text的DIV,而不是包装内容的右侧。有什么提示吗?

1 个答案:

答案 0 :(得分:0)

只需删除right: 0;并将其替换为此处的left: 0;

#text {
  position: absolute;
  width: 25%;
  left: 0;
  top: 0;
  bottom: 0;
  background: black;
  opacity: 0.5;
  filter: alpha(opacity=50);
}