CSS中的高度标记有问题。我希望页面显示时没有任何滚动条,只是无法弄清楚当我将body标签中的“高度”从99%更改为100%时,突然出现滚动条并打破设计。
我想知道为什么会发生这种情况,原因是什么。
谢谢!
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
html {
height:100%;
}
body {
height: 99%;
margin-left: 20px;
margin-top:0px;
}
.gallerytitle {
position: absolute;
top: 20px;
font-family: serif;
font-size: 20px;
text-align: left;
}
.fullgallerytitle {
text-align: left;
font-family: sans-serif;
font-size: 12px;}
.events{
position: absolute;
font-family: sans-serif;
font-size: 12px;
top: 20px;
right: 20px;}
/* Center Text Section */
.area {
width: 100%;
height: 100%;
position: relative;
}
.middlespace {
position: absolute;
left: 50%;
top: 50%;
display: table;
}
.middlespace p {
display: table-cell;
vertical-align: middle;
text-align: center;
}
.bottom-left {
position: absolute;
font:sans-serif;
bottom: 15px;
left: 15px;
}
.contact {
font-size: 11px;
font-family: sans-serif;
border-bottom: 1px black dotted;
}
.exhibitiontitle {
color: #d4d4d4;
font-style: italic;
font-family: sans-serif;
font-size: 10px;
text-align: center;
}
.contact {
font-size: 11px;
font-family: sans-serif;
border-bottom: 1px black dotted;
}
.bold {
font-family: serif;
}
.about {
font-size: 11px;
font-family: sans-serif;
}
.address {
font-size: 11px;
border-bottom: 1px grey dotted;
}
.bottom-right {
position: absolute;
bottom: 15px;
right:15px;
font-style: italic;
color: #8e8e8e;
font-size: 11px;
}
.openinghours {
font-style: italic;
color: #8e8e8e;
font-size: 11px;
}
.subscribebutton
{
height:10px;
font-size: 9px;
}
.subscribebox
{
height:10px;
font-size: 9px;
}
</style>
<title>XYZ</title>
</head>
<body>
<div class="gallerytitle">XYZ<br /></div>
<div class="events">LOREM</div>
<div class="bottom-left">
<span class="about">
<span class="bold">XYZ</span> is a project by XZY. |
<span="address">Website Information</span> — <a href="mailto:info@info.eu">info@info.com</a>
</span>
</div>
<div class="bottom-right">
<span class="openinghours">Open by Appointment</span><span class=""> sponsored by XYZ</span>
</div>
</body>
</html>
答案 0 :(得分:2)
身体上还有下边缘。
body {
height: 100%;
margin: 0 0 0 20px;
}
虽然您应该考虑使用css重置,例如eric meyers reset或normalize
答案 1 :(得分:0)
用这个替换你的身体风格应该可以解决问题:
body {
height: 100%;
margin-left: 20px;
margin:0px;
}
答案 2 :(得分:0)
它会破坏页面,因为您使用了99%的页面,然后将所有内容移动到20px的右侧。它将99%移到外面并使用更多。这是解决方案,我认为它们都有效:
body {
height: 100%;
margin-left: 20px;
margin-right: -20px;
margin-top:0px;
}
或
body {
height: 100%;
padding-left: 20px;
padding-right: -20px;
margin-top:0px;
}