+ 2
How do I insert a rectangle in the center of a screen ?
8 Answers
+ 2
Use margin:0 auto ; in your css. To horizontally center the elements
+ 2
Thanks a lot Ayush
+ 2
There are so many ways , refer this https://youtu.be/AXc1N4S0Vck
+ 2
.rectangle{
width:200px;
height:300px;
background-color:#000000;
position:absolute;
top:50%;
left:50%;
transform:translate(-50%,-50%);
}
This css code will definitely work for putting rectangle in the center.
+ 1
I will use and see if it's working thanks
+ 1
😊😊😊😊😊
+ 1
Thanks a lot for your help njay😊😊😊
- 1
This is a classic and tricky problem. Maybe this will help.
HTML
<div class='centered'> </div>
CSS
.centered {
position: fixed;
top: 50%;
left: 50%;
margin-top: -50px;
margin-left: -100px;
border-style:solid;
height:200px;
width:200px;
}