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

  • Home
  • SEARCH
  • 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 879839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:59:51+00:00 2026-05-15T11:59:51+00:00

I was trying to get my div that contains floating elements, to enlarge to

  • 0

I was trying to get my div that contains floating elements, to enlarge to encompass them, but it doesn’t seem to pay attention to the padding of the elements, effectively chopping them off. How can I get the div to be the correct height for my list items?

html:

<html>
  <head>
    <link type="text/css" rel="stylesheet" href="/stylesheets/test.css" />
  </head>

  <body>
    <div class="nav">
      <ul class="nav">
        <li class="nav"><a class="nav" href="#">One1</a></li>
        <li class="nav"><a class="nav" href="#">Two</a></li>
        <li class="nav"><a class="nav" href="#">Three</a></li>
        <li class="nav"><a class="nav" href="#">Four</a></li>
      </ul>
    </div>

    <div class="after"><h2>Heading</h2></div>
  </body>
</html>

css:

ul.nav, ul li.nav {
  display: inline;
  margin: 0px;
  padding: 0px;
}

ul.nav {
  list-style-type: none;
}

li.nav {
  display: block;
  float: left;
  background-color: red;
}

a.nav {
  background-color: green;
  padding: 10px;
  margin: 0;
}

a:hover.nav {
  background-color: gray;
}

div.nav {
  background-color: blue;
  overflow: hidden;
  width: 100%;
}

div.after {
  clear: left;
}
  • 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-15T11:59:52+00:00Added an answer on May 15, 2026 at 11:59 am

    I’m going in the same direction edl is: a, as an inline element, does not have vertical padding.

    However, IE up to IE 7 does not work well with display: inline-block (see http://www.quirksmode.org/css/display.html), so I recommend you set your links to display: block. Your list items are already floated, so it doesn’t make a difference.

    On a related note, I would also recommend you change your markup and stylesheet for clarity and readability:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
      "http://www.w3.org/TR/html4/strict.dtd">
    <html>
      <head>
        <title>Title</title> 
    
        <link type="text/css" rel="stylesheet" href="/stylesheets/test.css">
      </head>
    
      <body>
        <ul id="nav">
          <li><a href="#">One</a></li>
          <li><a href="#">Two</a></li>
          <li><a href="#">Three</a></li>
          <li><a href="#">Four</a></li>
        </ul>
    
        <h2>Heading</h2>
      </body>
    </html>
    

    and

    #nav {
      background-color: blue;
      list-style-type: none;
      margin: 0;
      overflow: hidden;
      padding: 0;
      width: 100%;
    }
    
    #nav li {
      background-color: red;
      float: left;
    }
    
    #nav li a {
      background-color: green;
      display: block;
      padding: 10px;
    }
    
    #nav li a:hover {
      background-color: gray;
    }
    

    Not every element needs to have a class, and using the same name for different purposes based on their tags will just induce a lot of headache later on. Just give the main element an ID and have your rules originate from there.

    That way, you can also get rid of unnecessary divs, simplifying your markup.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get a list of values within a div that I
I'm trying to get a DIV element into a table cell, in a way
I'm trying to get: document.createElement('div') //=> true {tagName: 'foobar something'} //=> false In my
I'm trying to get the source attribute of all images withing a specific div
I'm trying to work out how to get a div (#tips) to appear when
Trying to get an ASP application deployed; it worked for a while but then
I have a gallery type of interface that I'm trying to get to work,
I am trying to setup a menu with sub menu that contains ul. My
I'm trying to add a button that contains the .closest & .remove into an
I'm trying to get an XPath expression together that will give me all the

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.