Answers for "center elements using css"

CSS
89

center a div in css

.container {
  display: flex;
  justify-content: center;
  align-items: center;
}
Posted by: Guest on September-09-2020
7

center a div css

.center {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}
Posted by: Guest on March-31-2021
4

how to center a div element

/*ADD MARGIN auto to left and right*/
.box1{
    width:80%;
    margin:0 auto;
}
Posted by: Guest on August-27-2020
1

css center div

.my-div{
  width: 80%;
  margin: 10px auto;
  /*
    margin-left and right right has 'auto' value
    meaning that the browser will automatically calculate the remaining space
    and give it to the margin.
    From the example. 20% remained from 80%
    so that our div will have 
    margin-right: 10%
    margin-left: 10%
    and it will be centered.
  */
}
Posted by: Guest on June-12-2021

Browse Popular Code Answers by Language