Getting image to stretch a div

前端 未结 7 437
被撕碎了的回忆
被撕碎了的回忆 2021-02-04 00:34

How can I get an image to stretch the height of a DIV class?

Currently it looks like this:

相关标签:
7条回答
  • 2021-02-04 00:52

    Add overflow:auto; to .product1

    0 讨论(0)
  • 2021-02-04 01:02

    Assuming @John Millikin is correct, the code

    .product + * { clear: left; }
    

    would suffice to do the same thing without forcing you to manually adjust the code after the div.

    0 讨论(0)
  • 2021-02-04 01:04

    Try the following:

    .Strech
    {
        background:url(image.jpg);
        background-size:100% 100%;
        background-repeat:no-repeat;
    
        width:500px;
        height:500px;
    }
    
    0 讨论(0)
  • 2021-02-04 01:05

    One trick you can use is to set the <div>'s overflow property to hidden. This forces browsers to calculate the physical size of the box, and fixes the weird overlap problem with the floated image. It will save you from adding in any extra HTML markup.

    Here's how the class should look:

    .product1 {
        width: 100%;
        padding: 5px;
        margin: 0px 0px 15px -5px;
        background: #ADA19A;
        color: #000000;
        min-height: 100px;
        overflow: hidden;
    }
    
    0 讨论(0)
  • 2021-02-04 01:14

    In the markup after the image, insert something like <div style="clear:left"/>. A bit messy, but it's the easiest way I've found.

    And while you're at it, put a bit of margin on that image so the text doesn't butt up against it.

    0 讨论(0)
  • 2021-02-04 01:15
    display:inline  
    float:left  
    

    is your problem

    Floating makes the parents width not be stretched by the child, try placing the image without the float. If you take the float off, it should give you the desired effect.
    Another approach would be to make sure you are clearing your floats at the end of the parent element so that they don't scope creep.

    Update: After viewing your link Your height issue as displayed, is because the floats are not being cleared.

    0 讨论(0)
提交回复
热议问题