skip to Main Content

i have code with me ready and i can share with anyone, somehow stack-overflow keep giving me error while loading code.

i do created box and write all content inside the box , while applying CSS property justify-content: center it actually not working.

2

Answers


  1. Justify-content is sub-property of flex box so for using justify-content you have to add display flex I attached an example over here.

    <!DOCTYPE html>
    <html>
    
    <head>
        <style>
            .main {
                width: 100%;
                height: 200px;
                display: flex;
                border: 1px solid black;
                align-items: center;
                justify-content: center;
            }
    
            .check p {
                font-size: 25px;
            }
        </style>
    </head>
    
    <body>
        <h1>The justify-content Property</h1>
        <p>The "justify-content: center;" aligns the flex items at the center of the container:</p>
        <section class="main">
            <p>check this</p>
            <p>This is your text</p> <button>click for action</button>
        </section>
    </body>
    
    </html>
    Login or Signup to reply.
  2. The CSS justify-content property defines how the browser distributes space between and around content items along the main-axis of a flex container, and the inline axis of a grid container.

    Explained in the first sentence of https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content

    Mening you need display: flex; justify-content: center;

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search