Bootstrap 5 · January 18, 2022 0

Membuat Hero Section Pada Web Company Profile Dengan Bootstrap 5 #2

Setelah selesai membuat navigasi, kali ini kita akan membuat sebuah Hero Section. Langkah awal yang perlu dipersiapkan adalah membuat kerangka section hero seperti berikut :

      <!-- HERO SECTION -->
      <section id="hero">
        <div class="container h-100">
          <div class="row h-100">
            <div class="col-md-6">
              

            </div>
          </div>
        </div>
      </section>

Setelah itu tambahkan h1 dan paragraf

            <div class="col-md-6">
              <h1>Membantu 
                Temukan 
                Rumah Impian</h1>
              <p><span class="fw-bold">MORO ADVER</span> hadir memberikan solusi terbaik terhadap rumah impianmu, bisa langsung beli sewa ataupun anda jual kembali.</p>
            </div>

Setelah itu masukan tombol temukan rumah

              <button class="button-lg-primary">TEMUKAN RUMAH</button>
              <a href="#">
                <img src="asset/img/arrow.png" alt="">
              </a>

Masukan gambar hero dan ornamen setelah class row

          <img src="asset/img/img hero.png" alt="" class="position-absolute bottom-0 end-0 img-hero">
          <img src="asset/img/ornamen.png" alt="" class="h-100 position-absolute bottom-0 start-0">

Ubh file style.css seperti dibawah ini :

:root {
  --pr-color: #025782;
  --sc-color: #000;
}

body {
  font-family: "Noto Sans", sans-serif;
  background-color: #f6fbff;
}

/* NAVBAR */
.navbar-brand {
  font-weight: bold;
  font-size: 20px;
}

.nav-link {
  font-size: 16px;
}

.nav-link.active {
  font-weight: bold;
}

.button-primary {
  width: 109px;
  height: 34px;
  background-color: transparent;
  color: var(--sc-color);
  border: none;
  font-size: 16px;
}

.button-secondary {
  width: 109px;
  height: 34px;
  background-color: #fff;
  color: var(--pr-color);
  border: none;
  font-size: 16px;
  font-weight: bold;
}

/* HERO */
#hero {
  background: linear-gradient(111.44deg, #9dcbef 2.86%, #ffffff 100%);
  height: 100vh;
  width: 100%;
}

.img-hero {
  height: 100%;
}

Selanjutnya kita membuat div tagline sesuai dengan code berikut :

<div class="col-md-6 hero-tagline my-auto">

Setelah itu tambahkan file css sebagai berikut :

.hero-tagline h1 {
  color: #025782;
  font-weight: 700;
  font-size: 60px;
  line-height: 70px;
}

.hero-tagline p {
  font-size: 16px;
  color: #0d5b83;
  margin-top: 30px;
  line-height: 25px;
}

Setelah itu setting tombolnya pada css seperti ini

.button-lg-primary {
  width: 220px;
  height: 40px;
  background-color: #fff;
  color: #025782;
  border: none;
  font-size: 20px;
  font-weight: bold;
  margin-right: 5px;
}

Pada navbar ubah posisinya menjadi Fixed dengan widht nya 100

<nav class="navbar navbar-expand-lg navbar-light bg-transparant position-fixed w-100">

Sehingga hasilnya akan seperti dibawah ini

File Index.html

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

    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">

    <!-- Font Google -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap" rel="stylesheet">

    <!-- My Style -->
    <link rel="stylesheet" href="css/style.css">

    <!-- Icon Logo -->
    <link rel="icon" href="asset/img/icon.png" type="image/x-icon">

    <title>Rumah Idaman - Moro Adver</title>
  </head>
  <body>
    
    <!-- NAVBAR -->
    <nav class="navbar navbar-expand-lg navbar-light bg-transparant position-fixed w-100">
        <div class="container">
          <a class="navbar-brand" href="#">
            <img src="asset/img/icon.png" alt="" width="30"  class="d-inline-block align-text-top me-2"> MORO ADVER</a>
          <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
          </button>
          <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav mx-auto">
              <li class="nav-item mx-2">
                <a class="nav-link active" aria-current="page" href="#">HOME</a>
              </li>
              <li class="nav-item mx-2">
                <a class="nav-link" href="#">LAYANAN</a>
              </li>
              <li class="nav-item mx-2">
                <a class="nav-link" href="#">FITUR</a>
              </li>
              <li class="nav-item mx-2">
                <a class="nav-link" href="#">KONTAK</a>
              </li>
            </ul>
            <div>
                <button class="button-primary">DAFTAR</button>
                <button class="button-secondary">MASUK</button>
            </div>            
          </div>
        </div>
  </nav>

      <!-- HERO SECTION -->
      <section id="hero">
        <div class="container h-100">
          <div class="row h-100">
            <div class="col-md-6 hero-tagline my-auto">
              <h1>Membantu 
                Temukan 
                Rumah Impian</h1>
              <p><span class="fw-bold">MORO ADVER</span> hadir memberikan solusi terbaik terhadap rumah impianmu, bisa langsung beli sewa ataupun anda jual kembali.</p>

              <button class="button-lg-primary">TEMUKAN RUMAH</button>
              <a href="#">
                <img src="asset/img/arrow.png" alt="">
              </a>
            </div>  
          </div> 
          </div>

          <img src="asset/img/img hero.png" alt="" class="position-absolute bottom-0 end-0 img-hero">
          <img src="asset/img/ornamen.png" alt="" class="h-100 position-absolute bottom-0 start-0 img-ornamen">

        </div>
      </section>




    <!-- Optional JavaScript; choose one of the two! -->

    <!-- Option 1: Bootstrap Bundle with Popper -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>

    <!-- Option 2: Separate Popper and Bootstrap JS -->
    <!--
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.10.2/dist/umd/popper.min.js" integrity="sha384-7+zCNj/IqJ95wo16oMtfsKbZ9ccEh31eOz1HGyDuCQ6wgnyJNSYdrPa03rtR1zdB" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>
    -->
  </body>
</html>

File style.css

:root {
  --pr-color: #025782;
  --sc-color: #000;
}

body {
  font-family: "Noto Sans", sans-serif;
  background-color: #f6fbff;
}

/* NAVBAR */
.navbar {
  z-index: 3;
}

* {
  z-index: 2;
}

.navbar-brand {
  font-weight: bold;
  font-size: 20px;
}

.nav-link {
  font-size: 16px;
}

.nav-link.active {
  font-weight: bold;
}

.button-primary {
  width: 109px;
  height: 34px;
  background-color: transparent;
  color: var(--sc-color);
  border: none;
  font-size: 16px;
}

.button-secondary {
  width: 109px;
  height: 34px;
  background-color: #fff;
  color: var(--pr-color);
  border: none;
  font-size: 16px;
  font-weight: bold;
}

/* HERO */
#hero {
  background: linear-gradient(111.44deg, #9dcbef 2.86%, #ffffff 100%);
  height: 100vh;
  width: 100%;
}

.img-hero {
  height: 100%;
  z-index: 1;
}

.img-ornamen {
  z-index: 0;
}

.hero-tagline h1 {
  color: #025782;
  font-weight: 700;
  font-size: 60px;
  line-height: 70px;
}

.hero-tagline p {
  font-size: 16px;
  color: #0d5b83;
  margin-top: 30px;
  line-height: 25px;
}

.button-lg-primary {
  width: 220px;
  height: 40px;
  background-color: #fff;
  color: #025782;
  border: none;
  font-size: 20px;
  font-weight: bold;
  margin-right: 5px;
}