在%div上添加%边距

时间:2013-05-25 00:18:42

标签: css mobile center percentage margins

我正在设计的网站上有一些错误,关于响应式设计。

我想创建一个框,屏幕宽度为90%,然后在主框内添加3个其他框,但水平居中并保留百分比边距,因为我希望始终集中在网站的移动版本上。像这样举例如:

<ul>
 <li></li>
 <li></li>
 <li></li>
</ul>

CSS:

ul {
 width: 90%;
 border: green;
}

li {
 margin-left: 11%;
 margin-right: 11%;
}

但是当我调整浏览器的大小时,第三个“li”会停止运行并且不会占据所有3个中心。 我怎么能这样做?我正在使用Twitter Bootstrap。

1 个答案:

答案 0 :(得分:0)

你可能不会相信这一点 所有这一切都是因为在代码中添加断行或空格(使用display:inline-block)会在元素之间添加空格。

而不是

<li>one</li>
<li>two</li>
<li>three</li>

<li>one</li><li>two</li><li>three</li>

你应该以这样的结局结束:

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Margin</title>
<link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<style type="text/css">
body, ul {margin: 0;  padding: 0;  width: 100%}
ul {background: green; list-style-type: none}
li {display: inline-block; width: 11%; margin:0 11%; background: red}
</style>
</head>
<body>
<ul>
<li>one</li><li>two</li><li>three</li> <!-- No break lines nor spaces -->
</ul>
</body>
</html>