0

I'm trying to make each sections content centered. How do I do this? Am I using the containers/rows right? Do I put the alignment in the section? the container? the row? I don't know and neither works when I try

.content {
    height: 100vh;
}
<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Test</title>

        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
        <link rel="stylesheet" href="{{ url_for('static', filename='css/index.css') }}" />
    </head>
    <body>
            <section class="content" style="background-color: lightgreen;">
            <div class="container">
                <div class="row">
                    <div class="col-lg-6 text-center text-lg-start">
                        <h1>heading</h1>
                        <p>test</p>
                    </div>
    
                    <div class="col-lg-6">
                        <img src="https://via.placeholder.com/200/09f/fff.png" />
                    </div>
                </div>
            </div>
        </section>

        <section class="content" style="background-color: moccasin;">
            <div class="container">
                <div class="row">
                    <div class="col-lg-10 mx-auto col-lg-5">
                        <h1>heading</h1>
                        <p>test</p>
                    </div>
    
                    <div class="col-lg-6">
                        <img src="https://via.placeholder.com/200/09f/fff.png" />
                    </div>
                </div>
            </div>
        </section>
                <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
    </body>
</html>

using bootstrap v5.3.0-alpha1

edit: clarified question

2 Answers2

2

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Test</title>

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<link rel="stylesheet" href="{{ url_for('static', filename='css/index.css') }}" />
</head>
<body>
<section class="content" style="background-color: lightgreen;">
<div class="container">
<div class="row align-items-center">
    <div class="col-lg-6 text-center text-lg-start">
        <h1>heading</h1>
        <p>test</p>
    </div>

    <div class="col-lg-6">
        <img src="https://via.placeholder.com/500/09f/fff.png" />
    </div>
</div>
</div>
</section>

<section class="content" style="background-color: moccasin;">
<div class="container">
<div class="row justify-center text-center">
    <div class="col-lg-10 mx-auto col-lg-5">
        <h1>heading</h1>
        <p>test</p>
    </div>

    <div class="col-lg-6 m-auto">
        <img src="https://via.placeholder.com/500/09f/fff.png" />
    </div>
</div>
</div>
</section>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>

</body>
</html>
Jaswinder Kaur
  • 1,606
  • 4
  • 15
1

As I have checked your snippet, I have found that you have set the section height 100vh and your Image height is greater than it, So Image is overlapping to other section. To remove overlapping, You need to set section height greater than inside image element or You can remove the inline height of content class which applied on section. And to align section content in middle. Use class text-center with content class or container class otherwise you will have to write it with each element

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Test</title>

        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
        <link rel="stylesheet" href="{{ url_for('static', filename='css/index.css') }}" />
    </head>
    <body>
            <section class="content" style="background-color: lightgreen;">
            <div class="container text-center">
                <div class="row">
                    <div class="col-lg-6 text-lg-start">
                        <h1>heading</h1>
                        <p>test</p>
                    </div>
    
                    <div class="col-lg-6">
                        <img src="https://via.placeholder.com/500/09f/fff.png" />
                    </div>
                </div>
            </div>
        </section>

        <section class="content" style="background-color: moccasin;">
            <div class="container text-center">
                <div class="row">
                    <div class="col-lg-10  mx-auto col-lg-5">
                        <h1>heading</h1>
                        <p>test</p>
                    </div>
    
                    <div class="col-lg-6">
                        <img src="https://via.placeholder.com/500/09f/fff.png" />
                    </div>
                </div>
            </div>
        </section>
                <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
    </body>
</html>
Yogendra
  • 1,208
  • 5
  • 18
  • 38