html - 使用 100% 宽度时的空白

标签 html css whitespace removing-whitespace

我和一个 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 */
}

JSFiddle

最佳答案

第一个最佳实践是放置通用选择器 * { 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/

相关文章:

javascript - 在 Polymer 元素中使用 light dom 中定义的模板

css - 如何使我的 div 具有背景图像但没有内容显示并从页面顶部延伸到页面底部?

html - 如何调整复选框周围的点击区域?

html - 如何在asp.net webform中显示来自sql数据库的Html内容

java - JAXB Moxy 混合空格丢失

html - 尽管主体容器非流体,但使页脚全宽(容器流体)

css - 底部容器堆叠在中间容器顶部

html - 为什么在调整屏幕大小时我的图像会重新定位?

python - pyplot 图例条目中的空格?

image - HTML:元素周围的空白,如何删除?