display: flex;
align-items: center;
justify-content: center;
display: flex;
align-items: center;
justify-content: center;
/* order: vertical, horizontal */
/* If you need to access this quickly, just search for "fc" */
div {
display: flex;
justify-content: center;
align-items: center;
}
/* HORIZONTAL */
justify-content: center;
/* VERTICAL */
align-items: center;
.container {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
}
/* Row centering */
div {
display: flex;
flex-direction: row; /* Optional -- default flex-direction is row */
justify-content: center; /* center horizontally */
align-items: center; /* center vertically */
}
/* Column centering */
div {
display: flex;
flex-direction: column;
justify-content: center; /* center vertically */
align-items: center; /* center horizontally */
}
section {
width: 200px;
border: 1px solid #2d2d2d;
display: flex;
justify-content: center;
}
/* how to center a div in css flexbox */
place-content: center center;
flex-flow: row wrap;
/* below two line is work fine and same for both flex and grid layout */
display: (grid or flex as your usecase);
justify-content: center;
align-items: center;
/* <div class="center">
* <div>some important stuff </div>
* </div>
*/
.center{
display: flex;
justify-content: center;
align-items: center;
}
.vertical-container {
height: 300px;
display: -webkit-flex;
display: flex;
-webkit-align-items: center;
align-items: center;
-webkit-justify-content: center;
justify-content: center;
}
<div class="container">
<div class="item"></div>
</div>
div.container {
background: gray;
width: 80px;
height: 80px;
display: flex;
justify-content: center;
align-items: center;
}
div.item {
background: silver;
width: 30px;
height: 30px;
}
Code Example |
---|
Css :: css background image cut off |
Css :: line middle text css |
Css :: transition timing functions |
Css :: change svg color css |
Css :: zoom image inside div and move |
Css :: css selector label for |
Css :: css keyframes |
Css :: change mouse pointer on image hover |
Css :: inline block text align top |
Css :: tailwind css responsive table |
Css :: css opacity |
Css :: center div with flexbox |
Css :: install tailwind css |
Css :: media-queries |
Css :: how to make a flex container full page |
Css :: linear gradient not covering entire page |
Css :: setting multiple css using dom |
Css :: css select all immediate children |
Css :: create arrow div css |
Css :: alternate css animation |
Css :: Add border to text - Css |
Css :: change background color on hover |
Css :: letter spacing in css |
Css :: css list in line |
Css :: hide the scrollbar in css if not overflow |
Css :: line height tailwind |
Css :: css hover |
Css :: zoom background image css |
Css :: css focus-within |
Css :: backdrop filter all properties |