Solution 1 :

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!

Solution 2 :

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;

Problem :

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?


Comment posted by Sandesh Sapkota

And your code here ?

Comment posted by h0merr

Put on your code below so we can solve your doubts, this way we are blindly guessing

Comment posted by Hridoy Bhuiayn

Thanks man. This works perfectly <3

Comment posted by Hridoy Bhuiayn

Thanks man. it works now

Comment posted by MaZoli

No worries. If your problem is solved I‘d be happy if you marked ma answer as helpful. Thanks