Search
 
SCRIPT & CODE EXAMPLE
 

CSS

how to center items in css

{{-- 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
--}}


Comment

how to align items in css

div
{
  display:flex;
  align-items:center;
  justify-content:center;
  
}
Comment

center items

something {
	display: block;
    margin-left: auto;
    margin-right: auto;
}
Comment

align items center css

.parent_div
{
  display:flex;
  align-items:center;
}
Comment

css align-items center

div {
  display: flex;
  align-items: center;
}
Comment

what does align items center do

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;
}
Comment

PREVIOUS NEXT
Code Example
Css :: background image with color overlay gradient css 
Css :: css make background visible in text 
Css :: how to paralax effect on background image 
Css :: angular headers for enc type 
Css :: transform origin css 
Css :: how to make div possion top in css 
Css :: Align vertically and horizontally 
Css :: css zebra 
Css :: how to add hover effect in emotion 
Css :: css selector attribute contain 
Css :: flex direction tailwind 
Css :: bootstrap cheat sheet 
Css :: bootstrap 4 input error 
Css :: css smooth scroll 
Css :: line-weight css 
Css :: scrollbar css 
Css :: how to center horizontally and vertically block div 
Css :: css selector color 
Css :: css italic 
Css :: css delay between animation iterations 
Css :: backgorund color transitition css 
Css :: box style 
Css :: setting z index on before after pseudo classes 
Css :: fixed within the div css 
Css :: rgb blue color code 
Css :: remove double quotes from string kotlin 
Css :: javafx button padding css 
Css :: css margin top responsive 
Css :: mapping and each in sass 
Css :: button click css style 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =