gpt4 book ai didi

html - 当我的宽度设置为 100% 时,为什么我的网站会横向滚动?

转载 作者:太空宇宙 更新时间:2023-11-03 20:28:25 26 4
gpt4 key购买 nike

所以我的网站出于某种原因横向或水平滚动。看起来是页脚造成的,但我只是想不通这里的问题是什么?我认为这可能与页脚中的社交图标有关,但我不太确定。一些指导表示赞赏

我的网站在这里:
https://jgofficial1.000webhostapp.com/index.html

HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JG.OFFICAL</title>
<link rel="stylesheet" href="style.css">
<!--fonts-->
<link href="https://fonts.googleapis.com/css?family=Montserrat:600" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Oswald" rel="stylesheet">
</head>

<body>
<header>
<div class= "logo">
<!--h1>JG.OFFICIAL</h1-->
<img src= "../images/logo.png" alt= "Hello" height ="60px" width ="310px">
</div>
<nav>
<ul>
<li><a href= "index.html">HOME</a></li>
<li><a href= "work.html">WORK</a></li>
<li><a href= "contact.html">CONTACT</a></li>
<li><a href= "about.html">ABOUT</a></li>
</ul>
</nav>
</header>
<br><br>
<div id= "scroll1">
<img src= "../images/scrollbutton.png" alt= "Click to scroll" height = "50" width = "50">
</div>
<div id= "img-wrapper">
<img src= "../images/helloscreen.png" alt= "Hello" height= "870" width= "1228">
</div>

<div id= "text-wrapper2">
<div id= "text">
<p>Design is always in our lives, whether we like it or not.</p>
</div>
</div>

<footer>
<div class= "social-icons">
<img src= "../images/fb-icon.png" alt= "Facebook" height= "45" weight= "45">
<img src= "../images/yt-icon.png" alt= "YouTube" height= "45" weight= "45">
<img src= "../images/instagram-icon.png" alt= "Instagram" height= "45" weight= "45">
<img src= "../images/twitter-icon.png" alt= "Twitter" height= "45" weight= "45">
</div>
</footer>

</body>
</html>

CSS

header {
background-color: rgba(0,0,0,0.0);
height: 60px;
width: 100%;
margin-top: 0px;
}

.logo {
color: white;
font-family: 'Montserrat', sans-serif;
margin-left: 10px;
padding-bottom: 10px;
float: left;
width: 70px;
}

body {
background-image: url("../images/background1.png");
background-size: cover;
margin: 0;
}

nav {
float: right;
margin-right: 10px;
background-color: rgba(0,0,0,0.0);
}

nav ul {
list-style-type: none;
font-family: 'Oswald', sans-serif;
overflow: hidden;
margin-top: 0;
padding-top: 15px;
}

nav li {
display: inline;
padding-right: 30px;
}

nav li a {
color: white;
text-align: center;
text-decoration: none;
}

#scroll1 {
text-align: center;
margin-top: 200px;
}

#img-wrapper {
text-align: center;
margin: 0 auto;
}

#text-wrapper img {
width: 100%;
height: auto;
}

#text-wrapper2 {
background-color: rgba(0,0,0,0.4);
margin-bottom: 10px;
height: 400px;
width: 100%;
}

#scroll1 {
text-align: center;
}

#text p {
color: white;
font-family: 'Oswald', sans-serif;
padding-top: 15px;
padding-left: 15px;
}

footer {
background-color: rgba(0,0,0,0.3);
height: 60px;
width: 100%;
padding-left: 20px;
padding-top: 8px;
}

.social-icons {
width: 100%;
}

最佳答案

现在有两个原因。

  1. 图像的宽度为 1228px
  2. 页脚的宽度为 100% + 20px padding

两者都将内容推送到 100% 宽度。要修复它,您可以添加如下内容:

#img-wrapper img {
max-width: 100%;
}

footer {
box-sizing: border-box;
}

您不希望这种情况再次发生吗?更全面地设置这些属性,它们可能会对您有所帮助。因此,您可以在 CSS 之上添加

* {
box-sizing: border-box;
}

img {
max-width: 100%;
}

为什么要使用box-sizing: border-box;

The width and height properties include the content, the padding and border, but not the margin.

发件人:https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing

关于html - 当我的宽度设置为 100% 时,为什么我的网站会横向滚动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48247556/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com