我和一个 friend 正在开发一个网站,但由于某种原因,当我使用 100% 宽度时仍然存在空白。我怎样才能解决这个问题?这些是主要的 css 元素
#info_container{
height:100%;
width:100%;
display:inline-block;
padding-top:3%;
background-color:#D3D3D3;
}
#main_header {
background: -webkit-linear-gradient(#2a2a2a, #545454);
text-align: center;
align-items: center;
vertical-align: middle;
position: absolute;
width:100%;
height:8%;
margin:-1em;
position:fixed;
display: table;
width: 100%;
table-layout: fixed;
/* For cells of equal size */
}
最佳答案
第一个最佳实践是放置通用选择器 * { padding: 0;边距:0;}
以避免边距和填充溢出。
我更新了您的fiddle
CSS 的更改
* { padding: 0; margin: 0; }
#main_header {
background: -webkit-linear-gradient(#2a2a2a, #545454);
text-align: center;
align-items: center;
vertical-align: middle;
position: absolute;
width:100%;
position:fixed;
display: table;
width: 100%;
table-layout: fixed;
/* For cells of equal size */
}
#main_header a {
display:inline-block;
text-decoration:none;
color:#567aa9;
display: table-cell;
vertical-align: middle;
padding:.5%;
}
a span {
text-decoration:none;
color:#878787;
font-size:55px;
top: 10%;
overflow: hidden;
left:50%;
}
.a1:hover {
color:#bababa;
}
.a2:hover{
color:#bababa;
}
.a3:hover{
color:#bababa;
}
.a4:hover{
color:#bababa;
}
#info_container{
height:100%;
width:100%;
display:inline-block;
padding-top:7%;
}
html {
font-size: 62.5%;
}
body {
font-size: 1em;
}
@media (max-width: 300px) {
html {
font-size: 70%;
}
}
@media (min-width: 500px) {
html {
font-size: 80%;
}
}
@media (min-width: 700px) {
html {
font-size: 120%;
}
}
@media (min-width: 1200px) {
html {
font-size: 200%;
}
}
#info_container{
height: 100px; // changed this from 100%;
width:100%;
padding-top: 3%; // removed
display:inline-block;
background-color:#D3D3D3;
}
编辑:更新了 FIDDLE
关于html - 使用 100% 宽度时的空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33250126/