{{-- 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
--}}
div
{
display:flex;
align-items:center;
justify-content:center;
}
something {
display: block;
margin-left: auto;
margin-right: auto;
}
.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;
}
Code Example |
---|
Css :: animation shorthand css |
Css :: margin css |
Css :: grid css |
Css :: how to make a responsive box in css |
Css :: add arrow in select css |
Css :: cursor not pointer |
Css :: flickity css |
Css :: select two stuffes css |
Css :: reset div css |
Css :: bootstrap-start |
Css :: css overflow-y |
Css :: how to change border height in css |
Css :: add background video to div css |
Css :: lynx install bash |
Css :: css text overflow |
Css :: box glow css |
Css :: remove input border on focus |
Css :: css cursor delete |
Css :: fonmt family css |
Css :: background center |
Css :: css transform transition |
Css :: css create sidebar |
Css :: lightning color code |
Css :: radial-gradient css |
Css :: flex decoration css |
Css :: variables scss |
Css :: backdrop filter all properties |
Css :: background css |
Css :: sass installation |
Css :: tailwind npm |