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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:06:32+00:00 2026-06-18T11:06:32+00:00

I have a div with a known height, in px. In this div, I

  • 0

I have a div with a known height, in px. In this div, I have some text with a known font-size, in px. Now I want to use padding-top to push the text down so it touches the element beneath it. However, it must not extend the div by pushing too far.

How do I calculate the padding? Just subtracting font-size from div-height, causes the div to expand, even if I set line-height:100%. Is there a defined height based on font – is it always the same? Or does it depend on the font-family. I guess it must depend on the font-weight, at least.

(Don’t want to use position:absolute to solve the pushing down problem.)

  • 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-06-18T11:06:34+00:00Added an answer on June 18, 2026 at 11:06 am

    It varies depending on the font family. Each font has a different baseline. If you set the height of the container to match the height of the font then the font will still hang below the container. This can be centered using line-height, however there will still be some space present above and below the font.

    Here is an article which explains this better.

    http://blog.typekit.com/2010/07/14/font-metrics-and-vertical-space-in-css/

    DEMO:

    Also here is demo I started. You can easily tell where the baseline is and how much extra space there is on top. When line-height is set to equal font-size it centers the font vertically. However, as you can see there is still some white space on top and bottom. So the font itself is not exactly the same height as the container.

    HTML

    <h1>ABCDEFGHIJKLMNOPQRSTUVWXYZ</h1>
    <h1>abcdefghijklmnopqrstuvwxyz</h1>
    
    <h2>ABCDEFGHIJKLMNOPQRSTUVWXYZ</h2>
    <h2>abcdefghijklmnopqrstuvwxyz</h2>
    
    <h3>ABCDEFGHIJKLMNOPQRSTUVWXYZ</h3>
    <h3>abcdefghijklmnopqrstuvwxyz</h3>
    
    <h4>ABCDEFGHIJKLMNOPQRSTUVWXYZ</h4>
    <h4>abcdefghijklmnopqrstuvwxyz</h4>
    

    CSS

    h1 { 
        font-family:sans-serif;
        font-size:34px;
        height:34px;
        margin-bottom:5px;
        border:1px solid #CCC;
    }
    
    h2 { 
        font-family:serif;
        font-size:34px;
        height:34px;
        margin-bottom:5px;
        color:blue;
        border:1px solid #CCC;
        line-height:34px; /*NOTE THIS ONE HAS LINE-HEIGHT*/
    }
    
    h3 { 
        font-family:"impact";
        font-size:34px;
        height:34px;
        margin-bottom:5px;
        border:1px solid #CCC;
    }
    
    h4 {
        font-family:"Courier New";
        font-size:34px;
        height:34px;
        margin-bottom:5px;
        border:1px solid #CCC;
    }
    

    FIDDLE URL:

    http://jsfiddle.net/KtY4F/9/

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

Sidebar

Related Questions

Suppose I have div and I want to fetch data and push data into
I have the following piece of HTML page: <div id=main> <div id=description> Some text
I have div ( #child ) which won't expand to the full height of
So currently I have: #div { position: relative; height: 510px; overflow-y: scroll; } However
in my html page I have div with css: padding: 0px; color: rgb(51, 51,
I have a div centered vertically and horizontally in the page. But when this
I'm writing some JavaScript that changes the size of some content. To do this
I have the following issue whith this very simple task. I want to create
I have an <a> surrounding a <div> which also has some images, a <h2>
OK so I have a container div that loads some content which is generated

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.