代码之家  ›  专栏  ›  技术社区  ›  Hasan Zubairi

带左偏移的div上的Bootstrap 3图像

  •  0
  • Hasan Zubairi  · 技术社区  · 5 年前

    我试图制作一张图像向左偏移50%的卡片。使用相对位置,图像将被裁剪。我得到的结果如图所示。 enter image description here

    我的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>
    
    2 回复  |  直到 5 年前
        1
  •  0
  •   Minal Chauhan Adriano    5 年前

    您使用了引导,那么为什么不使用列结构呢

    .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>
        2
  •  0
  •   Alchemist    5 年前

    .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>

    你想要这个吗?