InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

CSS

    CSS selectors

    • CSS selectors

    CSS properties

    • CSS properties

    CSS cookbooks

    • !important annotation
    • Align div in center horizontally
    • Align div in center vertically
    • Align multiple divs horizontally
    • Align text in center horizontally
    • CSS - drop cap effect
    • CSS - enlarge image on hover
    • CSS - round toggle switch using checkbox and label
    • CSS automatic table row numbering
    • CSS circle and oval
    • CSS clearfix - clear float automatically using ::after
    • CSS counters
    • CSS nested counters
    • CSS3 gradients
    • Create CSS triangles
    • First letter capital and bigger
    • How to display text on image using css
    • Install sass on Mac or Linux using ruby gem
    • Place a div in bottom right corner of browser
    • Test site css, javascript, html in old IEs
    • csslint
    • inherit value
    • initial value
    • inline-block and baseline alignment
    • margin collapsing
    • node-sass quick start tutorial on Linux and Mac
    • unset value
    • web typography
     
    • Home
    • > Tutorials
    • > CSS

    CSS – inline-block and baseline alignment

    on Feb 19, 2016

    When we use display:inline-block to place elements next to each other, by default their baseline is aligned to to parent baseline unless vertical-align property of these element is set to something other than baseline.

    Here are some examples on how baseline alignment work.

    inline-block baseline alignment basic example

    The baseline of div element is the baseline of its last line box in the normal flow. Here both divs are aligned based on last text line.
    inline-block-baseline-example-div-having-text

    <style type="text/css" media="screen">
    .outer > * {
      display:inline-block;
      background-color:lightgreen;
    }
    .one {width:80px; height:80px;}
    .two {width:80px; height:80px;}
    </style>
    
    <div class="outer">
    <div class="one">hello</div>
    <div class="two">Some text that will wrap</div>
    </div>
    refresh done
    try it online

    inline-block baseline alignment – empty div

    In case div is empty, its baseline is bottom margin edge. Here last text line of first div is aligned with bottom margin edge of second div (as it is empty).
    inline-block-baseline-example-empty-div

    <style type="text/css" media="screen">
    .outer > * {
      display:inline-block;
      background-color:lightgreen;
    }
    .one {width:80px; height:80px;}
    .two {width:80px; height:80px;}
    </style>
    
    <div class="outer">
    <div class="one">hello</div>
    <div class="two"></div>
    </div>
    refresh done
    try it online

    inline-block baseline alignment – div with overflow

    In case div has overflow other than visible (e.g. scroll, hidden), its baseline is bottom margin edge. Here last text line of first div is aligned with bottom margin edge of second div (as it has overflow:scroll).
    inline-block-baseline-example=div-having-overflow-scroll

    <style type="text/css" media="screen">
    .outer > * {
      display:inline-block;
      background-color:lightgreen;
    }
    .one {width:80px; height:80px;}
    .two {width:80px; height:80px; overflow:scroll;}
    </style>
    
    <div class="outer">
    <div class="one">hello</div>
    <div class="two">hello</div>
    </div>
    refresh done
    try it online

    Suggested posts:

    1. CSS float – floating left, right and clearing
    2. CSS flex – shorthand for flex-grow, flex-shrink and flex-basis
    3. Jenkins – how to delete old builds
    4. Vim – show line numbers
    5. CSS selector specificity
    6. CSS justify-content – flexbox children aligment
    7. Mac – how to copy, alias, move using drag/drop and mouse pointer indicators for these
    8. WordPress – write custom php log to separate file
    Share this article: share on facebook share on linkedin tweet this submit to reddit
    Posted in Tutorials | Tagged CSS, CSS cookbook, CSS layout, Tutorials
    • Browse content
    • Article Topics
    • Article archives
    • Contact Us
    Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

    Copyright © 2025 InfoHeap.

    Powered by WordPress