Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
705 views
in Technique[技术] by (71.8m points)

performance - CSS shorthand vs longhand?

Which one better? Using shorthand like:

padding:5px 10px 15px 20px;

Or using longhand like:

padding-top:5px;
padding-right:10px;
padding-bottom:15px;
padding-left:20px;

Related to:

  • performance (browser performance, filesize)
  • documentation (easy maintenance by developer)
  • and others
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  • You shouldn't worry about CSS performance unless you have profiled the page load and it has became the bottleneck (I doubt, it is almost always multiple HTTP requests and images).
  • Any competent developer can remember clockwise from top for the order of values.
  • Shorthand means less bytes to be sent, which a CSS minifier doesn't optimise itself (I don't think).
  • I'd only use the long method if setting one value, e.g. padding-left: 3px.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...