我的问题

  1. 这些方法中有哪一种是专业网页设计师喜欢的?

  2. 在绘制网站时,Web浏览器是否首选这些方法中的任何一种?

  3. 这只是个人喜好吗?

  4. 我还遗漏了其他技巧吗?

Note: Above questions are in regards to designing a multi-column layout


浮动:左;

http://jsfiddle.net/CDe6a/

float:左图像

这是我在创建列布局时经常使用的方法,而且似乎工作得很好.不过,父母确实会self 崩溃,所以你只需要记住事后的数字clear:both;就可以了.我刚刚发现的另一个con是无法垂直对齐文本.

显示:内联;

这似乎纠正了折叠父级的问题,但添加了空格.

http://jsfiddle.net/CDe6a/1/

显示:内联图像

从html中删除空白似乎是解决这个问题的最简单方法,但如果你对html非常挑剔,就不需要这样做.

http://jsfiddle.net/CDe6a/2/

显示:内联-挡路;

看起来跟显示:内联;个一模一样.

http://jsfiddle.net/CDe6a/3/

DISPLAY:INLINE-挡路图像

显示:表格单元格;

http://jsfiddle.net/CDe6a/4/

显示:表格单元图像

很好用.

我的 idea :

我肯定我错过了很多东西,比如某些会 destruct 布局的例外情况,但显示:表格单元格;似乎效果最好,我想我会开始替换浮动:左;,因为我总是把clear:both;搞砸.我在网上读过很多关于这方面的文章和博客,但没有一篇能给我一个明确的答案,告诉我在设计网站时应该使用什么.

推荐答案

Of the options you asked about:

  • float:left;
    I dislike floats because of the need to have additional markup to clear the float. As far as I'm concerned, the whole float concept was poorly designed in the CSS specs. Nothing we can do about that now though. But the important thing is it does work, and it works in all browsers (even IE6/7), so use it if you like it.

如果使用:after Select 器清除浮动,则可能不需要额外的清除标记,但如果希望支持IE6或IE7,则这不是一个选项.

  • display:inline;
    This shouldn't be used for layout, with the exception of IE6/7, where display:inline; zoom:1 is a fall-back hack for the broken support for inline-block.

  • display:inline-block;
    This is my favourite option. It works well and consistently across all browsers, with a caveat for IE6/7, which support it for some elements. But see above for the hacky solution to work around this.

inline-block的另一个大警告是,由于内联方面的原因,元素之间的空白被视为与文本单词之间的空白相同,因此可以在元素之间出现空白.这方面有很多解决办法,但没有一个是理想的.(最好是元素之间不要有任何空格)

  • display:table-cell;
    Another one where you'll have problems with browser compatibility. Older IEs won't work with this at all. But even for other browsers, it's worth noting that table-cell is designed to be used in a context of being inside elements that are styled as table and table-row; using table-cell in isolation is not the intended way to do it, so you may experience different browsers treating it differently.

Other techniques you may have missed? Yes.

  • 既然你说这是针对多列布局的,那么你可能想知道CSS Columns feature个.然而,它并不是最受支持的功能(IE甚至在IE9中也不支持,而且所有其他浏览器都需要厂商前缀),所以你可能不想使用它.但这是另一种 Select ,你确实问过.

  • 还有CSS FlexBox功能,它允许文本从一个框流向另一个框.这是一个令人兴奋的功能,将允许一些复杂的布局,但这仍处于开发阶段——参见http://html5please.com/#flexbox

希望有帮助.

Html相关问答推荐

将小文本放在输入字段的右侧

Flexbox响应式图像不会缩小

如何将grid—template—column应用于元素中的子元素

只有一行上有溢出的CSS网格

如何通过扭曲元素来倾斜元素?

在Firefox中,使用写入模式:Vertical-LR时,不随内容扩展的css弹性项

在css中,如何在英雄版块的标题后面做一个粘性的导航栏?

Bootstrap 5.3.2模式页脚左填充还是左边距?

与窗高匹配的响应式正方形网格

浮动Div在CSS中未按预期工作

HTML 邮箱在 Gmail 中无法正确显示

为什么 html 元素的 max-width 和 width 一起工作?

为什么当我按第三个按钮时,前两个按钮会跳动?

为什么 CSS 网格超出了父级?

如何使Bootstrap 5卡可点击

在 iPhone 上分隔 HTML 邮箱输入中的多个邮箱条目

将图像高度调整到容器 div 中而不使其高度增加

使用 sprite 的问题,字符 sprite 中的额外边距

使用模板循环每行列出 3 个 bootstrap 卡

基本上,我想要两列包含文本和图像,但第二列是倒置的