There is a class named gdiv
in my style sheet which refer to the general div
condition.
I can change my text alignment from gdiv
. but can not change alignment of everything like div
inside div
. How can I align everything?
Asked
Active
Viewed 167 times
-2

Nehax
- 49
- 9

Hridoy Bhuiayn
- 1
- 1
-
And your code here ? – Sandesh Sapkota Jan 28 '20 at 13:12
-
Put on your code below so we can solve your doubts, this way we are blindly guessing – h0merr Jan 28 '20 at 13:14
2 Answers
0
I think the best way to align the items to the center of your div, is to use flexbox
.gdiv {
display: flex; /* just to set it to flex box */
justify-content: center; /* to align the items horizontally in the div */
align-items: center; /* to align the items vertically in the div */
}
if you want to align the DIV itself by its parent, you can use this code in the parent;
If what you want to align is a text, you can just use:
.gdiv {
text-align: center;
}
If you're beginner, i highly recommend you to study flexbox and grid in css!

Gabriel
- 11
- 1
-1
It is quite hard to give a solution without code. But flexbox should center everything inside a div, even other divs.
display: flex;
align-items: center;
justify-content: center;

MaZoli
- 1,388
- 1
- 11
- 17
-
1
-
No worries. If your problem is solved I‘d be happy if you marked ma answer as helpful. Thanks – MaZoli Jan 29 '20 at 20:18