skip to Main Content

I have tried many solutions, but to no avail.

I have issues mainly:

  1. why is there a scroll (both horizontally and vertically). it should just fit in the view-port size. i am using height:100vh. i have used meta tag too.
  2. why background-size:cover isn’t working, also giving scroll in vertical desktop view too.
  3. at least the text shouldn’t have been cut at all. why is it so?
  4. List item

desktop view:
desktop view seems ok.
mobile view:
half of screen left black, with scroll

*{
    margin: 0;
padding: 0;
font-family: 'Poppins', sans-serif;
}

#banner{
    background: linear-gradient(rgba(0,0,0,0.5), #009688) , url(Barber_Shop_img/banner.jpg);
    background-size: cover;
    background-position: center;
    height: 100vh;   
}


.logo{
    width: 140px;
    position: absolute;
    top: 4%;
    left: 10%;
}

.banner-text {
    text-align: center;
    padding: 180px;
    color: white;
}

.banner-text h1{
    font-size: 130px;
    font-family: 'Kaushan Script', cursive;
}
.banner-text p{
    font-size: 20px;
    font-style: italic;
}

.banner-btn{
    margin: 70px auto 0;
}

/* the tutorial aims to make buttons using anchor tag, and on hover make the background color to white and text color to black */
/* explain position relative and position absolute in this context */
/* explain z-index of -1 and 1 in this code */
/* explain the transition: color 0.5s in this code. because code runs same withotut writing the word 'color' */
.banner-btn a{
    color: white;
    border: .5px solid #fff;
    padding: 12px 0;
    margin: 0 10px;
    display: inline-block;
    text-decoration: none;
    width: 150px;
    position: relative;
    z-index: 1;
    transition: color 0.5s;
}
 
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Barbar Shop Website Design - Easy Tutorials</title>
    <link rel="stylesheet" href="style.css">
    <link href="https://fonts.googleapis.com/css2?family=Kaushan+Script&family=Poppins:wght@300&display=swap" rel="stylesheet">
</head>
<body>
     <section id="banner">
        <img class="logo" src="Barber_Shop_img/logo.png">
        <div class="banner-text">
            <h1>Hair Studio</h1>
            <p>Style your hair to Style your personality</p>
            <div class="banner-btn">
                <a href="#"> <span></span>Find Out</a>
                <a href="#"> <span></span>Read More</a>
            </div>
        </div>
    </section>

    
</body>
</html>

3

Answers


  1. Your background is not image and cover property is nonsense. Please update your code as below and it will work. Good luck

    #banner {
      background: linear-gradient(rgba(0, 0, 0, 0.5), #009688), url(Barber_Shop_img/banner.jpg);
      background-size: cover;
      background-position: center;
      height: 100vh;
      overflow: hidden;
    }
    
    @media screen and (max-width: 768px) {
      .banner-text {
        padding: 50px;
      }
    
      .banner-text h1 {
        font-size: 70px;
      }
    
      .banner-text p {
        font-size: 15px;
      }
    }
    
    Login or Signup to reply.
  2. *{
        margin: 0;
    padding: 0;
    font-family: 'Poppins', sans-serif;
    }
    
    #banner{
        background: linear-gradient(rgba(0,0,0,0.5), #009688) , url(Barber_Shop_img/banner.jpg);
        background-size: cover;
        background-position: center;
        background-attachment: center
        height: 100vh;   
    }
    
    
    .logo{
        width: 140px;
        position: absolute; 
        top: 4%;
        left: 10%;
    }
    
    .banner-text {
        text-align: center;
        padding: 180px;
        color: white;
    }
    
    .banner-text h1{
        font-size: 130px;
        font-family: 'Kaushan Script', cursive;
    }
    .banner-text p{
        font-size: 20px;
        font-style: italic;
    }
    
    .banner-btn{
        margin: 70px auto 0;
    }
    
    /* the tutorial aims to make buttons using anchor tag, and on hover make the background color to white and text color to black */
    /* explain position relative and position absolute in this context */
    /* explain z-index of -1 and 1 in this code */
    /* explain the transition: color 0.5s in this code. because code runs same withotut writing the word 'color' */
    .banner-btn a{
        color: white;
        border: .5px solid #fff;
        padding: 12px 0;
        margin: 0 10px;
        display: inline-block;
        text-decoration: none;
        width: 150px;
        position: relative;
        z-index: 1;
        transition: color 0.5s;
    }
     
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Barbar Shop Website Design - Easy Tutorials</title>
        <link rel="stylesheet" href="style.css">
        <link href="https://fonts.googleapis.com/css2?family=Kaushan+Script&family=Poppins:wght@300&display=swap" rel="stylesheet">
    </head>
    <body>
         <section id="banner">
            <img class="logo" src="Barber_Shop_img/logo.png">
            <div class="banner-text">
                <h1>Hair Studio</h1>
                <p>Style your hair to Style your personality</p>
                <div class="banner-btn">
                    <a href="#"> <span></span>Find Out</a>
                    <a href="#"> <span></span>Read More</a>
                </div>
            </div>
        </section>
    
        
    </body>
    </html>
    Login or Signup to reply.
  3. To make a fixed full-height background which works on all devices, use a separate <div> styled with position: fixed.

    For large headings you might find that vw units are good for setting the font size.

    .banner-text h1 {
        font-size: 15vw;
    }
    
    body {
      margin: 0;
      font-family: 'Poppins', sans-serif;
    }
    
    .fixed-background {
      z-index: -1;
      position: fixed;
      width: 100vw;
      height: 100vh;
      background: linear-gradient(rgba(0,0,0,0.5), #009688) , url(http://picsum.photos/800);
      background-size: cover;
      background-position: center;
      background-repeat: no-repeat;
    }
    
    .logo {
        width: 10vw;
        position: absolute;
        top: 4%;
        left: 10%;
    }
    
    .banner-text {
        text-align: center;
        padding: 10vw;
        color: white;
    }
    
    .banner-text h1 {
        font-size: 15vw;
        font-family: 'Kaushan Script', cursive;
    }
    .banner-text p {
        font-size: 20px;
        font-style: italic;
    }
    
    .banner-btn {
        margin: 70px auto 0;
    }
    
    .banner-btn a {
        color: white;
        border: .5px solid #fff;
        padding: 12px 0;
        margin: 0 10px;
        display: inline-block;
        text-decoration: none;
        width: 150px;
        position: relative;
        z-index: 1;
        transition: color 0.5s;
    }
    <link href="https://fonts.googleapis.com/css2?family=Kaushan+Script&family=Poppins:wght@300&display=swap" rel="stylesheet">
    
    <div class="fixed-background"></div>
    
    <section id="banner">
      <img class="logo" src="http://picsum.photos/300">
      <div class="banner-text">
        <h1>Hair Studio</h1>
        <p>Style your hair to Style your personality</p>
        <div class="banner-btn">
          <a href="#"> <span></span>Find Out</a>
          <a href="#"> <span></span>Read More</a>
        </div>
      </div>
    </section>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search