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 7704091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:36:26+00:00 2026-05-31T23:36:26+00:00

I am displaying two DIV panels with the code below. The only difference between

  • 0

I am displaying two DIV panels with the code below. The only difference between the two panels is that the SPAN element within the first DIV element has a font-size: 14px style applied to it while that of the second DIV element doesn’t have this style. On Firefox as well as Chrome the first panel appears to have a greater height than the second one. Here is a demo URL: http://jsfiddle.net/UWX2u/

A copy of the code follows:

<!DOCTYPE html>
<html>
<head>
<title>Margin border</title>
<style type="text/css">
body {
    line-height: 38px;
    font-size: 32px;
}

#panel1 {
    background: #00a000;
    float: left;
}

#panel2 {
    background: orange;
    float: left;
}

#panel1 p span {
    font-size: 14px;
}
</style>
</head>
<body>

    <div id="panel1">
        <p>Foo <span>Bar</span></p>
    </div>

    <div id="panel2">
        <p>Foo <span>Bar</span></p>
    </div>

</body>
</html>

With Firebug I could see that the computed height of the P element in the first DIV is 44.1833px while that of the P element in the second DIV is 38px. Why does this difference occur?

If I remove the line-height: 38px property from the CSS, both DIV elements have the same height. Here is a page that demonstrates this: http://jsfiddle.net/FJUDn/

  • 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-31T23:36:27+00:00Added an answer on May 31, 2026 at 11:36 pm

    As to “Why” it Happens

    According to W3C (bold emphasis added),

    ‘line-height’ specifies the minimal height of line boxes within the
    element. The minimum height consists of a minimum height above the
    baseline and a minimum depth below it … The height and depth of the font above
    and below the baseline are assumed to be metrics that are contained in the font.

    So what this tells me is that

    1) the line-height can go taller if need be (it is just a minimum), and

    2) your shrinking of the font would seem to be shifting how the font applies the minimum above and below the baseline of the span for the line-height: 38px. Apparently the smaller font size redistributes more spacing below the baseline of the smaller font, pushing the p tag taller. This seems confirmed in that if you add to the span a vertical-align: top as I did here, then the baseline shifts up for the smaller font, and no size change occurs in the p tag.

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

Sidebar

Related Questions

Here i am having a unordered list displaying two columns code and name .I
I have created a image div in html and below is the code <div
I have two different ways of displaying items in a WPF application. The first
I'm building my very first iPhone application. It's pretty simple, I'm displaying two lists
I have these two snippets, the first for displaying a customized post order via
Here is my scenario. I have a container div that has (n) child elements
is the syntax of the jquery correct? the first two lines in the code
I have a databound listbox which is actually displaying two columns of data. It
I have two plots displaying supply and demand, and one plot in which I
I`ve a problem with grouping and displaying results from two tables in MySQL db.

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.