【问题标题】:z-index not working with chrome 52 , edge and safariz-index 不适用于 chrome 52、edge 和 safari
【发布时间】:2016-08-03 19:00:03
【问题描述】:

Problem with the image (same code) size where return after a time with SAFARI browser

我有什么:

框架:

  • jQuery
  • 引导程序

我的工作:我有一个图像滑块

浏览器(工作,不工作):

  • chrome 版本 52 (n)(相同的移动搜索结果)
  • firefox 版本 52.0.2743.82 m (w)(相同的移动结果)
  • Internet Explorer 11 (w)
  • edge 版本 25.10... (n)
  • Safari 手机(版本未知)(n)

Image: How looks work and not work

问题: Overslay(见类)应该只是在 img 然后是文本和按钮,但它忽略了我的 z-index。

我确实删除了所有不重要的内容。

/********************************/
/*       Fade Bs-carousel       */
/********************************/
.fade-carousel {
    position: relative;
    height: 100vh;
}
.fade-carousel .carousel-inner .item {
    height: 100vh;
}
.fade-carousel .carousel-indicators > li {
    margin: 0 2px;
    background-color: #f39c12;
    border-color: #f39c12;
    opacity: .7;
}
.fade-carousel .carousel-indicators > li.active {
  width: 10px;
  height: 10px;
  opacity: 1;
}

/********************************/
/*          Hero Headers        */
/********************************/
.hero {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 3;
    color: #fff;
    text-align: center;
    text-transform: uppercase;
    text-shadow: 1px 1px 0 rgba(0,0,0,.75);
      -webkit-transform: translate3d(-50%,-50%,0);
         -moz-transform: translate3d(-50%,-50%,0);
          -ms-transform: translate3d(-50%,-50%,0);
           -o-transform: translate3d(-50%,-50%,0);
              transform: translate3d(-50%,-50%,0);
}
.hero h1 {
    font-size: 6em;    
    font-weight: bold;
    margin: 0;
    padding: 0;
}

.fade-carousel .carousel-inner .item .hero {
    opacity: 0;
    -webkit-transition: 2s all ease-in-out .1s;
       -moz-transition: 2s all ease-in-out .1s; 
        -ms-transition: 2s all ease-in-out .1s; 
         -o-transition: 2s all ease-in-out .1s; 
            transition: 2s all ease-in-out .1s; 
}
.fade-carousel .carousel-inner .item.active .hero {
    opacity: 1;
    -webkit-transition: 2s all ease-in-out .1s;
       -moz-transition: 2s all ease-in-out .1s; 
        -ms-transition: 2s all ease-in-out .1s; 
         -o-transition: 2s all ease-in-out .1s; 
            transition: 2s all ease-in-out .1s;    
}

/********************************/
/*            Overlay           */
/********************************/
.overlay {
    position: absolute;
    width: 100%;
    height: 100%;
    z-index: 2;
    background-color: #080d15;
    opacity: .7;
}

/********************************/
/*          Custom Buttons      */
/********************************/
.btn.btn-lg {padding: 10px 40px;}
.btn.btn-hero,
.btn.btn-hero:hover,
.btn.btn-hero:focus {
    color: #f5f5f5;
    background-color: #1abc9c;
    border-color: #1abc9c;
    outline: none;
    margin: 20px auto;
}

/********************************/
/*       Slides backgrounds     */
/********************************/
.fade-carousel .slides .slide-1, 
.fade-carousel .slides .slide-2,
.fade-carousel .slides .slide-3 {
  height: 100vh;
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
}
.fade-carousel .slides .slide-1 {
  background-image: url(https://ununsplash.imgix.net/photo-1416339134316-0e91dc9ded92?q=75&fm=jpg&s=883a422e10fc4149893984019f63c818); 
}
.fade-carousel .slides .slide-2 {
  background-image: url(https://ununsplash.imgix.net/photo-1416339684178-3a239570f315?q=75&fm=jpg&s=c39d9a3bf66d6566b9608a9f1f3765af);
}
.fade-carousel .slides .slide-3 {
  background-image: url(https://ununsplash.imgix.net/photo-1416339276121-ba1dfa199912?q=75&fm=jpg&s=9bf9f2ef5be5cb5eee5255e7765cb327);
}

/********************************/
/*          Media Queries       */
/********************************/
@media screen and (min-width: 980px){
    .hero { width: 980px; }    
}
@media screen and (max-width: 640px){
    .hero h1 { font-size: 4em; }    
}
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="">
<title>Home</title>
<!-- Bootstramp -->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<!-- Font-Awesome -->

<!-- CSS-Animation -->
<!-- Fontelo -->
</head>
<body>
<div class="carousel fade-carousel slide" data-ride="carousel" data-interval="4000" id="bs-carousel">
	<!-- Overlay -->
	<div class="overlay"></div>
	<!-- Indicators -->
	<ol class="carousel-indicators">
		<li data-target="#bs-carousel" data-slide-to="0" class=""></li>
		<li data-target="#bs-carousel" data-slide-to="1" class=""></li>
		<li data-target="#bs-carousel" data-slide-to="2" class=""></li>
	</ol>
	<!-- Wrapper for slides -->
	<div class="carousel-inner">
		<div class="item slides active">
			<div class="slide-1"></div>
			<div class="hero">
					<h1>Get rich</h1>
					<h3>Start now!</h3>
				<button class="btn btn-hero btn-lg" role="button">Registration</button>
			</div>
		</div>
		<div class="item slides">
			<div class="slide-2"></div>
			<div class="hero">
					<h1>We are smart</h1>
					<h3>Get start your next awesome project</h3>
				<button class="btn btn-hero btn-lg" role="button">See all features</button>
			</div>
		</div>
		<div class="item slides">
			<div class="slide-3"></div>
			<div class="hero">
					<h1>We are amazing</h1>
					<h3>Get start your next awesome project</h3>
				<button class="btn btn-hero btn-lg" role="button">See all features</button>
			</div>
		</div>
	</div>
</div>		
<!-- The scroll to top feature -->
</body></html>

【问题讨论】:

  • 您能否提供一个fiddle 来证明您的问题?

标签: html css slider


【解决方案1】:

你不能(可以但不推荐,好像你可以避免z-index,避免z-index在中间挤压那个叠加层,所以我用另一种方式让它工作,我觉得更好。

我删除了 overlay 标记 div 及其 CSS 规则,并改用了伪元素。

如果您愿意,您可以根据需要将其单独添加到每张幻灯片上,具有不同的颜色和不透明度,甚至是另一个背景图像。

/********************************/
/*            Overlay           */
/********************************/
.fade-carousel .slides:after {
  content: '';
  position: absolute;
  left: 0; top: 0;
  width: 100%; height: 100%;
  background-color: black;
  opacity: 0.7;
}

示例 sn-p

/********************************/
/*       Fade Bs-carousel       */
/********************************/
.fade-carousel {
    position: relative;
    height: 100vh;
}
.fade-carousel .carousel-inner .item {
    height: 100vh;
}
.fade-carousel .carousel-indicators > li {
    margin: 0 2px;
    background-color: #f39c12;
    border-color: #f39c12;
    opacity: .7;
}
.fade-carousel .carousel-indicators > li.active {
  width: 10px;
  height: 10px;
  opacity: 1;
}

/********************************/
/*          Hero Headers        */
/********************************/
.hero {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 3;
    color: #fff;
    text-align: center;
    text-transform: uppercase;
    text-shadow: 1px 1px 0 rgba(0,0,0,.75);
      -webkit-transform: translate3d(-50%,-50%,0);
         -moz-transform: translate3d(-50%,-50%,0);
          -ms-transform: translate3d(-50%,-50%,0);
           -o-transform: translate3d(-50%,-50%,0);
              transform: translate3d(-50%,-50%,0);
}
.hero h1 {
    font-size: 6em;    
    font-weight: bold;
    margin: 0;
    padding: 0;
}

.fade-carousel .carousel-inner .item .hero {
    opacity: 0;
    -webkit-transition: 2s all ease-in-out .1s;
       -moz-transition: 2s all ease-in-out .1s; 
        -ms-transition: 2s all ease-in-out .1s; 
         -o-transition: 2s all ease-in-out .1s; 
            transition: 2s all ease-in-out .1s; 
}
.fade-carousel .carousel-inner .item.active .hero {
    opacity: 1;
    -webkit-transition: 2s all ease-in-out .1s;
       -moz-transition: 2s all ease-in-out .1s; 
        -ms-transition: 2s all ease-in-out .1s; 
         -o-transition: 2s all ease-in-out .1s; 
            transition: 2s all ease-in-out .1s;    
}

/********************************/
/*          Custom Buttons      */
/********************************/
.btn.btn-lg {padding: 10px 40px;}
.btn.btn-hero,
.btn.btn-hero:hover,
.btn.btn-hero:focus {
    color: #f5f5f5;
    background-color: #1abc9c;
    border-color: #1abc9c;
    outline: none;
    margin: 20px auto;
}

/********************************/
/*       Slides backgrounds     */
/********************************/
.fade-carousel .slides .slide-1, 
.fade-carousel .slides .slide-2,
.fade-carousel .slides .slide-3 {
  height: 100vh;
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  position: relative;
}

/********************************/
/*            Overlay           */
/********************************/
.fade-carousel .slides:after {
  content: '';
  position: absolute;
  left: 0; top: 0;
  width: 100%; height: 100%;
  background-color: black;
  opacity: 0.7;
}

.fade-carousel .slides .slide-1 {
  background-image: url(https://ununsplash.imgix.net/photo-1416339134316-0e91dc9ded92?q=75&fm=jpg&s=883a422e10fc4149893984019f63c818); 
}
.fade-carousel .slides .slide-2 {
  background-image: url(https://ununsplash.imgix.net/photo-1416339684178-3a239570f315?q=75&fm=jpg&s=c39d9a3bf66d6566b9608a9f1f3765af);
}
.fade-carousel .slides .slide-3 {
  background-image: url(https://ununsplash.imgix.net/photo-1416339276121-ba1dfa199912?q=75&fm=jpg&s=9bf9f2ef5be5cb5eee5255e7765cb327);
}

/********************************/
/*          Media Queries       */
/********************************/
@media screen and (min-width: 980px){
    .hero { width: 980px; }    
}
@media screen and (max-width: 640px){
    .hero h1 { font-size: 4em; }    
}
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="">
<title>Home</title>
<!-- Bootstramp -->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<!-- Font-Awesome -->

<!-- CSS-Animation -->
<!-- Fontelo -->
</head>
<body>
<div class="carousel fade-carousel slide" data-ride="carousel" data-interval="4000" id="bs-carousel">
	<!-- Indicators -->
	<ol class="carousel-indicators">
		<li data-target="#bs-carousel" data-slide-to="0" class=""></li>
		<li data-target="#bs-carousel" data-slide-to="1" class=""></li>
		<li data-target="#bs-carousel" data-slide-to="2" class=""></li>
	</ol>
	<!-- Wrapper for slides -->
	<div class="carousel-inner">
		<div class="item slides active">
			<div class="slide-1"></div>
			<div class="hero">
					<h1>Get rich</h1>
					<h3>Start now!</h3>
				<button class="btn btn-hero btn-lg" role="button">Registration</button>
			</div>
		</div>
		<div class="item slides">
			<div class="slide-2"></div>
			<div class="hero">
					<h1>We are smart</h1>
					<h3>Get start your next awesome project</h3>
				<button class="btn btn-hero btn-lg" role="button">See all features</button>
			</div>
		</div>
		<div class="item slides">
			<div class="slide-3"></div>
			<div class="hero">
					<h1>We are amazing</h1>
					<h3>Get start your next awesome project</h3>
				<button class="btn btn-hero btn-lg" role="button">See all features</button>
			</div>
		</div>
	</div>
</div>		
<!-- The scroll to top feature -->
</body></html>

【讨论】:

    【解决方案2】:

    调用 bootstrap.min.css 时出错尝试完整路径

     <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    

    查看here

    【讨论】:

    • 我没有签入项目,但看起来你的 sn-p 工作与这个完美......也许应该改变 =)
    • 我做到了,但我没有 15 声望。
    【解决方案3】:

    我认为嵌套位置的问题是相对绝对的。试试这个:

    <div class="carousel-inner">
        <div class="item slides active">
            <div class="overlay"></div>
            <div class="slide-1"></div>
            <div class="hero">
    

    /********************************/
    /*       Fade Bs-carousel       */
    /********************************/
    .fade-carousel {
        position: relative;
        height: 100vh;
    }
    .fade-carousel .carousel-inner .item {
        height: 100vh;
    }
    .fade-carousel .carousel-indicators > li {
        margin: 0 2px;
        background-color: #f39c12;
        border-color: #f39c12;
        opacity: .7;
    }
    .fade-carousel .carousel-indicators > li.active {
      width: 10px;
      height: 10px;
      opacity: 1;
    }
    
    /********************************/
    /*          Hero Headers        */
    /********************************/
    .hero {
        position: absolute;
        top: 50%;
        left: 50%;
        z-index: 3;
        color: #fff;
        text-align: center;
        text-transform: uppercase;
        text-shadow: 1px 1px 0 rgba(0,0,0,.75);
          -webkit-transform: translate3d(-50%,-50%,0);
             -moz-transform: translate3d(-50%,-50%,0);
              -ms-transform: translate3d(-50%,-50%,0);
               -o-transform: translate3d(-50%,-50%,0);
                  transform: translate3d(-50%,-50%,0);
    }
    .hero h1 {
        font-size: 6em;    
        font-weight: bold;
        margin: 0;
        padding: 0;
    }
    
    .fade-carousel .carousel-inner .item .hero {
        opacity: 0;
        -webkit-transition: 2s all ease-in-out .1s;
           -moz-transition: 2s all ease-in-out .1s; 
            -ms-transition: 2s all ease-in-out .1s; 
             -o-transition: 2s all ease-in-out .1s; 
                transition: 2s all ease-in-out .1s; 
    }
    .fade-carousel .carousel-inner .item.active .hero {
        opacity: 1;
        -webkit-transition: 2s all ease-in-out .1s;
           -moz-transition: 2s all ease-in-out .1s; 
            -ms-transition: 2s all ease-in-out .1s; 
             -o-transition: 2s all ease-in-out .1s; 
                transition: 2s all ease-in-out .1s;    
    }
    
    /********************************/
    /*            Overlay           */
    /********************************/
    .overlay {
        position: absolute;
        width: 100%;
        height: 100%;
        z-index: 2;
        background-color: #080d15;
        opacity: .7;
    }
    
    /********************************/
    /*          Cu0stom Buttons      */
    /********************************/
    .btn.btn-lg {padding: 10px 40px;}
    .btn.btn-hero,
    .btn.btn-hero:hover,
    .btn.btn-hero:focus {
        color: #f5f5f5;
        background-color: #1abc9c;
        border-color: #1abc9c;
        outline: none;
        margin: 20px auto;
    }
    
    /********************************/
    /*       Slides backgrounds     */
    /********************************/
    .fade-carousel .slides .slide-1, 
    .fade-carousel .slides .slide-2,
    .fade-carousel .slides .slide-3 {
      height: 100vh;
      background-size: cover;
      background-position: center center;
      background-repeat: no-repeat;
    }
    .fade-carousel .slides .slide-1 {
      background-image: url(https://ununsplash.imgix.net/photo-1416339134316-0e91dc9ded92?q=75&fm=jpg&s=883a422e10fc4149893984019f63c818); 
    }
    .fade-carousel .slides .slide-2 {
      background-image: url(https://ununsplash.imgix.net/photo-1416339684178-3a239570f315?q=75&fm=jpg&s=c39d9a3bf66d6566b9608a9f1f3765af);
    }
    .fade-carousel .slides .slide-3 {
      background-image: url(https://ununsplash.imgix.net/photo-1416339276121-ba1dfa199912?q=75&fm=jpg&s=9bf9f2ef5be5cb5eee5255e7765cb327);
    }
    
    /********************************/
    /*          Media Queries       */
    /********************************/
    @media screen and (min-width: 980px){
        .hero { width: 980px; }    
    }
    @media screen and (max-width: 640px){
        .hero h1 { font-size: 4em; }    
    }
    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="">
    <title>Home</title>
    <!-- Bootstramp -->
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <!-- Font-Awesome -->
    
    <!-- CSS-Animation -->
    <!-- Fontelo -->
    </head>
    <body>
    <div class="carousel fade-carousel slide" data-ride="carousel" data-interval="4000" id="bs-carousel">
    
    	<!-- Indicators -->
    	<ol class="carousel-indicators">
    		<li data-target="#bs-carousel" data-slide-to="0" class=""></li>
    		<li data-target="#bs-carousel" data-slide-to="1" class=""></li>
    		<li data-target="#bs-carousel" data-slide-to="2" class=""></li>
    	</ol>
    	<!-- Wrapper for slides -->
    	<div class="carousel-inner">
    		<div class="item slides active">
    	<!-- Overlay -->
    	<div class="overlay"></div>
    			<div class="slide-1"></div>
    			<div class="hero">
    					<h1>Get rich</h1>
    					<h3>Start now!</h3>
    				<button class="btn btn-hero btn-lg" role="button">Registration</button>
    			</div>
          </div>
    		<div class="item slides">
    			<div class="slide-2"></div>
    			<div class="hero">
    					<h1>We are smart</h1>
    					<h3>Get start your next awesome project</h3>
    				<button class="btn btn-hero btn-lg" role="button">See all features</button>
    			</div>
    		</div>
    		<div class="item slides">
    			<div class="slide-3"></div>
    			<div class="hero">
    					<h1>We are amazing</h1>
    					<h3>Get start your next awesome project</h3>
    				<button class="btn btn-hero btn-lg" role="button">See all features</button>
    			</div>
    		</div>
    	</div>
    </div>		
    <!-- The scroll to top feature -->
    </body></html>

    【讨论】:

    • 我喜欢这个解决方案 =) 可能是最灵活的解决方案。
    猜你喜欢
    • 2017-04-05
    • 2011-04-20
    • 2021-05-07
    • 2011-04-19
    • 2021-11-19
    • 1970-01-01
    • 2014-09-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多