我整天都在寻找解决方案。可能有一个,但我不明白对 CSS 和 DIV 的解释。
链接或帮助将不胜感激。我试图将 DIV 并排放置在包装器中,但我不知道为什么它们不对齐。
谢谢您的帮助。~多纳文
左标题 = 75% 和右标题 = 25%,因此应该等于 100% 的包装器,即 95%。但是正确的标题正在包装。
和
Left、Middle 和 Right portlet 部分应在同一行对齐。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>test-columns</title>
<style type="text/css">
#buttons {
border: 1px solid;
text-align: center;
width: 95%;
margin: 0 auto;
}
#container_heading {
border: 1px solid;
width: 95%;
text-align: center;
margin: 0 auto;
}
#left_heading {
border: 1px solid;
float: left;
width: 75%;
text-align: center;
margin: 0;
padding: 0;
}
#right_heading {
border: 1px solid;
float: right;
width: 25%;
text-align: center;
margin: 0;
padding: 0;
}
#controls {
clear: both;
border: 1px solid;
text-align: center;
width: 95%;
margin: 0 auto;
}
#sections {
border: 1px solid;
margin: 0px auto;
width: 95%;
}
#left_portlets {
border: 1px solid;
text-align: center;
float: left;
width: 33%;
margin: 0 auto;
}
#middle_portlets {
border: 1px solid;
text-align: center;
width: 33%;
margin: 0 auto;
}
#right_portlets {
border: 1px solid;
text-align: center;
float: right;
width: 33%;
margin: 0 auto;
}
</style>
</head>
<body style="margin: 0" >
<div id="buttons">
Buttons
</div>
<br /><br />
<div id="container_heading">
<div id="left_heading">
Left Heading
</div>
<div id="right_heading">
Right Heading
</div>
</div>
<br /><br />
<div id="controls">
Controls
</div>
<br /><br />
<div id="sections">
<div id="left_portlets">
<div id="1-1_portlet">
1-1 Portlet
</div>
<div id="1-2_portlet">
1-2 Portlet
</div>
<div id="1-3_portlet">
1-3 Portlet
</div>
</div>
<div id="middle_portlets">
<div id="2-1_portlet">
2-1 Portlet
</div>
<div id="2-2_portlet">
2-2 Portlet
</div>
<div id="2-3_portlet">
2-3 Portlet
</div>
</div>
<div id="right_portlets">
<div id="3-1_portlet">
3-1 Portlet
</div>
<div id="3-2_portlet">
3-2 Portlet
</div>
<div id="3-3_portlet">
3-3 Portlet
</div>
</div>
</div>
</body>
</html>
+-------------------------------------------------- --------------------------------+
编辑:
哇。这帮助很大...
我从宽度中去掉了一个百分点来补偿边框并添加了“display:inline-block;” 到彼此相邻排列的 div 和“box-sizing:border-box;” 到整个样式表。
事情现在排成一排。但是现在我如何平衡外部边缘,所以一切都是方形的?每次我做一点改变,布局就会中断。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>test-columns</title>
<style type="text/css">
/* apply a natural box layout model to all elements */
* { -moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box; }
#buttons {
border: 1px solid;
text-align: center;
width: 95%;
margin: 0 auto;
}
#container_heading {
border: 0px;
width: 95%;
text-align: center;
margin: 0 auto;
}
#left_heading {
border: 1px solid;
width: 74%;
text-align: center;
margin: 0;
padding: 0;
display: inline-block;
}
#right_heading {
border: 1px solid;
width: 24%;
text-align: center;
margin: 0;
padding: 0;
display: inline-block;
}
#controls {
clear: both;
border: 1px solid;
text-align: center;
width: 95%;
margin: 0 auto;
}
#sections {
border: 0px;
margin: 0px auto;
width: 95%;
text-align: center;
}
#left_portlets {
border: 1px solid;
text-align: center;
width: 31%;
margin: 0 auto;
display: inline-block;
}
#middle_portlets {
border: 1px solid;
text-align: center;
width: 31%;
margin: 0 auto;
display: inline-block;
}
#right_portlets {
border: 1px solid;
text-align: center;
width: 31%;
margin: 0 auto;
display: inline-block;
}
</style>
<script type="text/javascript" language="javascript">
</script>
</head>
<body style="margin: 0" >
<div id="buttons">
Buttons
</div>
<div id="container_heading">
<div id="left_heading">
Left Heading
</div>
<div id="right_heading">
Right Heading
</div>
</div>
<div id="controls">
Controls
</div>
<div id="sections">
<div id="left_portlets">
<div id="1-1_portlet">
1-1 Portlet
</div>
<div id="1-2_portlet">
1-2 Portlet
</div>
<div id="1-3_portlet">
1-3 Portlet
</div>
</div>
<div id="middle_portlets">
<div id="2-1_portlet">
2-1 Portlet
</div>
<div id="2-2_portlet">
2-2 Portlet
</div>
<div id="2-3_portlet">
2-3 Portlet
</div>
</div>
<div id="right_portlets">
<div id="3-1_portlet">
3-1 Portlet
</div>
<div id="3-2_portlet">
3-2 Portlet
</div>
<div id="3-3_portlet">
3-3 Portlet
</div>
</div>
</div>
</body>
</html>