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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:21:36+00:00 2026-06-18T07:21:36+00:00

I have a header tag, with a fixed width, that in some instances will

  • 0

I have a header tag, with a fixed width, that in some instances will contain 2 lines of text, in some cases 1. I’d like them to vertically align in the center, as if the padding was already figured out to compensate for this.

I’m hoping to accomplish this without modifying the mark-up.

<h1>This would be 2 lines of text</h1>
<h1>This is 1 line</h1>
<h1>This would be 2 lines of text</h1>
<h1>This is 1 line</h1>
<h1>This would be 2 lines of text</h1>
<h1>This is 1 line</h1>
<h1>This would be 2 lines of text</h1>
<h1>This is 1 line</h1>

CSS:

h1 {
float:left;
margin:5px;
padding:5px;
width:100px;
height:50px;
vertical-align:middle; /*obvi doesn't work because it's not an inline element */
text-align:center;
background:#336699;
color:#fff;
}

Maybe… like a CSS selector that determines 2 different padding properties based on an automatic height? Like, if I set the height to auto, and if the header tag exceeds 60px (what it would be for 2 lines), then make the padding this, but if the automatic height is less than that, then make the padding this….

h1[height>60px] { padding:10px 0px; }
h1[height<60px] { padding:20px 0px; }

I hope that makes sense. I’m just not sure how to write it… or is there a better way?

Please see example.

http://jsfiddle.net/KcD3v/

Many thanks SO

  • 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-18T07:21:37+00:00Added an answer on June 18, 2026 at 7:21 am

    You can try to do something like that:

    HTML

    <div class="header">
        <h1>This would be 2 lines of text</h1>
        <h1>This is 1 line</h1>
        <h1>This would be 2 lines of text</h1>
        <h1>This is 1 line</h1>
        <h1>This would be 2 lines of text</h1>
        <h1>This is 1 line</h1>
        <h1>This would be 2 lines of text</h1>
        <h1>This is 1 line</h1>
    </div>
    

    CSS

    .header {
        display: inline-table; /* IE8+, Chrome, FF3+, Opera7+ */
    }
    
    h1 {
        display: table-cell;
        margin:5px;
        padding:5px;
        width:100px;
        height:50px;
        vertical-align: middle;
        text-align:center;
        background:#336699;
        color:#fff;
    }
    

    In this way you can use tables without break the website semantic. Look at MDN for further details about display and table styling.

    However, usually only one <h1> element per page is used to define the website’s page title, then all the other combinations of <h*> elements.

    If you don’t need cross-browser compatibility (for example, if you’re developing some Chrome/Firefox extension/webapp), even the new flexbox could be an interesting alternative.


    Another way could be to change vertical-align in your code with line-height set to the height of your <h1> element, but in this case you will have limited to a single line of text.

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

Sidebar

Related Questions

I have a header text in a h1 tag. I'd like to have a
I Have a fixed position tag that is styled as follows within my CSS:
In my fixed-width website, I have a layout similar to this: <div id=wrapper> <header>...</header>
I'm using HTML5 boilerplate and have a header tag going the full width across
I have my core web-app code in the header right now in a tag
I have a header file like this: #ifndef __GEN_NOTE_MARKERS_TO_DEVELOPERS_HPP__ #define __GEN_NOTE_MARKERS_TO_DEVELOPERS_HPP__ #ifdef _DEBUG //
I have a header file, lets say Common.h, that is included in all of
I would like to have logic in the Meta Description (located in Banner Header)
i have a header file global.h where i declare a few variables that i
I have a simple div tag: I need to make the thead fixed and

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.