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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:28:40+00:00 2026-06-14T04:28:40+00:00

I have a div with height 50px that contains a child div. The height

  • 0

I have a div with height 50px that contains a child div. The height of the child div is inherited from the parent by using the css attribute/value pair: height: 100%.

    <div style="height: 50px;">
        <div style="height: 100%;">Some Text</div>
    </div>            

I want to verically align the text in the child div and to do so I add the line-height property to the child div.

    <div style="height: 50px;">
        <div style="height: 100%; line-height: 50px;">Some Text</div>
    </div>            

Notice that for line-height I have to explicitly define the height as 50px.

The child div can inherit the height property from the parent (using height: 100%) but for line-height I must explicitly set the value?

If so, this is (IMO) kindof messy because let’s say I have a div that is nested 10 levels deep and it inherits the height property all the way down. Then if I want to vertically align the text within this div I have to not only hard-code the value to equal the height of the upper-most parent div but I have navigate through my code to find the parent that explicitly defines the height.

Note that I don’t want to define line-height at the parent level and then use inherit at the child node to get the value.

It would be nice if there were a way to set line-height equal to the height of the div that it resides in. Perhaps the syntax would look like the following (totally made up):

<div style="height: 100%; line-height: from-property('height');">Some Text</div>

Where line-height uses the from-property method to access the height property. (Yes, I know having a method such as from-property introduces the potential for a circular dependency so perhaps some other way would be better. I am simply using it to express what I would like to have.)

Thanks!

Jan

  • 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-14T04:28:41+00:00Added an answer on June 14, 2026 at 4:28 am

    You could use jQuery to work out the height of the parent() and then to add line-height dynamically based on that height?

    It would look something like:

    $(document).ready(function(){
    
        $('.lineHeightDiv').each(function(){
            var div_height = $(this).parent('div').height();
            $(this).css('lineHeight', (div_height / 2) + "px");
        });
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If you have a parent div that wraps a fixed height div and a
i have one fixed div and that is placed on page using css. i
I have div ( #child ) which won't expand to the full height of
Consider that we have a DIV with fixed height. Without a defined width ,
It seems that in Firefox, if I have div A with fixed width/height and
I have a div that expands to the height of it's content. It works
I have a Div that is 400px in height with the ID content, I
I have a wrapper div element that contains a div that in turns contains
Say you have a 50px by 50px div/box <div style=width: 50px; height: 50px;> </div>
I have a div with a child div inside it. I'm using jQuery to

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.