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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:57:38+00:00 2026-06-02T14:57:38+00:00

How can I align two inline-blocks so that one is left and the other

  • 0

How can I align two inline-blocks so that one is left and the other is right on the same line? Why is this so hard? Is there something like LaTeX’s \hfill that can consume the space between them to achieve this?

I don’t want to use floats because with inline-blocks I can line up the baselines. And when the window is too small for both of them, with inline-blocks I can just change the text-align to center and they will be centered one atop another. Relative(parent) + Absolute(element) positioning has the same problems as floats do.

The HTML5:

<header>
    <h1>Title</h1>
    <nav>
        <a>A Link</a>
        <a>Another Link</a>
        <a>A Third Link</a>
    </nav>
</header>

The css:

header {
    //text-align: center; // will set in js when the nav overflows (i think)
}

h1 {
    display: inline-block;
    margin-top: 0.321em;
}

nav {
    display: inline-block;
    vertical-align: baseline;
}

Thery’re right next to each other, but I want the nav on the right.

a diagram

  • 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-02T14:57:40+00:00Added an answer on June 2, 2026 at 2:57 pm

    Edit: 3 years has passed since I answered this question and I guess a more modern solution is needed, although the current one does the thing 🙂

    1.Flexbox

    It’s by far the shortest and most flexible. Apply display: flex; to the parent container and adjust the placement of its children by justify-content: space-between; like this:

    .header {
        display: flex;
        justify-content: space-between;
    }
    

    Can be seen online here – http://jsfiddle.net/skip405/NfeVh/1073/

    Note however that flexbox support is IE10 and newer. If you need to support IE 9 or older, use the following solution:

    2.You can use the text-align: justify technique here.

    .header {
        background: #ccc; 
        text-align: justify; 
    
        /* ie 7*/  
        *width: 100%;  
        *-ms-text-justify: distribute-all-lines;
        *text-justify: distribute-all-lines;
    }
     .header:after{
        content: '';
        display: inline-block;
        width: 100%;
        height: 0;
        font-size:0;
        line-height:0;
    }
    
    h1 {
        display: inline-block;
        margin-top: 0.321em; 
    
        /* ie 7*/ 
        *display: inline;
        *zoom: 1;
        *text-align: left; 
    }
    
    .nav {
        display: inline-block;
        vertical-align: baseline; 
    
        /* ie 7*/
        *display: inline;
        *zoom:1;
        *text-align: right;
    }
    

    The working example can be seen here: http://jsfiddle.net/skip405/NfeVh/4/. This code works from IE7 and above

    If inline-block elements in HTML are not separated with space, this solution won’t work – see example http://jsfiddle.net/NfeVh/1408/ . This might be a case when you insert content with Javascript.

    If we don’t care about IE7 simply omit the star-hack properties. The working example using your markup is here – http://jsfiddle.net/skip405/NfeVh/5/. I just added the header:after part and justified the content.

    In order to solve the issue of the extra space that is inserted with the after pseudo-element one can do a trick of setting the font-size to 0 for the parent element and resetting it back to say 14px for the child elements. The working example of this trick can be seen here: http://jsfiddle.net/skip405/NfeVh/326/

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

Sidebar

Related Questions

I have two divs, inline. One displays a measurement, the other displays a unit
How can I align the first column to the right and second column to
How can I vertically align a Label and TextBlock at Top so that their
I can't seem to get this text to align vertically. Can someone please tell
I have a table of one row with two columns.I want to align content
Can we include two headers in jqgrid. One with a colModel and one without
I have two float elements, right and left. The parent element for all of
I'm trying to display two <div> elements on the same line, but in the
I'm trying to execute two events using the same class in jquery... having one
How to achieve independent horizontal scrolling between two ul lists using the left, right,

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.