×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

An element (div) enclosed by "border"

An element (div) enclosed by "border"

An element (div) enclosed by "border"

(OP)
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

RE: An element (div) enclosed by "border"

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

RE: An element (div) enclosed by "border"

(OP)
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 --> display:inline-block;

 
Did it for me and I'm truely gratreful to you!

RE: An element (div) enclosed by "border"

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close