我想知道,如果您像这样编写代码,浏览器的性能是否会有所不同:
<div class="css-1 css-2 css-3 css-4 css-5">
<div class="css-everything">
如果你把所有东西都放在.css中,而不是部分css类中,加载站点的速度会更快吗?
发布于 2012-06-25 23:00:02
正如你所说的那样,这是唯一的观点问题。没别的了。
Examples
假设您有如下场景:
场景:1
CSS:
.button {
width:100px;
border-radius: 5px;
}
.blueBG {
background-color: blue;
}
.redBG {
background-color: red;
}
.left{
float: left;
margin-left: 10px;
}
.right {
float: right;
margin-right: 10px;
}
HTML:
<a href="stackoverflow.com" class="button red left">StackOverflow</a>
<p class="blue">Text with blue background</p>
<img class="left" src="image.jpg"></img>
现在想一想,如果我在这里使用类似这样的代码:
CSS:
.blueButtonLeft {
width:100px;
border-radius: 5px;
background-color: blue;
float: left;
margin-left: 10px;
}
.blueButtonRight {
width:100px;
border-radius: 5px;
background-color: blue;
float: right;
margin-right: 10px;
}
.redButtonLeft {
width:100px;
border-radius: 5px;
background-color: red;
float: left;
margin-left: 10px;
}
.redButtonRight {
width:100px;
border-radius: 5px;
background-color: red;
float: right;
margin-right: 10px;
}
HTML:
<a href="stackoverflow.com" class="blueButtonLeft">StackOverflow</a>
<!-- Need of defferent code for img and p -->
我希望不同之处是显而易见的。难到不是么?
场景:2
很抱歉,我需要离开一段时间,我一定会回来,稍后再做更多修改。
https://stackoverflow.com/questions/11190414
复制相似问题