{{-- 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 :: mat dialog background color |
Css :: row reverse grid |
Css :: quitar borde a un boton css |
Css :: terraform rds |
Css :: button edges rounded css |
Css :: how to margin placeholdr text |
Css :: css filter color |
Css :: css break wrap header |
Css :: how to make all the columns equal size with flexbox |
Css :: repeating-linear-gradient |
Css :: css blur bg |
Css :: css image size adjust |
Css :: css change text size |
Css :: css light grey |
Css :: css font |
Css :: css transform origin |
Css :: how to use purgecss with webpack mix laravel |
Css :: css align center |
Css :: span to left css |
Css :: css prevent background scrolling |
Css :: css resize image |
Css :: font face |
Css :: autocomplete widget not working in modal popup |
Css :: angular ng-deep |
Css :: html css background linear-gradient |
Css :: absolute center css |
Css :: css border gradient |
Css :: style scrollbar |
Css :: css select all immediate children |
Css :: purge tailwind 3 |