Doesn’t image cover the entire screen?

Asked

Viewed 139 times

0

I’m developing a banner plus it’s not covering the entire screen equal to the image below it, the banner gets some white pieces around it.

Note: In this same banner I’m trying to do the paralax effect, and it’s not working if someone can give me a hint of what to do, I appreciate.

@charset "utf-8";
#brand-image{
	height: 100px;
	float: center;
}
.nav {
    position: fixed;
    padding-top: 15px;
    top: 0;
    z-index: 2;
    width: 100%;  
}
.navbar-brand {
    position: absolute;
    left: 50%;
    margin-left: -50px !important;  /* 50% of your logo width */
    display: block;
	margin-top: -20px;
}
/***************Corpo**********/
body, html{
    margin: 0;
    padding: 0;
}
body{
    background-image: url(img/fundo.jpg);
}

.wrapper{
    height: 50%;
    overflow-x: hidden;
    overflow-y: hidden;
    perspective: -10px;
    transform-style: preserve-3d;
}

.adesao{
    position: relative;
    height: 450px;
    min-width: 700px;
    transform-style: inherit;
}
.adesao::before{
    content: " ";
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    bottom: 0;
    z-index: -1;
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center center;
    transform: translateZ(-1px) scale(1.5);
}
.txt_adesao{
    position: absolute;
    top: 40%;
    width: 100%;
    padding: 20px o;

    color: white;
    text-shadow: 0 0 5px #000;
    font-size: 40px;
    text-align: center;
}
.txt_vejamais{
    position: absolute;
    top: 60%;
    left: 45%;
    width: 10%;
    padding: 20px o;

    color: white;
    text-shadow: 0 0 5px #000;
    font-size: 20px;
    text-align: center;
    border-style: solid;
    border-color: white;

}
.bg1::before{
    max-width: 100%;
    background-image: url(https://i.imgur.com/21wBdiC.jpg);
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!------ Include the above in your HEAD tag ---------->

<!DOCTYPE html>
<html lang="pt-br">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link rel="stylesheet" type="text/css" href="Bootstrap-4.1.3/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="design.css">
	<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
	<script type="text/javascript" src="js/jquery.countdown.js"></script>
	<script type="text/javascript" src="Bootstrap-4.1.3/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="js/bootbox.min.js"></script>
	<title>Formandos de Mecatrônica</title>

	<nav class="nav navbar-expand-lg navbar-dark bg-primary sticky-top">
	    	<a class="navbar-brand" href="#">
	    		<img id="brand-image" alt="Website Logo" />
	  		</a>
	  	<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
	    <span class="navbar-toggler-icon"></span>
	  	</button>
	  	<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
	    	<div class="navbar-nav">
	      		<a class="nav-item nav-link active" href="#">Home <span class="sr-only">(current)</span></a>
			    <a class="nav-item nav-link" href="#">Buffet</a>
			    <a class="nav-item nav-link" href="#">Local</a>
			    <a class="nav-item nav-link disabled" href="#">Loja</a>
	    	</div>
	  	</div>
	</nav>
</head>
<body>
	<div class="container-fluid">
		<main class="wrapper">
			<a href="https://www.google.com/">
				<section class="adesao bg1">
					<p class="txt_adesao">Faça sua ADESAO ONLINE </p>
					<p class="txt_vejamais">Veja Mais</p>
				</section>
			</a>
		</main>
	</div>
	</br>
	<div>
		<img src="https://images7.alphacoders.com/671/671281.jpg" width="100%">
	</div>
	</body>
</html>

  • Seriously though you want to put a picture of 30MB in your project? And this nav in the <head>?

  • Not this image I put of example, picked randomly on google, just for comparison, this image she takes the whole screen while the banner does not.

1 answer

2


The problem with margins is paddling left and right class .container-fluid. You can eliminate them by placing the class px-0:

<div class="container-fluid px-0">

The class px-0 eliminates the side paddings.

The spacing below is due to the <br>, that shouldn’t be there (see in this answer the correct use of <br>)

There is also an error in CSS:

padding: 20px o; /* usando a letra "o" em vez do número 0 */

Another problem is the <nav> within the tag <head>, when you should be in <body>.

Another mistake is the float: center;. There is no value center for float. Avoid using float, even more with Bootstrap.

To do the Parallax effect, set the property background-attachment: fixed; in class .bg1::before{. That will fix the background image making the effect work:

.bg1::before{
   max-width: 100%;
   background-image: url(https://i.imgur.com/21wBdiC.jpg);
   background-attachment: fixed;
}

Example: (I replaced the heavy image with another)

@charset "utf-8";
#brand-image{
height: 100px;
float: center;
}
.nav {
position: fixed;
padding-top: 15px;
top: 0;
z-index: 2;
width: 100%;  
}
.navbar-brand {
position: absolute;
left: 50%;
margin-left: -50px !important;  /* 50% of your logo width */
display: block;
margin-top: -20px;
}
/***************Corpo**********/
body, html{
margin: 0;
padding: 0;
}
body{
background-image: url(img/fundo.jpg);
}

.wrapper{
height: 50%;
overflow-x: hidden;
overflow-y: hidden;
perspective: -10px;
transform-style: preserve-3d;
}

.adesao{
position: relative;
height: 450px;
min-width: 700px;
transform-style: inherit;
 }
 .adesao::before{
content: " ";
position: absolute;
top: 0;
right: 0;
left: 0;
bottom: 0;
z-index: -1;
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
transform: translateZ(-1px) scale(1.5);
}
.txt_adesao{
position: absolute;
top: 40%;
width: 100%;
padding: 20px 0;

color: white;
text-shadow: 0 0 5px #000;
font-size: 40px;
text-align: center;
}
.txt_vejamais{
position: absolute;
top: 60%;
left: 45%;
width: 10%;
padding: 20px o;

color: white;
text-shadow: 0 0 5px #000;
font-size: 20px;
text-align: center;
border-style: solid;
border-color: white;

}
.bg1::before{
   max-width: 100%;
   background-image: url(https://i.imgur.com/21wBdiC.jpg);
   background-attachment: fixed;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">

<nav class="nav navbar-expand-lg navbar-dark bg-primary sticky-top">
	    	<a class="navbar-brand" href="#">
	    		<img id="brand-image" alt="Website Logo" />
	  		</a>
	  	<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
	    <span class="navbar-toggler-icon"></span>
	  	</button>
	  	<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
	    	<div class="navbar-nav">
	      		<a class="nav-item nav-link active" href="#">Home <span class="sr-only">(current)</span></a>
			    <a class="nav-item nav-link" href="#">Buffet</a>
			    <a class="nav-item nav-link" href="#">Local</a>
			    <a class="nav-item nav-link disabled" href="#">Loja</a>
	    	</div>
	  	</div>
	</nav>
   <div class="container-fluid px-0">
		<main class="wrapper">
			<a href="https://www.google.com/">
				<section class="adesao bg1">
					<p class="txt_adesao">Faça sua ADESAO ONLINE </p>
					<p class="txt_vejamais">Veja Mais</p>
				</section>
			</a>
		</main>
	</div>
	</br>
	<div>
		<img src="https://www.cleverfiles.com/howto/wp-content/uploads/2016/08/mini.jpg" width="100%">
	</div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.