Results 1 to 3 of 3

Thread: seconds right float doesn't work

  1. #1
    Join Date
    Apr 2009
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default seconds right float doesn't work

    Hi guys, I've trying to achieve the following.

    I want to have a div element floating on the right 100px from the top and the rest of content is filled with text.




    I can achive the following:

    Have the image float on right, but 0px from top, using simple
    Code:
    float:right


    If i put my
    Code:
    p
    elements before the
    Code:
    image
    in my html, the image's position (y-coordinate) will change as the content changes (I want it always 100px from top no matter what).

    I've tried to add another right-floated element with width 10px; (or so) "on top". This places my image correctly, but the the text overflows beneath the floated image (note that if my top div has width greater than my image everything works fine). I've tested this in both FF 3 and IE7 with the same outcome



    Can anyone help me with this ... thank you

    p.s. here's my html

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">

    <
    html>
    <
    head>
    <
    title>float</title>
    <
    style type="text/css"

    .
    content width400pxbackground#FFFF00; padding: 5px; } 
    .floatright floatrightheight100pxborder1px solid #000; } 
    .offset width10px; }
    .
    imgholder width100pxclearright; } 

    </
    style
    </
    head>

    <
    body>

    <
    div class="content">

    <
    div class="floatright offset"></div>
    <
    div class="floatright imgholder"><h1>image</h1></div>

    <
    p>Lorem ipsum dolor sit ametconsectetur adipiscing elitAliquam posuereLorem ipsum dolor sit ametconsectetur adipiscing elit
    Cras ornareVestibulum a nulla id velit elementum imperdietNam a purusSuspendisse non enimNullam id semPellentesque 
    habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas
    Maecenas aliquet varius tellus
    Aliquam sed nunc eu tortor semper vulputateNunc risus.</p>
    <
    p>Lorem ipsum dolor sit ametconsectetur adipiscing elitAliquam posuereLorem ipsum dolor sit ametconsectetur adipiscing elit
    Cras ornareVestibulum a nulla id velit elementum imperdietNam a purusSuspendisse non enimNullam id semPellentesque 
    habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas
    Maecenas aliquet varius tellusAliquam sed nunc 
    eu tortor semper vulputate
    Nunc risus.</p>

    </
    div>

    </
    body>

    </
    html
    Last edited by 3v1l5w1n; 04-23-2009 at 12:32 AM.

  2. #2
    Join Date
    Apr 2009
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    just in case someone is wondering, the trick is to increase the width gradually up to 100px ... I've got around by doing this:

    1.) make all div's clear: right; and float: right;
    2.) get to [my image] 100px "step by step"
    PHP Code:
    <style>
    .
    float-right clearrightfloatright; }
    </
    style>
    ....
    <
    div class="float-right" style="width: 10px; height: 80px; "></div>
    <
    div class="float-right" style="width: 80px; height: 20px; "></div>
    <
    div class="float-right" style="width: 100px; height: 100px; ">[my image]</div>

    <
    p>.... 
    the key seems to be to have the last div before [my image] div sized big enough so that the text can adjust correctly around [my image]

  3. #3
    Join Date
    Apr 2009
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Actually, more elegant css solution seems to be to add some margin-top to the second floated item equal to 1 line-height of the text. I tested in FF and IE7 and it works

    PHP Code:
    .content width400pxbackground#FFFF00; padding:5px; }
    .floatright floatrightheight100px; }
    .
    offset width0px; }
    .
    imgholder width100pxclearrightmargin-top1emborder1px solid #000; } 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •