Effect 100% above the Carousel

2

I need to put an overlay effect on top of a Carousel of the bootstrap, but that takes all the height of it.

Clarifying better ... the first time I worked in this style - not in this section I sent - through some modifications I even managed to make the effect 100% on the Carousel and follow that perfectly on any device, only which in IE I had a problem, because my menu was totally thrown out of the slider (to the right side of the monitor where I had nothing else to view besides itself), whereas in other browsers it worked super well. So I decided to redo everything - in case it was this part I showed you - to which I adjusted the menu and left the part of the effect pending, but now I have this great doubt of how to solve: - (

.efeito-overlay {
  z-index: 100;
}

nav {
  z-index: 200;
}

.slide {
  z-index: 40;
}

.efeito-overlay {
  width: 100%;
  height: 100% !important;
  overflow: hidden;
  position: absolute;
  background-image: repeating-linear-gradient(90deg, transparent 0px, transparent 3px, rgba(0, 0, 0, 0.15) 3px, rgba(0, 0, 0, 0.15) 4px), repeating-linear-gradient(0deg, transparent 0px, transparent 3px, rgba(0, 0, 0, 0.15) 3px, rgba(0, 0, 0, 0.15) 4px), linear-gradient(to right bottom, rgba(0, 0, 0, 0.20), rgba(0, 0, 0, 0.15)), url();
  background-position: bottom, left, top left, center;
  background-repeat: no-repeat, no-repeat, no-repeat, no-repeat;
  background-size: cover;
}

.carousel-inner>.item>img,
.carousel-inner>.item>a>img {
  width: 100%;
  margin: auto;
}

.slide {
  display: block;
  position: absolute;
  min-width: 100%;
  min-height: auto;
  width: 100%;
  height: auto;
  background-color: #000;
  margin-left: auto;
  margin-right: auto;
  box-sizing: border-box;
}

.carousel-inner img {
  width: 100%;
  height: auto;
}

.clearfix::after {
  content: "";
  display: block;
  clear: both;
}

.floated {
  float: left;
}

header {
  position: relative;
  display: flex;
  justify-content: center;
  align-content: center;
}

nav {
  width: 100%;
  height: 130px;
  position: absolute;
  top: 0;
  padding: 10px 100px;
  display: flex;
  align-content: center;
  display: inline-block;
}

nav #menu {
  background-color: #CCC;
  border-radius: 1px !important;
  float: right;
}

nav .icon-bar {
  background-color: #FFF;
}

nav a {
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.875em;
  letter-spacing: 1px;
  color: #000;
}
<!DOCTYPE html>
<html lang="pt-br">
<head>

  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Menu</title>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <link href="https://use.fontawesome.com/releases/v5.0.6/css/all.css" rel="stylesheet">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

</head>
<body>
  <header>


    <div class="efeito-overlay"></div>
    <div class="slide clearfix">
      <div id="myCarousel" class="carousel slide" data-ride="carousel">

        <div class="carousel-inner" role="listbox">
          <div class="item slide1 active floated"><img src="imagens/1-slide.jpg" alt="">
            <div class="carousel-caption"></div>
          </div>
          <div class="item floated"><img src="imagens/2-slide.jpg" alt="">
            <div class="carousel-caption"></div>
          </div>
          <div class="item floated"><img src="imagens/3-slide.jpg" alt="">
            <div class="carousel-caption"></div>
          </div>
        </div>
      </div>
    </div>
    <nav class="navbar">
      <div class="container-fluid">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#mymenu">
			        <span class="icon-bar"></span>
			        <span class="icon-bar"></span>
			        <span class="icon-bar"></span>                        
			      </button>
          <a class="navbar-brand" id="logo" href="index.html">Logo</a>
        </div>
        <div class="collapse" id="mymenu">
          <ul class="nav navbar-nav" id="menu">
            <li><a href="#">Link 1</a></li>
            <li><a href="#">Link 2</a></li>
            <li><a href="#">Link 3</a></li>
            <li><a href="#">Link 4</a></li>
          </ul>
        </div>
      </div>
    </nav>
  </header>
</body>

</html>
    
asked by anonymous 30.03.2018 / 22:21

3 answers

1

In the mexi practically nothing at all in your CSS, I only put height set to .slider and overflow:hidden so the images do not go beyond the height of slider .

Another thing you have to do is to put div overlay inside slider , so it will match the height of .slider , regardless of the height it has. >

Your slider also had some problems tagging, including the floated class in the image, which prevents it from occupying 100% of the width of the slider.

Here is the official Bootstrap3 Slider documentation link

Now see the example of how the result was with the overlay under the slider. (you may need to make some adjustments to your nav if you want it over the slider)

.efeito-overlay {z-index: 100;}
nav{ z-index: 200; }
.slide{ z-index: 40;}

.efeito-overlay {
	width: 100%;
	height: 100% !important;
	overflow: hidden;
	position: absolute;

	background-image: 
	repeating-linear-gradient(90deg, transparent 0px, transparent 3px, rgba(0, 0, 0, 0.15) 3px, rgba(0, 0, 0, 0.15) 4px),
	repeating-linear-gradient(0deg, transparent 0px, transparent 3px, rgba(0, 0, 0, 0.15) 3px, rgba(0, 0, 0, 0.15) 4px),
	linear-gradient(to right bottom, rgba(0, 0, 0, 0.20), rgba(0, 0, 0, 0.15)), url();

	background-position: bottom, left, top left, center;
	background-repeat: no-repeat, no-repeat, no-repeat, no-repeat;
	background-size: cover;
}
  
.carousel-inner > .item > img,
.carousel-inner > .item > a > img {
	width: 100%;
	margin: auto;
}	
.slide{
  display: block;
  position: absolute;
  min-width: 100%;
  height: 200px; /* aqui vc define a altura do slider */
  width: 100%;
  background-color: #000;
  margin-left: auto;
  margin-right: auto;
  box-sizing: border-box;
  overflow: hidden; /* isso evita que a imagem ultrapasse altura do slider */
}
.carousel-inner img{
	width: 100%;
	height: auto;
}
.clearfix::after {
  content: "";
  display: block;
  clear: both;
}
.floated {
  float: left;
}
  
header{
	position: relative;
	display: flex;
	justify-content: center;
	align-content: center;
}
nav{
	width: 100%;
	height: 130px;
	position: absolute;
	top: 0;
	padding: 10px 100px;
	display: flex;
	align-content: center;
	display: inline-block;
}
nav #menu{
	background-color: #CCC;
	border-radius: 1px !important;
	float: right;
}

nav .icon-bar{
	background-color: #FFF;
}
nav a{
	font-weight: 700;
	text-transform: uppercase;
	font-size: 0.875em;
	letter-spacing: 1px;
	color: #000;
}
		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link href="https://use.fontawesome.com/releases/v5.0.6/css/all.css" rel="stylesheet">
  	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


<header>

<div id="myCarousel" class="carousel slide clearfix" data-ride="carousel">
    <div class="efeito-overlay"></div>
  <!-- Wrapper for slides -->
  <div class="carousel-inner">
    <div class="item active">
      <img src="https://picsum.photos/354/300"alt="Los Angeles">
      <div class="carousel-caption"></div>
    </div>

    <div class="item">
      <img src="https://picsum.photos/355/300"alt="Chicago">
      <div class="carousel-caption"></div>
    </div>
  
    <div class="item">
      <img src="https://picsum.photos/356/300"alt="New york">
      <div class="carousel-caption"></div>
    </div>
  </div>
</div>

<nav class="navbar">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#mymenu">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>                        
      </button>				
      <a class="navbar-brand" id="logo" href="index.html">Logo</a>
    </div>
    <div class="collapse" id="mymenu">
        <ul class="nav navbar-nav" id="menu">			        
        <li><a href="#">Link 1</a></li>
        <li><a href="#">Link 2</a></li>
        <li><a href="#">Link 3</a></li>
        <li><a href="#">Link 4</a></li>
      </ul>
    </div>
  </div>
</nav>
      

</header>

EDIT

The problem that you reported in the comment occurs because the image will follow the aspect ratio (height X width). When you greatly reduce the width of the screen and the image has the Width / Width ratio changed since it is 100% width and height "automatic."

To solve your problem you can by min-height: 500px !important; in some places of CSS, however the image will be flattened horizontally, because you will restrict the height, but the width is always 100% ...

Run Snippet and run the screen-width tests that you see better. The solution to not letting flatten is to use @media to treat the image for each screen width without letting it deform too much the width / height proportions

Follow the code below:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Page Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" media="screen" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<style>
    .efeito-overlay {z-index: 100;}
nav{ z-index: 200; }
.slide{ z-index: 40;}

.efeito-overlay {
	width: 100%;
	height: 100% !important;
	overflow: hidden;
	position: absolute;

	background-image: 
	repeating-linear-gradient(90deg, transparent 0px, transparent 3px, rgba(0, 0, 0, 0.15) 3px, rgba(0, 0, 0, 0.15) 4px),
	repeating-linear-gradient(0deg, transparent 0px, transparent 3px, rgba(0, 0, 0, 0.15) 3px, rgba(0, 0, 0, 0.15) 4px),
	linear-gradient(to right bottom, rgba(0, 0, 0, 0.20), rgba(0, 0, 0, 0.15)), url();

	background-position: bottom, left, top left, center;
	background-repeat: no-repeat, no-repeat, no-repeat, no-repeat;
	background-size: cover;
}
.slide{
  display: block;
  position: absolute;
  min-width: 100%;
  height: 500px; /* aqui vc define a altura do slider */
  width: 100%;
  /* background-color: #000; */
  margin-left: auto;
  margin-right: auto;
  box-sizing: border-box;
  overflow: hidden; /* isso evita que a imagem ultrapasse altura do slider */
}
.carousel-inner > .item > img,
.carousel-inner > .item > a > img {
	width: 100%;
    margin: auto;
    min-height: 500px !important;
}	
.carousel-inner {
    min-height: 500px !important;
    width: 100%;
}	
.carousel-inner img{
	width: 100%;
	min-height: 500px !important;
}
.carousel-inner .active {
    min-height: 500px !important;
    width: 100%;
}
.clearfix::after {
  content: "";
  display: block;
  clear: both;
}
.floated {
  float: left;
}
  
header{
	position: relative;
	display: flex;
	justify-content: center;
	align-content: center;
}
nav{
	width: 100%;
	height: 130px;
	position: absolute;
	top: 0;
	padding: 10px 100px;
	display: flex;
	align-content: center;
	display: inline-block;
}
nav #menu{
	background-color: #CCC;
	border-radius: 1px !important;
	float: right;
}

nav .icon-bar{
	background-color: #FFF;
}
nav a{
	font-weight: 700;
	text-transform: uppercase;
	font-size: 0.875em;
	letter-spacing: 1px;
	color: #000;
}
</style>
</head>
<body>
    
    <header>

        <div id="myCarousel" class="carousel slide clearfix" data-ride="carousel">
            <div class="efeito-overlay"></div>
          <!-- Wrapper for slides -->
          <div class="carousel-inner">
            <div class="item active">
              <img src="https://picsum.photos/354/300"class="img-fluid" alt="Los Angeles">
              <div class="carousel-caption"></div>
            </div>
        
            <div class="item">
              <img src="https://picsum.photos/355/300"class="img-fluid" alt="Chicago">
              <div class="carousel-caption"></div>
            </div>
          
            <div class="item">
              <img src="https://picsum.photos/356/300"class="img-fluid" alt="New york">
              <div class="carousel-caption"></div>
            </div>
          </div>
        </div>
        
        <nav class="navbar">
          <div class="container-fluid">
            <div class="navbar-header">
              <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#mymenu">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>                        
              </button>				
              <a class="navbar-brand" id="logo" href="index.html">Logo</a>
            </div>
            <div class="collapse" id="mymenu">
                <ul class="nav navbar-nav" id="menu">			        
                <li><a href="#">Link 1</a></li>
                <li><a href="#">Link 2</a></li>
                <li><a href="#">Link 3</a></li>
                <li><a href="#">Link 4</a></li>
              </ul>
            </div>
          </div>
        </nav>
              
        
        </header>
    
    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>
    
01.04.2018 / 14:32
0

The position of your "effect-overlay" div is wrong. You're putting it off your slide, if you want it to take 100% of the height of the slide, it has to be inside the slide div, so you can get the height property of the parent element. In your code, your "overlay effect" is taking the height of the header.

    
31.03.2018 / 04:52
0

Change the .slide to position: relative and use .slide:after with all your css from .efeito-overlay and remove the html div like this:

.slide:after {
    width: 100%;
    height: 100% !important;
    overflow: hidden;
    position: absolute;

    background-image: 
    repeating-linear-gradient(90deg, transparent 0px, transparent 3px, rgba(0, 0, 0, 0.15) 3px, rgba(0, 0, 0, 0.15) 4px),
    repeating-linear-gradient(0deg, transparent 0px, transparent 3px, rgba(0, 0, 0, 0.15) 3px, rgba(0, 0, 0, 0.15) 4px),
    linear-gradient(to right bottom, rgba(0, 0, 0, 0.20), rgba(0, 0, 0, 0.15)), url();

    background-position: bottom, left, top left, center;
    background-repeat: no-repeat, no-repeat, no-repeat, no-repeat;
    background-size: cover;
}
.slide{
  display: block;
  position: relative;
  min-width: 100%;
  height: 500px; /* aqui vc define a altura do slider */
  width: 100%;
  /* background-color: #000; */
  margin-left: auto;
  margin-right: auto;
  box-sizing: border-box;
  overflow: hidden; /* isso evita que a imagem ultrapasse altura do slider */
}
    
04.04.2018 / 00:58