简体   繁体   English

为什么幻灯片图片比屏幕(和容器)大?

[英]Why are the slideshow pictures bigger than the screen (and container)?

I have solved all the problems before, thank you very much for help.之前的问题都解决了,非常感谢大家的帮助。 But now new ones appeared.但现在出现了新的。 The thing is that when I deleted the size of all containers (it was 1024px before), my slide images became way bigger than the screen.问题是当我删除所有容器的大小(之前是 1024 像素)时,我的幻灯片图像变得比屏幕大得多。 See the images 1 [and] 2 .请参阅图像1 [和] 2 Please help cause I need slide images to be full sized on the home page without scrolling down.请帮助我需要在主页上显示全尺寸幻灯片图像而无需向下滚动。 HTML HTML

<!--Start Home-->
<section class="home" id="home">
    <div class="container">
        <div class="mySlides">
            <img src="img/Home/вид1 классика.jpg" style="width:100%">
          </div>
          <div class="mySlides">
            <img src="img/Home/спальня море1.jpg" style="width:100%">
          </div>
          <div class="mySlides">
            <img src="img/Home/07.jpg" style="width:100%">
          </div>
          <div class="mySlides">
            <img src="img/Portfolio/4/розовая комната (5).jpg" style="width:100%">
          </div>
          <div class="mySlides">
            <img src="img/Portfolio/3/титова мал спальня (3).jpg" style="width:100%">
          </div>
    </div>
</section>
<!--End Home-->

CSS for the Home section主页部分的 CSS

/*Home Section*/

.home {
    height: 100vh;
    background-size: cover;
    background-position: center;
}
.home .container {
    height: 850px;
}
.home .container .mySlides {
    padding-top: 70px;
    width: 100%;
}

CSS for the whole website (to see the characteristics of main elements)整个网站的CSS(查看主要元素的特性)

html {
scroll-behavior: smooth;
}

body {
    margin: 0;
    font-family: 'Montserrat', sans-serif;
    max-width: 100%;
}
*{
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
.container {
    margin: auto;
}
.row {
    display: flex;
    flex-wrap: wrap;
}
.section-title {
    flex: 0 0 100%;
    max-width: 100%;
    margin-bottom: 40px;
}
.section-title h1 {
    display: inline-block;
    font-size: 30px;
    text-transform: uppercase;
    font-weight: 500;
    margin: 0 0 10px;
    position: relative;
}
.text-center {
    text-align: center!important;
}
.text-left {
    text-align: left!important;
}
.text-right {
    text-align: right!important;
}

JS JS

// Automatic Slideshow - change image every 5 seconds
var myIndex = 0;
carousel();

function carousel() {
  var i;
  var x = document.getElementsByClassName("mySlides");
  for (i = 0; i < x.length; i++) {
    x[i].style.display = "none";  
  }
  myIndex++;
  if (myIndex > x.length) {myIndex = 1}    
  x[myIndex-1].style.display = "block";  
  setTimeout(carousel, 5000);    
}

It is written in the devtools that the section and the container has the height of 850 but the div with slides is way bigger.在 devtools 中写道,section 和 container 的高度为 850,但带有幻灯片的 div 更大。 Don't know why.不知道为什么。 See 33

Thank in advance for help.预先感谢您的帮助。

the mySlides div has no height value so it takes the height of his content, and even if it did had a height you have an overflow problem. mySlides div 没有height值,所以它需要他的内容的高度,即使它确实有height你也有溢出问题。 I suggest giving the img itself the height value or max-height .我建议给 img 本身的height值或max-height

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM