html - 使用伪元素覆盖

标签 html css

  <div class="box small">
    <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>

    <div class="detail"> for more info click below</div>
    <div class="read-more"> click</div>
 </div>

CSS

.detail{
      position: relative;
}
.detail:after{
  content: "";
  display: block;
  position: fixed; /* could also be absolute */ 
  bottom: 0;
  left: 0;
  height: 100%;
  width: 20%;
  z-index: 10;
  background-color: rgba(0,0,0,0.2)
}  

我想为这两个 div 添加背景:

 <div class="detail"> for more info click below</div>
 <div class="read-more"> click</div>  

我无法添加包装器 div ,所以我使用覆盖技术:

Demo

我如何相对于父框覆盖?

最佳答案

我不知道我是否得到了你想要的,但我认为这是你想要做的

.box {
    padding:20px;
    border:1px solid #000;
    position:relative;
}

.small {
    width:200px;
    height:200px;
}

.detail{
      position: relative;
}
.box:after{
  content: "";
  display: block;
  position: absolute; 
  bottom: 0;
  left: 0;
  z-index: 10;
  background-color: rgba(0,0,0,0.2);
  right:0;
  bottom:0;
    height:100%;
    width:100%;
}

和html

<div class="box small">
    <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>

    <div class="detail"> for more info click below</div>
     <div class="read-more"> click</div>
</div>

关于html - 使用伪元素覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32676178/

相关文章:

javascript - 将数据从数据库插入谷歌图表 codeigniter

html - Bootstrap 图像轮播,文本在右边

javascript - 在 IE8(Javascript 和 CSS)中使用拉伸(stretch) BG 淡化图像背景

css - 当我使用绝对定位来定位我的菜单时,我页面下方的 anchor 标签消失了

javascript - 创建一个链接以在另一个窗口中运行 javascript

jquery - Phonegap - 向右滑动 Facebook 风格的导航/布局

javascript - 如何减少元素边框的长度?

php - 日历自定义 [突出当前月份]

css - 如何在 MUI AppBar 中将 Button 对齐到最右边?

html - 导航栏折叠在 Bootstrap 中不起作用