<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>MY NAME</title>
<style>
/*CSS RESET*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
/*CSS RESET*/
body
{
background-color: white;
width: 100vw;
max-width: 100vw;
}
header
{
width: 100vw;
max-width: 100vw;
height: 15vh;
max-height: 8vw;
background-color: white;
}
h1
{
font-size: 5vw;
max-height: 5vw;
line-height: 1;
color: #333333;
}
h2
{
font-size: 2vw;
max-height: 2vw;
line-height: 0.1;
color: #333333;
}
#upperContainer
{
width: 100vw;
max-width: 100vw;
max-height: 60vh;
background-color: purple;
text-align: center;
}
#leftBlock
{
width: 50vw;
height: 60vh;
max-width: 100vw;
max-height: 60vh;
height: 60vh;
display: inline-block;
vertical-align: middle;
background-color: pink;
}
#rightBlock
{
width: 50vw;
max-height: 60vh;
background-color: yellow;
display: inline-block;
vertical-align: middle;
}
#lowerContainer
{
width: 100vw;
max-width: 100vw;
max-height: 60vh;
background-color: purple;
text-align: center;
}
#leftBlock2
{
width: 50vw;
height: 60vh;
max-width: 100vw;
max-height: 60vh;
height: 60vh;
display: inline-block;
vertical-align: middle;
background-color: green;
}
#rightBlock2
{
width: 50vw;
height: 60vh;
max-height: 60vh;
background-color: yellow;
display: inline-block;
vertical-align: middle;
}
footer
{
width: 100vw;
max-width: 100vw;
height: 15vh;
max-height: 8vw;
background-color: blue;
}
</style>
</head>
<body>
<header>
<mark><h1>MY NAME</h1></mark>
<h2>DESCRIPTION</h2>
</header>
<section id="upperContainer"><article id="leftBlock"></article><article id="rightBlock"></article></section>
<!--UNCOMMENT TO SEE PROBLEM <section id="lowerContainer"><article id="leftBlock2"></article><article id="rightBlock2"></article></section>-->
<footer>FOOTER</footer>
</body>
</html>
我的问题是:当我在html中删除注释标签“”时,页面的宽度突然比浏览器窗口宽。你们知道如何解决这个问题吗?我觉得这是某种奇怪的错误。
最佳答案
首先,您的#rightBlock中没有高度。添加此代码:height: 60vh;
然后,当您添加第二部分LowerContainer时,您将“自动”创建一个垂直滚动条。由于滚动条的原因,您需要更多的水平空间来显示内容,这是因为您拥有水平滚动条。
如果您将height = 10vh改为,则不会有任何问题。