【问题标题】:Bootstrap 3 image over div with left offset带有左偏移的 div 上的 Bootstrap 3 图像
【发布时间】:2021-02-22 02:11:45
【问题描述】:

我正在尝试制作一张图像向左侧偏移 50% 的卡片。随着相对位置的图像被裁剪。我得到的结果如图所示。

我的 CSS 是

.card2 {
  position: relative;
  margin: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
  border-radius: 6px;
  padding: 1rem;
  overflow: hidden;
  background-color: rgb(255, 255,255,1);
  margin:0px auto;
  width: 80vw;
  height: 60vh;
}


.dvInsideTL {
  position: absolute;
  left:-40px;
  z-index: 100;
}

而html是

<div class="card2">

      <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the 
        industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and 
        </p>
      
          <div class="dvInsideTL">
              <img src="https://via.placeholder.com/250" alt="" />
          </div>
    </div>

【问题讨论】:

    标签: html css placeholder


    【解决方案1】:

    .card2 {
      position: relative;
      margin: 0;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
      border-radius: 6px;
      padding: 1rem;
      overflow: hidden;
      background-color: rgb(255, 255,255,1);
      margin: 0px auto;
      width: 80vw;
      height: 60vh;
      display: flex;
      flex-direction: row-reverse;
      align-items: center;
    }
    .card2 p {
      margin: 0;
      padding-left: 20px;
    }
    
    .dvInsideTL {
      
    }
    <div class="card2">
    
          <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the 
            industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and 
            </p>
          
              <div class="dvInsideTL">
                  <img src="https://via.placeholder.com/250" alt="" />
              </div>
        </div>

    你想要这个吗?

    【讨论】:

    • 有了这个css,div就显示在了背景div里面。如果我将最后一行 translateX 更改为 -150,它将显示顶部 div 50% 并裁剪其他 50%。它应该在背景 div 之外,并且应该显示在顶部。希望我没有听起来令人困惑。
    • mdbootstrap.com/docs/jquery/components/cards 你想要这样的卡片吗?你能告诉我这张卡的划痕吗?
    【解决方案2】:

    你用过bootstrap,那为什么不用列结构

    .card2 {
      position: relative;
      margin: 0;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
      border-radius: 6px;
      padding: 1rem;
      overflow: hidden;
      background-color: rgb(255, 255,255,1);
      margin:0px auto;
      width: 80vw;
      height: 60vh;
    }
    
    
    .dvInsideTL {
      position: absolute;
      left:0px;
      z-index: 100;
    }
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <div class="card2">
      <div class="row">
        <div class="col-xs-6">
          <div class="dvInsideTL">
            <img src="https://via.placeholder.com/250" alt="" />
          </div>
        </div>
        <div class="col-xs-6">
          <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and 
          </p>
        </div>
    </div>

    【讨论】:

    • 两个 div 并排出现。我希望图像在背景 div 之外为 50。
    猜你喜欢
    • 1970-01-01
    • 2014-04-30
    • 1970-01-01
    • 1970-01-01
    • 2018-03-17
    • 2011-03-08
    • 2019-06-22
    • 2016-04-05
    • 2014-03-08
    相关资源
    最近更新 更多