100% effect on Carousel

Asked

Viewed 893 times

2

I’m needing to put an overlay effect over a bootstrap Carousel, but it takes all the same height.

Clarifying better ... the first time I worked in this style - not in this excerpt I sent - through some modifications I even managed to make the effect stay 100% on Carousel and follow this way perfectly on any device, only that in IE I had a problem as my menu was totally thrown out of the slider (to the right side of the monitor where there was nothing else to view other than itself), while in the other browsers worked super well.
So I decided to redo everything - in this case I showed you - to which I adjusted the menu and left the part of the effect pending, only now I have this big question 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>
  <script src="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>

  • You want to cover the whole page or just the part of Carousel?

  • Only the part of the Carousel

  • Why don’t you put the div overlay inside the Carousel div?

  • Hello dvd, I tried to do this but it didn’t work for me. Thank you!

  • Then you will have to do this with Javascript, because the div overlay is out of Carousel and is without reference.

  • Hello dvd, I edited my question and explained it a little better.

  • Fernanda I left a comment in my answer, look it solves, if it doesn’t work I’ll ask you Edit your question with everything you have code there, because I could not simulate this error here, the way I did Overlay worked well in my test

Show 2 more comments

3 answers

1

At I touched practically nothing in your CSS, I just put one height defined for the .slider and overflow:hidden so the images are not extrapolating the height of the slider.

Another thing that had to be done is to put the div overlay within the slider, so she’ll follow the height of the .slider, no matter how tall he is.

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

Here’s the official Bootstrap3 Slider documentation https://getbootstrap.com/docs/3.3/javascript/#Carousel

Now see the example of how the result was with the overlay under the slider. (you might have 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>
  	<script src="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 you reported in the comment is because the image will follow its ratio (height x width). When vc greatly reduces the width of the screen and image gets the ratio Height/Width changed since it is 100% width and height "automatic.

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

Perform the Snippet and make the screen width tests that you via better understand. The solution to not let flatten is to use the @media to treat the image for each screen width without letting it deform the proportions too much width/height

Follows code:

<!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>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>

  • Hello ... with your adaptation I didn’t even have to touch the menu because it continued working well, but in smaller resolutions the height you added ends up accompanying the screen. Only I am seeing like this or for you also appears?

  • Fernanda the height should always be 200px which was the height I used in the example. If that height is varying make sure you have this tag on <head> of your page <meta name="viewport" content="width=device-width, initial-scale=1">. If you’re testing this one responsiveness right here on snippet Stackoverflow’s will not work anyway no, you have to put the code in your project. Anything is just talk

  • Hi Hugo, so I copied your code in a new file to do the test and in case I needed a higher height, so I increased it, and although the image keeps the responsive, the div slide and the overlay do not follow 100% the image. Is that what I meant if it happened to you too.

  • See image: https://uploaddeimagens.com.br/imagens/screen1-png-e5646ebc-9c21-4175-8ce4-68d74ee7ab9f

  • @Fernanda you put the overflow:hidden in div with id="myCarousel"? If you have already posed I think the problem should be another CSS that is interfering there somehow.... I did some tests here and could not simulate this mistake, mine does not let the overlay escape from Slider! Check the override, if you do not resolve update I will ask you to edit your question with the FULL code that you are currently using

  • Hi Hugo, I copied your code exactly as you sent me and the only modification I made was to increase the height of the class. slider 200px to 500px and nothing else. I will today still take a closer look and anything I return. I am grateful !!

  • @Fernanda made an Edition in my reply, give a look at the details ai of your problem

Show 2 more comments

0

The position of your "overlay-effect" div is wrong. You’re putting it outside 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 take the height property of the parent element. In your code, your "overlay-effect" is picking up the header height.

  • 1

    Enter an example code to illustrate your answer better.

  • Thank you Bianca, yes, I know my class. effect-overlay is tracking the height of my header, but I tried to make modifications to the positions and did not succeed, so I asked for help here on the forum. I thank you anyway and then I’ll do new tests.

0

Change the . slide to position: relative and use .slide:after with all its css .efeito-overlay and remove the div from the html 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 */
}

Browser other questions tagged

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