Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

An element (div) enclosed by "border" 1

Status
Not open for further replies.

lupidol

Programmer
Apr 23, 2008
125
IL
Hi everyone,
My "container" div contains various changeable elements such as lists, forms and more within it.
That "container" has a "border" property to confine it's content by a surrounding frame.
I wouldn't like this "frame" to be static, meaning: it shouldn't have a rigid width such as: "100px".
I want its' width to change in accordance with its' content. If the content of that div is 10 px, border's
width should be 10 px etc..
I tried: "width: auto; margin: auto" and recieved the whole display's width as border's width.
Can anyone give me a suggestion of how to create an "elastic" border attribute?
Thanks
 
Without seeing your css and html its hard to offer a suggestion. However under normal circumstances, a div will always be as wide as its parent element. Meaning it will stretch to cover up its parent.

If you want it to not be the entire width of its parent element, you can change its display property to inline-block, and its overflow to auto. and give it a min-width if necessary.

Code:
<!DOCTYPE HTML>
<html>
<style type="text/css">
div.content
{
	display:inline-block;
	border:1px solid red;
}
</style>
<body>

<div class="content">
Lorem ipsum .... Lorem ipsum ....Lorem ipsum ....Lorem ipsum <br>....Lorem ipsum ....Lorem ipsum ....Lorem ipsum ....Lorem ipsum ....
Lorem ipsum ....Lorem ipsum ....Lorem ipsum ....Lorem ipsum <br>....Lorem ipsum ....Lorem ipsum ....Lorem ipsum ....
Lorem ipsum ....Lorem ipsum ....Lorem ipsum ....Lorem ipsum <br>....Lorem ipsum ....Lorem ipsum ....
</div>

</body>

</html>

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Thanks a lot vacunita !
The code is a more complicated then as preseneted here so I hoped I could get a solution without having to present it and I got !!
Code:
Did it for me and I'm truely gratreful to you!
 
No problem, glad I could help.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top