简体   繁体   English

HTML5 CSS对齐问题

[英]HTML5 CSS Alignment Issue

A link to my page: My Page 指向我页面的链接: 我的页面

For debugging purposes I have set CSS background colors for the 3 sections of my page. 出于调试目的,我为页面的3个部分设置了CSS背景颜色。 The "Zine" should have background of red, the "Book Cover" should have a background of "green", and the "Magazine" at the end should be "Yellow". “Zine”应该有红色背景,“Book Cover”应该有“green”背景,而“Magazine”应该是“Yellow”。

For some reason the background of red is only getting applied to a very small portion of the "Zine" section, all the images and text in the Zine section should have background red but most of it is coming up green. 由于某种原因,红色的背景仅应用于“Zine”部分的一小部分,Zine部分中的所有图像和文本应该具有背景红色,但大部分都是绿色的。

Also if you notice this is on a 960 grid layout, and in the Book section (which should be green background) I have a h1 Book Jacket> tag, which you will actually see the text Book Jacket on the outside of the 960 grid (right side of page to the top right of the image of David Carson) 此外,如果您注意到这是在960网格布局上,并在书籍部分(应该是绿色背景)我有一个h1 Book Jacket>标签,您将在960网格外部实际看到文本Book Jacket(右侧页面右侧的David Carson图像)


Edit: Found solution: 编辑:找到解决方案:

I changed the following code: 我更改了以下代码:

<article class="container_12">
  <section class="zine">

To: 至:

<article>
  <section class="container_12 zine">

I think this fix works because the section class "zine" wraps the entire contents of what should have been red background. 我认为这个修复有效,因为节类“zine”包含应该是红色背景的全部内容。 This eliminates need for a clear fix, however the clearfix suggested by others also works. 这消除了对明确修复的需要,但是其他人建议的clearfix也有效。

The height of .zine is collapsing. .zine的高度正在崩溃。 This happens because it contains floated elements which aren't cleared. 发生这种情况是因为它包含未清除的浮动元素。 There are quite a few methods of clearing floats. 有很多清除浮子的方法。 I'd recommend using one (or both) of the following two methods: 我建议使用以下两种方法中的一种(或两种):

  1. The "clearfix hack" . “clearfix hack” Simply add the CSS rules from this page to your CSS docuement and add the class "cf" (or whatever) in addition to the class "zine". 只需将此页面中的CSS规则添加到CSS文档中,并在“zine”类之外添加“cf”(或其他)类。
  2. Or, overflow: hidden . 或者, 溢出:隐藏 Basically, just add overflow: hidden to the "zine"-element. 基本上,只需将overflow: hidden添加到“zine”元素中即可。

Edit: 编辑:

As you found out yourself, since you use the 960 grid, the container_12 and container_16 -elements have clearfix built-into them. 正如您自己发现的,因为您使用960网格, container_12container_16 -elements内置了clearfix。 Adding either of those class names to the wrapping elements does the same thing as I explained above. 将这些类名中的任何一个添加到包装元素都与我上面解释的相同。

You should use the grid_X classes (X is a number between 1 and 12), when you use 960.gs . 当您使用960.gs时,您应该使用grid_X类(X是1到12之间的数字)。 and you should add a .clear after every "row". 并且你应该在每个“行”之后添加.clear。

You should take a look at 960.gs 's source and see how they use it. 你应该看一下960.gs的来源,看看他们是如何使用它的。 That's a really good overview. 这是一个非常好的概述。

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

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