Forum Moderators: not2easy

Message Too Old, No Replies

div width with dynamic content

         

cameraguy

9:49 pm on Jul 14, 2005 (gmt 0)

10+ Year Member



Here is my problem:

I have a div for which I cannot set a width value since its content is dynamic. Furthermore I need to position this div relative to other elements of the page.

div#poem {
background-color:#CC33FF;
position: relative;
}

My problem is that the background color of this div is not limited to the area covered by the text, but runs all the way to the right hand side of the page.

----------------------------------------------------------------------------------
¦Dynamic text:
¦I don't know
¦how large it is!
----------------------------------------------------------------------------------

If I use 'position:absolute' the background will be nicely contained, but the div will interfere with other elements positioned on the page.

So, my questions is: how can I have a contained background and border for a div while positioning it relatively?

-----------------
¦Dynamic text:
¦I don't know
¦how large it is!
-----------------

I hope you can help.

D_Blackwell

1:10 am on Jul 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Will it work for you to position relatively, and float?

div#poem {
background-color:#c3f;
position: relative;

float: left;
border: .1em solid #000;
}

cameraguy

7:07 am on Jul 16, 2005 (gmt 0)

10+ Year Member



WOW! Apparently that did it! I still need to check this thoroughly but at first glance it works.

I had found another solution which involved containing the main div within a on-line one-cell table, but my objective was to adopt a CSS-only solution and you helped me do that.

Thanks!