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

CSS3 flexbox

    Flexbox container properties

    • display:flex and inline-flex
    • flex-direction
    • flex-wrap
    • flex-flow
    • justify-content
    • align-items
    • align-content

    Flexbox items properties

    • order
    • flex-grow
    • flex-shrink
    • flex-basis
    • flex
    • align-self

    Flexbox cookbooks

    • CSS flexbox - align div vertically and horizontally in center
     
    • Home
    • > Tutorials
    • > CSS
    • > CSS properties
    • > CSS3 flexbox

    CSS flexbox – align div vertically and horizontally in center

    on Sep 13, 2016

    CSS flexbox can be used to align a div in center of container div both vertically and horizontally. Use the flexbox with following properties:

    1. justify-content: center (to align flex-item horizontally in center)
    2. align-items: center (to align flex-item vertically in center)
    <style>
    .fbox {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 200px; height:100px; background-color:gray;
    }
    .child {
      background-color:green;
    }
    </style>
    
    <div class=fbox>
    <div class="child">div in center</div>
    </div>
    refresh done
    try it online

    Related

    • CSS - align div in center vertically

    Suggested posts:

    1. CSS transform – translateX and translateY
    2. Mac – how to copy, alias, move using drag/drop and mouse pointer indicators for these
    3. Javascript – implement class using function
    4. CSS justify-content – flexbox children aligment
    5. PHP how to get current url
    6. CSS flex-shrink – shrink flex item if needed
    7. CSS align-items – flexbox items vertical alignment
    8. CSS float – floating left, right and clearing
    Share this article: share on facebook share on linkedin tweet this submit to reddit
    Posted in Tutorials | Tagged CSS, CSS properties, CSS3 flexbox, 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