CSS - How to align image left bottom to the text block?

后端 未结 5 870
感动是毒
感动是毒 2020-12-20 18:37

\"alt

As this image ?

相关标签:
5条回答
  • 2020-12-20 19:02

    You would use:

    float: left; 
    position: absolute;
    bottom: 0px;
    
    0 讨论(0)
  • 2020-12-20 19:03

    That is not possible in HTML/CSS.

    Absolute positioning allows placement like that, but you should ensure other content not clashing with it - no text flowing around.

    Float mechanism gives you flowing around, but only allows placing float on the horizontal level of its "anchor" - no positioning but left/right..

    0 讨论(0)
  • 2020-12-20 19:03

    It is possible, I have come up with a right top placed image, not bottom left, maybe you can work around with it.

    .wrap-box {
        width: 400px;
        text-align: justify;
    }
    
    .wrap-box img {
        float: right;
        padding: 0 0 5px 5px;
        height: 80px;
        width: 80px;
    }
    

    The box:

    <div class="wrap-box"> 
    <img src="http://farm5.static.flickr.com/4020/4656328142_faab111247.jpg"> 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 scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </div>
    
    0 讨论(0)
  • 2020-12-20 19:08

    That is now possible using CSS Shapes with either known container height or the use of js.

    You need a floated 100% height image container:

    height: 100%; /* either js or known parent height */
    float: left;
    width: 100px;
    

    Actual shape of the float is a bottom-aligned rectangle defined by shape-outside property:

    shape-outside: polygon(
       0 100%,                  /* bottom left point */
       100px 100%,              /* 100px to the right */
       100px calc(100% - 100px) /* 100px above the bottom */
    );
    

    var text = document.querySelector('.text');
    
    // setting container height + some extra space to compensate for the "image"
    text.style.height = (text.clientHeight + 20) + 'px';
    .text {
      columns: 2;
      /* also works with columns! */
      -webkit-columns: 2;
      width: 600px;
    }
    .text-known-height {
      height: 230px;
      width: 400px;
    }
    .text p {
      margin-bottom: 10px;
      margin-top: 0;
    }
    .float-bottom {
      background: rgba(0, 0, 0, 0.1);
      width: 100px;
      height: 100%;
      position: relative;
    }
    .float-right {
      float: right;
      shape-outside: polygon(100% 100%,
      /* bottom right point */
      calc(100% - 100px) 100%,
      /* 100px from right edge */
      calc(100% - 100px) calc(100% - 100px));
    }
    .float-right .image {
      right: 0;
      left: auto;
    }
    .float-left {
      float: left;
      shape-outside: polygon(0 100%,
      /* bottom left point */
      100px 100%,
      /* 100px to the right */
      100px calc(100% - 100px)
      /* point 100px above the bottom */
      );
    }
    .image {
      position: absolute;
      bottom: 0;
      left: 0;
      width: 90px;
      height: 90px;
      line-height: 90px;
      text-align: center;
      color: white;
      background: #7233B6;
    }
    <!DOCTYPE html>
    <html>
    
    <head>
      <meta charset="utf-8">
      <title>JS Bin</title>
    </head>
    
    <body>
    
      <h3>Unknown height container</h3>
      <div class="text">
        <div class="float-bottom float-left">
          <div class="image">image</div>
        </div>
        <p>
          Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec neque lacinia, fermentum neque quis, feugiat erat. Nam et sem aliquam, placerat nulla eu, lobortis enim. Nulla ut semper urna. Sed et diam arcu. Vestibulum ante ipsum primis in faucibus
          orci luctus et ultrices posuere cubilia Curae; Duis sodales, ex a euismod dignissim, magna nulla egestas urna, non fringilla velit lorem ornare turpis. Sed nibh ipsum, iaculis nec mi sed, tincidunt ultrices magna. Nulla posuere orci erat, id fringilla
          magna hendrerit id. Etiam vestibulum arcu feugiat risus lacinia pretium. Donec ut nisi vitae tortor faucibus bibendum eu ac massa. Pellentesque ac magna eget nunc efficitur ultrices nec in ipsum. Praesent interdum elementum turpis.
          <p>
            Sed suscipit nulla eu dapibus dignissim. Vestibulum scelerisque sed turpis eget ultrices. Ut ut pharetra ex. Nam hendrerit magna a varius vehicula. Nunc risus dui, dictum et ex quis, viverra interdum sem. Proin varius sapien ipsum. Maecenas felis purus,
            egestas a massa non, pharetra vulputate tellus. Suspendisse potenti. Sed viverra aliquam iaculis. Quisque non diam sapien. Curabitur semper velit non urna congue, at consectetur turpis finibus.
      </div>
    
      <h3>Known height</h3>
      <div class="text-known-height">
        <div class="float-bottom float-right">
          <div class="image">image</div>
        </div>
        <p>
          Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec neque lacinia, fermentum neque quis, feugiat erat. Nam et sem aliquam, placerat nulla eu, lobortis enim. Nulla ut semper urna. Sed et diam arcu. Vestibulum ante ipsum primis in faucibus
          orci luctus et ultrices posuere cubilia Curae; Duis sodales, ex a euismod dignissim, magna nulla egestas urna, non fringilla velit lorem ornare turpis. Sed nibh ipsum, iaculis nec mi sed, tincidunt ultrices magna. Nulla posuere orci erat, id fringilla
          magna hendrerit id. Etiam vestibulum arcu feugiat risus lacinia pretium. Donec ut nisi vitae tortor faucibus bibendum eu ac massa.
      </div>
    
    </body>
    
    </html>

    0 讨论(0)
  • 2020-12-20 19:09

    Add following style to image

    float: left; 
    padding-right:10px;
    padding-top:10px;
    position:absolute,
    bottom: 10px;
    
    0 讨论(0)
提交回复
热议问题