Inline CSS formatting best practices - Two questions

后端 未结 4 1986
遥遥无期
遥遥无期 2020-12-08 07:28

Question #1 - When specifying an inline style in an HTML element, is it necessary to include a trailing semi-colon? For example ...

4条回答
  •  广开言路
    2020-12-08 07:40

    Question 1: Not required for your first question as written, but you would need to have the semi-colon if multiple definitions were present.

    Question 2: Spaces are not required unless you are separating values in a specific property, such as: box-shadow:0 0 5px 0 #000;

    One reason that you may want to add them in anyway, at least in a CSS-file context, would be that if you ever needed to run the CSS through a post-processor, like Sass, not having the semi-colons at the end of the line will cause the compiler to fail.

    In summary, then: For inline styles, the above answers apply, but for CSS in separate files on the file system, I would always add the extra semi-colons and spaces to make it easier to read. You can always run your CSS through a compressor when you are ready for production.

提交回复
热议问题