0

I'm learning HTML5, CSS3 and Bootstrap4 and have created a dummy project.

I'm attempting to create a row that will house my icon and text (company name) side-by-side and have use display:inline to achieve the same. This is followed by a tag line.

However I'm unable to get the content of the entire row in the center. I have tried text-center or text-xs-center but to no avail. I even created a custom css class

.text-center-custom{
    text-align: center !important;
}

but that also didn't work.

index.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Project1</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
        integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <link href="https://fonts.googleapis.com/css?family=Karla&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=B612:700&display=swap" rel="stylesheet"> 
    <link href="https://fonts.googleapis.com/css?family=Frank+Ruhl+Libre&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="main.css" type="text/css">
</head>

<body>
    <div class="container">
        <div class="row" id="topSection">
            <div class="col-xs-12 text-center">
                <img src="icons/icon.png" class="inline">
                <h1 class="inline">Test Project</h1>
                <br><br>
                <h3>This is my first test project</h3>
                <h3>BOOTSTRAP</h3>
                <a href="" class="btn btn-danger">Sign-Up</a>
                <br>
            </div>
        </div>
    </div>
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
        integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
        crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
        integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
        crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
        integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
        crossorigin="anonymous"></script>
</body>

</html>

main.css

#topSection{
    background: url(images/background.jpg);
    background-position: center;
    background-size: 100%;
    color: bisque;
}

.inline{
    display: inline;
    font-family: 'B612', sans-serif;
}

.text-center-custom{
    text-align: center !important;
}
Dark Sorrow
  • 1,681
  • 14
  • 37

4 Answers4

2

#topSection{
    background: url(images/background.jpg);
    background-position: center;
    background-size: 100%;
    color: bisque;
}

.inline{
    display: inline;
    font-family: 'B612', sans-serif;
}

.text-center-custom{
    text-align: center !important;
}
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Project1</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
        integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <link href="https://fonts.googleapis.com/css?family=Karla&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=B612:700&display=swap" rel="stylesheet"> 
    <link href="https://fonts.googleapis.com/css?family=Frank+Ruhl+Libre&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="main.css" type="text/css">
</head>
<body>
    <div class="container">
        <div class="row justify-content-center" id="topSection">
            <div class="col-12 text-center">
                <img src="icons/icon.png" class="inline">
                <h1 class="inline">Test Project</h1>
                <br><br>
                <h3>This is my first test project</h3>
                <h3>BOOTSTRAP</h3>
                <a href="" class="btn btn-danger">Sign-Up</a>
                <br>
            </div>
        </div>
    </div>
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
        integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
        crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
        integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
        crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
        integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
        crossorigin="anonymous"></script>
</body>
</html>

Use justify-content-center on row For reference you can go through Bootstrap 4 flex utilities Hope it'd help

Sai Manoj
  • 3,809
  • 1
  • 14
  • 35
nazifa rashid
  • 1,469
  • 1
  • 9
  • 20
1

you can do that using bootstrap 4 flex utilities by using d-flex justify-content-center to row. Make sure that bootstrap 4 doesn't have class col-xs-12, it's replaced by col-12

#topSection{
    background: url(images/background.jpg);
    background-position: center;
    background-size: 100%;
    color: bisque;
}

.inline{
    display: inline;
    font-family: 'B612', sans-serif;
}

.text-center-custom{
    text-align: center !important;
}
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Project1</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
        integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <link href="https://fonts.googleapis.com/css?family=Karla&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=B612:700&display=swap" rel="stylesheet"> 
    <link href="https://fonts.googleapis.com/css?family=Frank+Ruhl+Libre&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="main.css" type="text/css">
</head>

<body>
    <div class="container">
        <div class="row d-flex justify-content-center" id="topSection">
            <div class="col-12 text-center">
                <img src="icons/icon.png" class="inline">
                <h1 class="inline">Test Project</h1>
                <br><br>
                <h3>This is my first test project</h3>
                <h3>BOOTSTRAP</h3>
                <a href="" class="btn btn-danger">Sign-Up</a>
                <br>
            </div>
        </div>
    </div>
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
        integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
        crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
        integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
        crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
        integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
        crossorigin="anonymous"></script>
</body>

</html>
Sai Manoj
  • 3,809
  • 1
  • 14
  • 35
1

please replace this 2line to your code

<div class="row text-center" id="topSection">
<div class="col-12 text-center w-100">

#topSection {
  background: url(images/background.jpg);
  background-position: center;
  background-size: 100%;
  color: bisque;
}

.inline {
  display: inline;
  font-family: 'B612', sans-serif;
}

.text-center-custom {
  text-align: center !important;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <title>Project1</title>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  <link href="https://fonts.googleapis.com/css?family=Karla&display=swap" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css?family=B612:700&display=swap" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css?family=Frank+Ruhl+Libre&display=swap" rel="stylesheet">
  <link rel="stylesheet" href="main.css" type="text/css">
</head>

<body>
  <div class="container">
    <div class="row text-center" id="topSection">
      <div class="col-12 text-center w-100">
        <img src="icons/icon.png" class="inline">
        <h1 class="inline">Test Project</h1>
        <br><br>
        <h3>This is my first test project</h3>
        <h3>BOOTSTRAP</h3>
        <a href="" class="btn btn-danger">Sign-Up</a>
        <br>
      </div>
    </div>
  </div>
  <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>

</html>
Sai Manoj
  • 3,809
  • 1
  • 14
  • 35
Irin
  • 1,274
  • 1
  • 8
  • 9
0

Use this code

Just change <div class="col-xs-12 text-center"> to <div class="col-md-12 text-center">

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Project1</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
        integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <link href="https://fonts.googleapis.com/css?family=Karla&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=B612:700&display=swap" rel="stylesheet"> 
    <link href="https://fonts.googleapis.com/css?family=Frank+Ruhl+Libre&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="main.css" type="text/css">
</head>

<body>
    <div class="container">
        <div class="row" id="topSection">
            <div class="col-md-12 text-center">
                <img src="icons/icon.png" class="inline">
                <h1 class="inline">Test Project</h1>
                <br><br>
                <h3>This is my first test project</h3>
                <h3>BOOTSTRAP</h3>
                <a href="" class="btn btn-danger">Sign-Up</a>
                <br>
            </div>
        </div>
    </div>
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
        integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
        crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
        integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
        crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
        integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
        crossorigin="anonymous"></script>
</body>

</html>