960网格系统-嵌套网格有布局问题
我刚刚开始为自己开发一个爱好网站,并尝试使用 960 css 网格系统 来布局我的 html 元素在屏幕上。
我有了基本的想法,刚刚实现了一个骨架网站 在我的服务器上
我有几个问题到目前为止:
<div class="container_12">
<div class="grid_12">
<div id='top_bar' class='grid_insider'><!-- start of #top_bar -->
<ul id='top_menu' class='grid_5'><!-- start of #top_menu -->
<li>Home</li>
<li>Fake1</li>
<li>Fake2</li>
<li>Fake3</li>
</ul><!-- end of #top_menu -->
<ul id='user_panel' class='grid_2 prefix_4'><!-- start of #user_panel -->
<li>log in</li>
<li>faq</li>
</ul><!-- end of #user_panel -->
</div><!-- end of #top_bar -->
</div>
<div class="clear"></div>
<div id='title_bar' class="grid_12">
<h1 id="logo" align='center'>LOGO, TITLE and SLOGAN all go here!</h1>
</div><!-- end .grid_1 -->
<div class="clear"></div>
我使用的是基于网格 12 的模板,因此每个“行”上的“网格”总数应为 12。但是,我只能将两个元素放在同一“行”上,网格总数加起来为 11 ,但不是 12。如果我将 #user_panel" 的类更改为“grid_3 prefix4”,那么实际上会将该元素带到下一行,这会破坏所有内容。
另一件事是,尽管第一级元素(例如top_bar 和 title_bar 位于正确的位置(您可以使用方便的 Firefox 插件 gridfox 来确认) ,精确宽度为 940px,嵌套网格未处于应有的位置(偏离设计位置)。
我是这个 css 网格系统的新手,是否有更好的方法来管理嵌套元素?不得不说 960.gs 上的一些示例网站非常令人惊奇:)
提前感谢您的任何建议
更新信息
好的,根据下面的答案,我认为这仍然是可能的!要在调试嵌套网格时使用彩色边框,有一种特殊的方法可以“作弊”:
.grid_insider
{
border : 1px solid red;
margin : -1px; /* this will stop the element from 'expanding' its space */
}
I've just started developing a hobby site for myself, and trying to use the 960 css grid system to layout my html elements on screen.
I got the basic idea and just implemented a skeleton website here on my server
There are several questions I've got so far:
<div class="container_12">
<div class="grid_12">
<div id='top_bar' class='grid_insider'><!-- start of #top_bar -->
<ul id='top_menu' class='grid_5'><!-- start of #top_menu -->
<li>Home</li>
<li>Fake1</li>
<li>Fake2</li>
<li>Fake3</li>
</ul><!-- end of #top_menu -->
<ul id='user_panel' class='grid_2 prefix_4'><!-- start of #user_panel -->
<li>log in</li>
<li>faq</li>
</ul><!-- end of #user_panel -->
</div><!-- end of #top_bar -->
</div>
<div class="clear"></div>
<div id='title_bar' class="grid_12">
<h1 id="logo" align='center'>LOGO, TITLE and SLOGAN all go here!</h1>
</div><!-- end .grid_1 -->
<div class="clear"></div>
I am using a grid 12 based template, hence the total number of "grids" on each "row" should be 12. However, I can only make the two elements on the same "row" with total number of grids added up to 11, but not 12. If I change the #user_panel"'s class to "grid_3 prefix4", then that would actually take this element to the next line, which breaks everything.
Another thing is, although the first-level elements such as the top_bar and title_bar are on the right position (you can confirm that using a handy Firefox plugin gridfox), with exact width of 940px, the nested grids are not in positions they are supposed to be (a bit away from the designed positions).
I am new to this css grid system, is there a better way to manage the nest elements? I have to say some of the sample websites on the 960.gs are quite amazing to see :)
Thanks for any suggestion in advance!
Updated Info
Okay, based on the answer below, I reckon it is still possible to use colored borders when debugging the nested grids, there is an adhoc way to "cheat":
.grid_insider
{
border : 1px solid red;
margin : -1px; /* this will stop the element from 'expanding' its space */
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定您是否还没有意识到,该框架确实提供了一种嵌套元素的方法。
这会覆盖它们赋予所有网格元素的边距,从而允许侧面的元素靠在其容器的侧面。
您需要做的是将左侧菜单栏指定为
alpha
类,将右侧菜单栏指定为omega
类。然后,您必须删除添加到这两个元素及其容器的所有边框。这是因为 CSSfloat
非常精确,如果您使元素大于定义的框架,就会中断。如果您需要添加边框,则必须添加一些额外的样式来覆盖这些样式,并使它们的宽度比框架中定义的小两个像素(边框的每一侧各一个)。
Not sure if you haven't realized, but the framework does provide a method for nested elements.
This overrides the margins they give to all grid elements, thus allowing the elements on the side to rest against the sides of their containers.
What you'd need to do is to give the left menu bar the
alpha
class, the right one theomega
class. Then, you'll have to remove all of the borders you added to those two elements and their container. This is because CSSfloat
s are very precise, and will break if you make the elements any larger than the framework defined.If you need to add borders you'll have to add some additional styles that override these and give them widths two px (one for each side of the border) smaller than it is defined in the framework.
和一个很晚的答案......
使用边框轮廓
或使用框大小
and a very late answer....
use either outline for your borders
or use box-sizing