简体   繁体   English

为什么我要建立的网站右侧有空白?

[英]Why do I have white space on the right side of the website I'm building?

I'm building a website using a grid system as the framework. 我正在建立一个使用网格系统作为框架的网站。 At first I had no problems with margins and padding, but now I have extra white space on the right side of my website. 刚开始时,页边距和填充没有问题,但是现在网站右侧有多余的空白。

Here is my fiddle: http://jsfiddle.net/071ad2hg/1/ 这是我的小提琴: http : //jsfiddle.net/071ad2hg/1/

I already found the problem and it is from the following code: 我已经发现问题了,它来自以下代码:

.grid_12 { width: 100%; }

When I comment out this line the problem goes away, but I've used it in many places throughout my site and am wondering why this is happening all of a sudden. 当我注释掉这行代码时,问题就消失了,但是我在整个站点的许多地方都使用了它,并且想知道为什么这突然发生了。 I would like to keep it as is and just fix it somehow. 我想保持原样,以某种方式修复它。

Beacuse body has 8px margin you can change that by adding margin 0 to body css tag 因为body的边距为8px,所以可以通过在body css标签中添加margin 0来更改它

demo http://jsfiddle.net/ckqkyaqd/ 演示http://jsfiddle.net/ckqkyaqd/

body {
    font-family: 'elegant_luxmager';
    color: #444948;
    margin:0;

}

Add this to your body in the css. 将此添加到您的CSS身体中。

margin: 0;

and set a pixel width for your grids. 并为网格设置像素宽度。

.grid_12 {
width: 1000px;
margin: 0 2% 1% 0;
float: left;
display: block;
}

I would suggest using a .wrapper instead. 我建议改用.wrapper

.wrapper {
margin-left: auto;
margin-right: auto;
width: 1000px;
}

<div class="wrapper"></div>

Found your issue: 找到了您的问题:

It's the 25% margin that adds the whitespace, use a wrapper to center that part or use <center> 25%的余量增加了空格,使用包装器将零件居中或使用<center>

#images_row_1, #images_row_2, #images_iOS {
 margin-left: 25%; 
}

Use the inspector in Google Chrome developer tools and see the order in which the CSS is being applied. 使用Google Chrome开发人员工具中的检查器,查看CSS的应用顺序。 You have this additional margin which is being applied to the div. 您有此额外的边距将应用于div。 Try using a wrapper div or better yet use a defined responsive framework like Bootstrap or Foundation . 尝试使用包装div或更好的方法,但使用定义的响应框架(如BootstrapFoundation)

#images_row_1, #images_row_2, #images_iOS {
margin-left: 25%;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM