<div style="padding:10px;">content</div>
问题#2 – 指定内联样式时,应在冒号将属性名称与属性值分隔开之后插入空格吗?
<div style="padding: 10px;">content</div>
对比
<div style="padding:10px;">content</div>
解决方法
仅在声明之间需要分号。
A declaration-block (also called a
{}-block in the following text) starts
with a left curly brace ({) and ends
with the matching right curly brace
(}). In between there must be a list
of zero or more semicolon-separated
(;) declarations.
资料来源:http://www.w3.org/TR/css3-syntax/#rule-sets
The value of the style attribute must
match the Syntax of the contents of a
CSS declaration block (excluding the
delimiting braces)
资料来源:http://www.w3.org/TR/css-style-attr/#syntax
因为你只有一个声明,没有什么可分开,所以不需要分号。
但是,CSS语法允许空声明,这意味着您可以根据需要添加前导和尾随分号。例如,这是有效的CSS:
.foo { ;;;display:none;;;color:black;;; }
并相当于:
.foo { display:none;color:black }
答案2:不。
A declaration is either empty or
consists of a property,followed by a
colon (:),followed by a value. Around
each of these there may be whitespace.
资料来源:http://www.w3.org/TR/css3-syntax/#declarations
您可以添加空格以提高可读性,但它们没有相关性。