gpt4 book ai didi

html - html正文溢出的未知原因

转载 作者:行者123 更新时间:2023-11-28 13:53:21 24 4
gpt4 key购买 nike

所以我正在为一个类(class)建立一个网站,我有一个意外的 css 问题。在较小的尺寸下, body 似乎会扩展到视口(viewport)之外。将 body 宽度设置为 100vw100% 并且没有任何变化,我不明白为什么会这样?

您可能需要将代码片段复制粘贴到代码笔中。 Stack 不允许我链接到 codepen :(

无论如何,任何你能告诉我解决的问题都会有所帮助!

body{

width:100vw;
margin:0;
padding:0;


}
.page-wrapper{
width:100%;
height:100%;

display: grid;
grid-template-columns: 0.5fr repeat(3, 2fr) 0.5fr;
grid-template-rows: auto 0em repeat(2, auto);
grid-template-areas: "header header header header header"
". . . . ."
". main main main ."
"footer footer footer footer footer";
}

.header{
display:flex;
position:relative;

align-items: center;

flex-direction:column;



height:80vh;
grid-area: header;

color:white
}

.navbar{
display: flex;

margin-top:8%;

width:70%;


justify-content: center;
}


.nav-item{
font-size: 2rem;
margin: 0em 0.2em;
}

.dot{
margin-right: 0.15em;
}
.dot.first, .dot.last{

}


.title-welcome{
margin-top:1.5em;
padding:0 1em;
font-size:3rem;
text-align: center;
}



.header_video-wrapper{
grid-area: header;

height:100%;
width:100%;
overflow:none;
}

.header_video-overlay{
opacity:0.4;
position:absolute;
width:100%;
height:100%;
}

.header_video{
position:absolute;
}


.main_content{
grid-area: main;
height:auto;

/* adds a break between sections */
padding-top:2em;
}
.footer{
height:4rem;
grid-area:footer;
}

/*placeholder classes are just for grid demonstration*/
.placeholder{
width:100%;
background-color: grey;
}


@media screen and (min-width:768px){


.page_container{

grid-template-columns: 0.5fr repeat(3, 2fr) 0.5fr;
grid-template-rows: repeat(3, auto) 14rem;
grid-template-areas:"header header header header header header header header"
". carousel carousel carousel carousel carousel carousel ."
". main main main main main main ."
"footer footer footer footer footer footer footer footer";

}


.header{
height: 45vh
}

.navbar{

}

.nav-item{

}

.dot.first, .dot.last{
/* display:none; */
}

.main_content{

}

.footer{

}
}
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Truro Multicultural Festival</title>
<link rel="shortcut icon" href="favicon.ico" type="image/vnd.microsoft.icon" />
<link rel="stylesheet" href="styles-index.css" type="text/css" type="text/css" />
</head>

<body>
<div class="page-wrapper">
<div class="header">
<nav class="navbar">
<div class="nav-item">
<div>
<span class="dot first">•</span>
<a href="" class="page_link">Home</a>
</div>
</div>
<div class="nav-item">
<div>
<span class="dot">•</span>
<a href="/about" class="page_link">About</a>
</div>
</div>
<div class="nav-item">
<div>
<span class="dot">•</span>
<a href="/events" class="page_link">Events</a>
</div>
</div>
<div class="nav-item">
<div>
<span class="dot">•</span>
<a href="/contact" class="page_link">Contact</a>
<span class="dot last">•</span>
</div>
</div>
</nav>
<h1 class="title-welcome">
Welcome To The Truro Multicultural Festival
</h1>
</div>
<div class="header_video-wrapper" preload="none">
<div class="header_video-overlay"></div>
<video class="header_video" src="media/header-video.webm"></video>
</div>


<main class="main_content placeholder"></main>
<footer class="footer placeholder"></footer>
</div>
</body>

</html>

最佳答案

内容(四个链接的文本)不会换行:当它们都在一行中时,它们肯定相当宽,这使您的 HTML 内容比浏览器窗口更宽。

要么让内容适应(较小的文本),以更窄的宽度包裹内容(媒体查询),要么通过将 overflow: hidden 添加到 .page-wrapper(或 .header)来 overflow hidden 内容。

关于html - html正文溢出的未知原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59259206/

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