1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

CSS image in a div tag overlaps the border

Discussion in 'CSS' started by fadetoblack22, Nov 21, 2008.

  1. #1
    My problem is that my image on the left does not push the div container it is in like the text does. How do I make it do that?

    [​IMG]

    CSS:

    .reviewbox {
    background-color: #D3D7DB;
    border: 1px solid #0C4A92;
    width: 776px;
    margin: 0 0 10px 0;
    }

    .reviewimg {width: 100px; height: 100px; position: absolute;}

    .reviewbox img {padding: 10px 0 0 10px;}

    .reviewbox p {padding-left: 100px; width: 666px;}

    html:

    <div class="reviewbox">

    <div class="reviewimg"><img src=""></div>

    <p>
    text goes here.
    </p>

    </div>


    thanks.

    Edit: I can't put a reviewbox height because on different pages there is different amounts of text.
     
    fadetoblack22, Nov 21, 2008 IP
  2. judge0

    judge0 Peon

    Messages:
    400
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try get rid of the
    height:100px;
    position:absolute;
    Code (markup):
     
    judge0, Nov 21, 2008 IP
  3. gwkg

    gwkg Peon

    Messages:
    143
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It doesn't work with IE6 and lower, but you can use min-height on the review box to set the minimum height.


    min-height:120px;


    When there is more text it will expand, when there is little text, it will be the height you specify.

    There are a couple hacks for IE6 and below

    http://www.greywyvern.com/code/min-height-hack
     
    gwkg, Nov 21, 2008 IP
  4. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #4
    that doesn't work. it just pushes the text down so it is not inline with the image.
     
    fadetoblack22, Nov 21, 2008 IP
  5. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #5
    I'd rather not use hacks for something that seems so simple. there must be a better way to do this. I was wondering how the text can push the box down but not the image?
     
    fadetoblack22, Nov 21, 2008 IP
  6. 007c

    007c Peon

    Messages:
    611
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Just use floats, very simple contain around your text and float all 3 divs left or make sure .reviewbox has layout and float the text and img div. There's a few other ways but imo that's the simplest.
     
    007c, Nov 21, 2008 IP
  7. cipals15

    cipals15 Well-Known Member

    Messages:
    1,085
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    100
    #7
    You should use a fixed height.
    Make your review box content into a frame.
    Place a continue link that display the next portion of the texts.
     
    cipals15, Nov 21, 2008 IP
  8. judge0

    judge0 Peon

    Messages:
    400
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #8
    <style>
    .reviewimg {
    background-color: #D3D7DB;
    border: 1px solid #0C4A92;
    width: 776px;
    margin: 0 0 10px 0;
    }
    .reviewimg img {padding: 10px 0 0 10px; float:right}
    .reviewimg p {padding-left: 100px; width: 666px; clear:both}
    </style>
    <div class="reviewimg">
    <img  src="images/photo_03.gif"/>
    <p>This element encloses text which is intended to be taken from another source--a long quotation. Note that browsers will not automatically put in quotation marks around the quoted test. Some browsers don't indent quoted text very much; some developers put quotes around the text to make sure the quotation is properly indicated.
    This element encloses text which is intended to be taken from another source--a long quotation. Note that browsers will not automatically put in quotation marks around the quoted test. Some browsers don't indent quoted text very much; some developers put quotes around the text to make sure the quotation is properly indicated.
    </p>
    </div>
    Code (markup):
    really this my try is it work for u
     
    judge0, Nov 21, 2008 IP
  9. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #9

    thanks, it didn't work, but I changed some things around and came up with this and it worked.

    .reviewimg {
    background-color: #D3D7DB;
    border: 1px solid #0C4A92;
    width: 776px;
    margin: 0 0 10px 0;
    }
    .reviewimg img {padding: 12px 0 0 10px; float:left;}
    .reviewimg p {padding-left: 16px; width: 652px; float: left;}

    I also added a div with a clear:both before closing the .reviewimage
     
    fadetoblack22, Nov 21, 2008 IP
  10. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #10
    There is still one problem I need help with though.

    In IE all <p> text is pushed to the top of its container with no gap.

    However in FireFox the <p> text has a nice gap at the top.

    How do I set a value for this in the stylesheet so that it both does the same thing?

    thanks.
     
    fadetoblack22, Nov 21, 2008 IP
  11. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Man, I can't believe what was going on with this code earlier-- the first response was the right one-- when you absolutely position something, it's NOT in the page anymore-- that's why it can't push down the box. The box doesn't know its there! Content on a page can't see absolutely positioned things and absolutely positioned things only see their nearest positioned ancestor.
    The min-height one could have worked, though it's only covering up for the fact that the img was absolutely positioned.

    The clearing div when you floated the img (you don't have to float the p too unless you didn't want it to wrap under the image if it got longer than the img) does work, but it's kinda frowned upon because it means you're adding extra markup in the html. There are ways to do this in CSS too, if you want.
    Take a look.

    Anyway, the p-- did you remove all default margins and padding from p's? Cause I'm wondering if it's FF has padding or margin by default on the p's while IE doesn't.

    You can also have top-padding on the reviewbox itself, though this may push your img down too far since it also has padding on the top-- but I like using padding-top on containers instead of the children because it'll push all children down by the same amount and I wouldn't have to write so much code setting padding on all the children.
     
    Stomme poes, Nov 22, 2008 IP
  12. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #12
    Thanks, I didn't really know what I was doing with the absolute position. It was just a guess to try and get it to work. Obviously it didn't.

    Post number 7 was the randomest lol. I've never had one which suggests something that odd.

    thanks for the link as well.
     
    fadetoblack22, Nov 22, 2008 IP
  13. greenbaret

    greenbaret Peon

    Messages:
    24
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #13
    .reviewbox {
    background-color: #D3D7DB;
    border: 1px solid #0C4A92;
    width: 776px;
    margin: 0;
    padding:0;
    position:relative;
    }

    .reviewbox img {margin: 10px; width: 100px; height: 100px; float:left;}

    .reviewbox p{
    font-family:Arial, Helvetica, sans-serif;
    font-size:12px
    }

    /*to clear float <br class="spacer" />*/
    .spacer{float:none; line-height:0;}
     
    greenbaret, Nov 26, 2008 IP