www.webdeveloper.com
Results 1 to 3 of 3

Thread: width:auto question (This should be easy!)

  1. #1
    Join Date
    Oct 2005
    Posts
    59

    width:auto question (This should be easy!)

    In this page, I want the outer div (with the green border) to automatically be as small as the div within it. In this case, as small as the "hi". I have the inner div set to width:auto; margin:0 auto.

    If I set the inner div to a width, then the outer div shrinks to that width. But at width:auto, the width goes to 100%.

    This is the code:

    Code:
    <div style="width:100%;text-align:center;">
    	<div style="width:auto;margin:0 auto;border:10px solid green;">
        	hi
       	</div>
    </div>
    This is the URL:

    http://littleduck.com/test.html

    I'd think that width:auto would tell the inner div to be only as wide as the content within it, but no. What's the workaround here? I can not set a width for this div.

    Thank you!

  2. #2
    Join Date
    Oct 2005
    Posts
    59
    (Sorry, I mistyped ... the green border is around the inner div. Regardless, what I want is for the border to just be around the little "hi" without having to set a width for the div.)

  3. #3
    Join Date
    Oct 2010
    Location
    Ohio
    Posts
    233
    you could do the border on the element itself

    HTML Code:
    <div style="width:100&#37;;text-align:center;">
    	<span style="border:10px solid green;">
        	hi
       	</span>
    </div>
    you could use p or h* or whatever.
    ~Ryan
    www.rdennispallas.com <-- Personal Site, changing regularly cuz its ugly.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles