【问题标题】:CSS: absolute and relative nested within relative, overlapCSS:绝对和相对嵌套在相对中,重叠
【发布时间】:2016-12-22 23:43:16
【问题描述】:

我正在尝试在 html/css 中创建一个框(其中的 div 彼此相对),其中读取更多超链接文本(相对定位),覆盖背景图像(绝对)。这样就可以在描述中添加更多的文字,框而不是重叠图像。

Example of the current issue.

如您所见,描述忽略了图像位置和重叠。

有谁知道我将如何制作它,以便它推动阅读更多和下面的图像,而不是重叠?

html 代码:

        <div class="box">
            <div class="box-cont">
                <span class="content-type"></span>
                <h2 itemprop="name">Test limit thingTest limit thingTest limit thingTest limit thingTest..</h2>
                <p class="meta">By random name,  and random,  on 7 Random 2018</p>

                <p class="desc" itemprop="description">Look, just because I don't be givin' no man a foot massage don't make it right for Marsellus to throw Antwone into a glass ************' house, ******' up th

                <span class="img"><img src="/assets/image.jpg" alt="Screen bw"></span>

                <p class="cta"><span>+ read more</span></p>

            </div>
        </div>
    </a>

css 代码:

box-wrap {
    margin-bottom: 10px;
    display: block;
    text-decoration: none;
    color: #1e5373;
}

.section-boxes .box {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

box p, .box h2, .box .content-type {
    position: relative;
    z-index: 2;
}

.box .img img {
    display: block;
    width: 100%;
    height: auto;
}
img {
    max-width: 100%;
    height: auto;
}

.section-boxes .box .cta {
    position: absolute;
    bottom: 30px;
}

这是我通过实际控制盒子中的一些/大部分定位而设法过滤的内容。描述的 z-index 较高,这就是它与阅读更多框重叠的原因。

【问题讨论】:

  • 分享一些代码,以便有人可以帮助您。
  • 分享你的代码
  • aavrug,我也很喜欢,代码严重分散在不同页面的负载中(我没有写),即使是一个模糊的答案也会为我指明正确的方向现在,说实话。
  • 你好。您要做的是向我们提供与问题相关的 HTML 和 CSS。 (我们不想要也不需要全部)在不知道当前设置的情况下,几乎不可能为您提供任何帮助。

标签: html css sass


【解决方案1】:

根据您的编辑进行编辑: CSS 中的修改在下面注释。

然后把&lt;p class="cta"&gt;&lt;span&gt;+ read more&lt;/span&gt;&lt;/p&gt;放在&lt;div class="img"&gt;&lt;img src="/assets/image.jpg" alt="Screen bw"&gt;&lt;/div&gt;上面。

在打开 &lt;p class="cta"&gt; 之前,您还缺少关闭 &lt;/p&gt;

使用此设置,+read more 将与背景图像重叠,但不与描述重叠(尝试在描述中添加更多文本,您会看到它会将+read more 和背景图像向下推)。

box-wrap {
  margin-bottom: 10px;
  display: block;
  text-decoration: none;
  color: #1e5373;
}
.cta {
  background: yellow;
}
.section-boxes .box {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
box p,
.box h2,
.box .content-type {
  position: relative;
  z-index: 2;
}
.box .img img {
  display: block;
  width: 100%;
  height: auto;
}
img {
  max-width: 100%;
  height: auto;
  /* add these, adjust margin as desired*/
  margin-top: -34px;
  position: absolute;
  right: 0;
  z-index: -1;
}
.section-boxes .box .cta {
  position: absolute;
  bottom: 30px;
}
<div class="box boxed-">
  <div class="box-cont">
    <span class="content-type"></span>
    <h2 itemprop="name">Test limit thingTest limit thingTest limit thingTest limit thingTest..</h2>
    <p class="meta">By random name, and random, on 7 Random 2018</p>
    <p class="desc" itemprop="description">Look, just because I don't be givin' no man a foot massage don't make it right for Marsellus to throw Antwone into a glass ************' house, ******' up th</p>
    <p class="cta"><span>+ read more</span>
    </p>
    <div class="img">
      <img src="/assets/image.jpg" alt="Screen bw">
    </div>
  </div>
</div>

【讨论】:

  • 谢谢,会试用并报告!
  • 嘿 Syden,这似乎没有用,因为我想阅读更多重叠但不是描述。我会尝试解决这个问题,并在找到解决方案并且我决心找到解决方案后报告。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-30
  • 2012-03-27
  • 2011-09-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多