+ 1

How do i position an element to the center of a div element?

Am having a two elements and i want to position the other element to the center of the div such that, its position is always at the center irrespective of the screen size. How do i do that. thanks in advance.

11th Apr 2020, 9:14 PM
Mark Etale
Mark Etale - avatar
4 odpowiedzi
11th Apr 2020, 9:28 PM
Raj Chhatrala
Raj Chhatrala - avatar
0
thanks,,,, let me try
11th Apr 2020, 9:42 PM
Mark Etale
Mark Etale - avatar
0
Just to it Div{ position:relative; } Item{ position: absolute; top:50%; left:50%; transform: translate (-50%,-50%); } This method will help you
12th Apr 2020, 2:56 AM
Yogesh Jangid
Yogesh Jangid - avatar
0
have tried this it doesn't seem to work fine for me,,,, div { position: relative; } item { position: absolute; margin: auto; top: 0px; bottom: 0px; left: 0px; right: 0px } this one works fine for one element but fails for for multiple elements
12th Apr 2020, 3:24 AM
Mark Etale
Mark Etale - avatar