zoukankan      html  css  js  c++  java
  • css布局学习资料

    http://www.barelyfitz.com/screencast/html-training/css/positioning/
    http://www.noupe.com/css/css-layouts-40-tutorials-tips-demos-and-best-practices.html
    http://css-tricks.com/


    http://www.quirksmode.org/css/clearing.html

    Clearing floats

    No compatibility problems. Incredible, isn't it?

    Discuss this page.

    A common problem with float-based layouts is that the floats' container doesn't want to stretch up to accomodate the floats. If you want to add, say, a border around all floats (ie. a border around the container) you'll have to command the browsers somehow to stretch up the container all the way.

    The problem

    Let's try it. This is the CSS we'll use throughout the page:

    div.container { 	border: 1px solid #000000; }  div.left { 	 45%; 	float: left; }  div.right { 	 45%; 	float: right; } 

    Now this happens:

    The left column.

    The left column.

    The left column.

    The left column.

    The right column.

    The right column.

    The right column.

    We want the black border to go around both our floating columns. That doesn't happen, though. The container div itself has no height, since it only contains floating elements. Therefore the border stubbornly stays at the top of the floating columns.

    The old solution

    The old solution to this problem required you to add an extra element with clear: both to the container. Once it was in place the container contained a non-floating element, which means it stretches itself up to accomodate it:

    The left column.

    The left column.

    The left column.

    The left column.

    The right column.

    The right column.

    The right column.

    clearer div with clear: both

    This can be done either by adding the extra element in the HTML source code (as the example above does) or by using the :after pseudo-class to generate it. Since Explorer (Win and Mac) doesn't support :after this second solution was mainly of theoretical interest.

    In any case, adding an HTML element for presentation's sake is something we've learned to avoid. Unfortunately the problem could not be solved in any other way, until now.

    The new solution

    It was Alex Walker who first posted a new, simpler solution, though he gives the credits for actually inventing it to Paul O'Brien. In any case, the solution seems to be:

    div.container { 	border: 1px solid #000000; 	<strong>overflow: auto; 	 100%</strong> } 

    The width is necessary to trigger "hasLayout" in Explorer Windows (except for 7). This works:

    The left column.

    The left column.

    The left column.

    The left column.

    The right column.

    The right column.

    The right column.

    Now the border neatly fits around the floated elements.

    The tricky bits

    A few points merit extra attention:

    1. The trick works with three of the four overflow values: auto, hidden and scroll. Of course, using the last value will show scrollbars, regardless of whether they're needed or not.
    2. Some browsers also need a width or height for the container div.
    3. The browser may show scrollbars when the content escapes beyond the specified width.

    width or height required

    The use of a width or height declaration is required to make the effect work in Explorer Windows and Opera. If you don't include it Explorer Windows continues to show the border at the top of the columns, as if there were no overflow. Opera completely hides the content of the container.

    A 100% is a neat starting point, although more complicated layouts may require other values.

    Explorer Mac: hidden

    If Explorer Mac is still important to you, use overflow: hidden. This browser always shows scrollbars when you use overflow: auto; and I'm not sure why.

    Unwanted scrollbars

    As Dave Shea noted, this solution might cause unwanted scrollbars if the content escapes from the container box. Personally I wonder if this will be a serious problem. overflow: hidden makes sure that no scrollbars will ever be visible. Of course some content might be hidden instead, but if we make very sure that

    1. the height of the container remains flexible (ie. "as much as needed")
    2. the widths of the combined floats never exceed the width of the container, and preferably remain slightly smaller to allow for some flexibility

    this problem will never creep up.

    On the other hand, never say never. In pure tests like the ones above the effect works fine. In real-world sites, where there's plenty more CSS to confuse browsers, something will eventually go wrong somewhere. Until we reach that point, though, this technique will do nicely.

    The complete effect

    For completeness' sake, here's the code you need:

    div.container { 	border: 1px solid #000000; 	overflow: hidden; 	 100%; }  div.left { 	 45%; 	float: left; }  div.right { 	 45%; 	float: right; } 

    The left column.

    The left column.

    The left column.

    The left column.

    The right column.

    The right column.

    The right column.

    Home Sitemap Contact Donations


  • 相关阅读:
    以下文件中的行尾不一致。要将行尾标准化吗
    用户 NT AUTHORITYNETWORK SERVICE 登录失败
    sql server 2008 不允许保存更改,您所做的更改要求删除并重新创建以下表 的解决办法
    附加数据库对于服务器失败(Microsoft.SqlServer.Smo),无法升级数据库,因为它是只读的,或者具有只读文件
    IIS上部署MVC网站,打开后ExtensionlessUrlHandler-Integrated-4.0解决方法
    HTTP 错误 404.2
    vs智能提示突然消失的解决办法 (vs2008 vs2010 vs2012 智能提示)
    Visual Studio 常用快捷键
    403.14-Forbidden Web 服务器被配置为不列出此目录的内容及Login on failed for "IIS APPPOOLASP.NET v4.0"问题
    短信轰炸PC版
  • 原文地址:https://www.cnblogs.com/lexus/p/2156392.html
Copyright © 2011-2022 走看看