空白div不好? [英] Are empty divs bad?

查看:170
本文介绍了空白div不好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Aptana制作一个网站,我使用空白的div元素来制作边框底部的样式。

我无法将它作为边框元素的一部分,因为它需要始终具有相同的宽度,并且所谓的父元素实际上会根据大小而改变大小关于内容。



问题存在:使用像这样的空div是不好的?
Aptana给我一个警告。它说我应该修剪空的div。



我正在谈论divs在这里与类showinfo-border-left / right

 < div class =showinfo> 
< div class =showinfo-left>文字< / div>
< div class =showinfo-right>更多文字< / div>
< / div>
< div class =showinfo-border-left>< / div>
< div class =showinfo-border-right>< / div>


解决方案

From 加速您的网页的最佳实践



减少DOM元素的数量



复杂页面意味着需要下载更多字节,这也意味着JavaScript中的DOM访问速度较慢。例如,当您想要添加事件处理程序时,如果在页面上循环遍历500或5000个DOM元素,则会有所不同。
大量的DOM元素可能是一种症状,应该通过页面的标记来改善某些内容,而不必删除内容。您是否使用嵌套表进行布局?你是否只投入更多的东西来解决布局问题?也许有一个更好,更符合语义的方法来做你的标记。
YUI CSS实用工具的一个很好的帮助:grids.css可以帮助您整体布局,fonts.css和reset.css可以帮助您剥离浏览器的默认格式。这是一个重新开始并考虑标记的机会,例如,只有在语义上有意义时才使用s,而不是因为它会呈现新行。
DOM元素的数量很容易测试,只需输入Firebug的控制台:
document.getElementsByTagName('*')。length
有多少DOM元素太多了?检查其他具有良好标记的类似页面。例如,Yahoo!主页是一个非常繁忙的页面,仍然不超过700个元素(HTML标签)。


I'm making a website in Aptana and i'm using an empty div element for the styling of a border-bottom.

I couldn't make it part of the element it's a border of because it needs to have the same width all the time and that supposed parent element in fact changes size depending on the content.

Question being: Is it bad to use empty divs like this? Aptana gives me a warning. It says i "should trim empty div".

I'm talking about the divs down here with the class "showinfo-border-left/right"

<div class="showinfo">
    <div class="showinfo-left">Text</div>
    <div class="showinfo-right">More text</div>
</div>
    <div class="showinfo-border-left"></div>
    <div class="showinfo-border-right"></div>

解决方案

From Best Practices for Speeding Up your Webpage

Reduce the Number of DOM Elements

A complex page means more bytes to download and it also means slower DOM access in JavaScript. It makes a difference if you loop through 500 or 5000 DOM elements on the page when you want to add an event handler for example. A high number of DOM elements can be a symptom that there's something that should be improved with the markup of the page without necessarily removing content. Are you using nested tables for layout purposes? Are you throwing in more s only to fix layout issues? Maybe there's a better and more semantically correct way to do your markup. A great help with layouts are the YUI CSS utilities: grids.css can help you with the overall layout, fonts.css and reset.css can help you strip away the browser's defaults formatting. This is a chance to start fresh and think about your markup, for example use s only when it makes sense semantically, and not because it renders a new line. The number of DOM elements is easy to test, just type in Firebug's console: document.getElementsByTagName('*').length And how many DOM elements are too many? Check other similar pages that have good markup. For example the Yahoo! Home Page is a pretty busy page and still under 700 elements (HTML tags).

这篇关于空白div不好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆