{{-- this is my code
there is two ways to do it
the first method using flex box
--}}
<html>
<body>
<style>
.center {
display: flex;
align-items: center;
justify-content: center;
}
</style>
<div>
<h1 class="center">title</h1>
<h4 class="center">body</h4>
<div class="center">
<img src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__480.jpg" height="400px" width="400px" >
</div>
</div>
</body>
</html>
{{--
but the problem with this method that you need to give each element the center class
and in the case of some elments such as an image you need to wrap it inside a div
and pass the center class to it
--}}
{{-- the other way is using css grid --}}
<style>
.center {
display: grid;
place-items: center;
}
</style>
<div class="center">
<h1 >title</h1>
<h4>body</h4>
<img src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__480.jpg" height="400px" width="400px" >
</div>
{{--
the cool thing about this method that you just need to pass the center class,
in the parent div and evreything inside this div will be centered
and for example you dont need to put the image elemnt in a div in order for it to work
--}}
something {
display: block;
margin-left: auto;
margin-right: auto;
}
something {
display: grid;
place-items: center;
}
.parent_div
{
display:flex;
align-items:center;
}
div {
display: flex;
align-items: center;
}
div{
display:flex;
/*The flexbox items are aligned at the center of the cross axis.
(vertical align) ⬇️⬆️*/
align-items:center;
/* The flexbox items are aligned at the center hirozontally ⬅️➡️*/
justify-content:center;
}
display: inline-block
Code Example |
---|
Css :: centering with flexbox |
Css :: padding top |
Css :: border properties css |
Css :: equivalent zoom css |
Css :: media screen desktop |
Css :: wpdb insert query |
Css :: not hover css |
Css :: css units |
Css :: how to add fade-in with page transition |
Css :: css 2 bilder nebeneinander |
Css :: bootstrap list |
Css :: align text in center css |
Css :: css style slider color |
Css :: opacity color |
Css :: div class sr-only |
Css :: install webpack encore |
Css :: scss breakpoints |
Css :: espacio entre lineas css |
Css :: scrollbar height css |
Css :: css module multiple classes |
Css :: background image blur css codepen |
Css :: hover media query |
Css :: linear gradient in text |
Css :: add inner border css |
Css :: multiple divs next to each other |
Css :: triangle css |
Css :: scss linear gradient not working |
Css :: bootstrap breakpoints |
Css :: transform origin css |
Css :: use css to replace icon with text when hover |