Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 515655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:39:01+00:00 2026-05-13T07:39:01+00:00

I need a div with a border to wrap around arbitrarily sized fixed-width content

  • 0

I need a div with a border to wrap around arbitrarily sized fixed-width content (this means I do not know what that fixed width will be, it changes from page to page).

The below html does what I’d expect in IE 6, that is, if you size the browser window down to less than the width of the content (in this case a fixed-width <p>, but it could be any fixed width content), the div with the border stops shrinking at the right-hand edge of the content. However, in IE 7 (and FF), the border continues to shrink down to stay within the browser window’s width, going behind and showing through the content.

Is there a way to make the div shrink and grow with the browser window, but never have a width less than the content?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 
  Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

  <head>
    <title>Border Test</title>
  </head>

  <body>
    <div style="border: 1px #0000FF solid;padding:3px;">
      <p style="width:700px;">
        Lorem ipsum dolor sit amet, consectetur 
        adipiscing elit. Praesent varius mi a leo
        ultrices consequat. Nam id venenatis ligula. 
        Suspendisse et faucibus eros. Donec quis 
        augue eu nunc cursus blandit vel vel odio.
        Suspendisse rutrum aliquet massa, eu ultricies
        elit laoreet a. Curabitur feugiat cursus.
      </p>
    </div>
  </body>
</html>

Update: I did some poking around in IE 8, and display:table in the <div> style declaration fixes it there.

<div style="border: 1px #0000FF solid;padding:3px;display:table;">

Is there any way to simulate display:table in IE 7?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:39:02+00:00Added an answer on May 13, 2026 at 7:39 am

    add “overflow:auto” to the parent div, so…

    <div id="parentDiv" style="border: 1px #0000FF solid;padding:3px;overflow:auto;">  should make it work.
    

    This way, you have the best solution CSS can offer. Now, as for your powerusers, use this bit of jquery to give the parent div the proper width, according to its child div.

    Note that i give your divs a class so i can easily target them.

    <body>
        <div class="parentDiv" style="border: 1px #0000FF solid;padding:3px;overflow:auto;">
          <p style="width:700px;">
            Lorem ipsum dolor sit amet, consectetur 
            adipiscing elit. Praesent varius mi a leo
            ultrices consequat. Nam id venenatis ligula. 
            Suspendisse et faucibus eros. Donec quis 
            augue eu nunc cursus blandit vel vel odio.
            Suspendisse rutrum aliquet massa, eu ultricies
            elit laoreet a. Curabitur feugiat cursus.
          </p>
        </div>
    <script type="text/javascript">
    $(function(){
       $('.parentDiv').each(function(){
          var newWidth = $(this).find('p:first').width();
          $(this).width(newWidth);
       });
    });
    
    </script>
      </body>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 278k
  • Answers 278k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You could just set it explicitly in your handler: success… May 13, 2026 at 3:15 pm
  • Editorial Team
    Editorial Team added an answer Your has function should probably look like this: if (c[val]!=null… May 13, 2026 at 3:15 pm
  • Editorial Team
    Editorial Team added an answer You're dealing with a pre-standard C++ library, and you've seen… May 13, 2026 at 3:15 pm

Related Questions

I have a cleared <hr> tag with margins top and bottom. However, after two
I came across an interesting problem today. I have a text email I'm sending
I'm trying to create a jQuery plugin, inside I need to do an AJAX
I'm trying to use the CSS word-wrap property with break-word value. I want to
I'd like to ensure that there's never a line break between a radio button

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.