There are several HTML elements that I have not introduced to this point because without CSS they have little point, and almost no meaning. These elements include span
and div
.
到目前为止,我还没有介绍几个HTML元素,因为没有CSS,它们几乎没有意义,也几乎没有意义。 这些元素包括span
和div
。
div
is arguably the most overused and misunderstood element in the HTML5 specification, so let’s try to kill a few common mistakes right off the bat:
div
可以说是HTML5规范中使用最广泛和最容易理解的元素,因此让我们尝试立即消除一些常见错误:
- It's an element used after all other section elements have been eliminated.
- 这是 在除去所有其他section元素之后使用的 元素 。
-
<div>
is not special in that regard. You do not need to use a<div>
并不特殊。 您无需使用<div>
in order to access advanced CSS such as<div>
即可访问高级CSS(例如 positioning. positioning) 。 -
<div>
can be applied to any other element, wrapping a<div>
进行的任何操作都可以应用于任何其他元素,所以将<div>
around a single element is almost always redundant and unnecessary.<div>
包裹在单个元素上几乎总是多余且不必要的。 -
<ul>
. Wrapping a<ul>
。 将<div>
around the<div>
包裹在<ul>
is redundant.<ul>
周围是多余的。 -
Use a combination of
outline
andbox-shadow
instead. -
而是
使用
outline
和box-shadow
的组合 。
Avoid setting -
height: 100%
, allowheight: 100%
,允许<div>
elements to find their own height, determined by their content.<div>
元素根据其内容确定自己的高度。
<div>
is a
<div>
是
"container of last resort"
“不得已的容器”
<div>
you can do to any other element<div>
做的任何事情都可以对任何其他元素做的事情
<div>
should almost never contain a single element<div>
几乎不应包含单个元素
<div>
is not a substitute for, or addition to, a block or section element<div>
不能替代或添加块或节元素
<div>
to create an extra border around an element<div>
在元素周围创建额外的边框
height
on any element, other than images).
避免在image之外的任何元素上设置height
)。