如何清理这个CSS代码;缩短或删除不必要的部分(需要CSS完美主义者)

如何清理这个CSS代码;缩短或删除不必要的部分(需要CSS完美主义者),css,Css,我如何清理这个CSS代码:缩短它,将属性嵌套在一起,删除不必要的代码,等等 /* reset */ html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, str

我如何清理这个CSS代码:缩短它,将属性嵌套在一起,删除不必要的代码,等等

/* reset */
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {
    margin: 0;
    padding: 0;
    border: 0;
    outline: 0;
    font-size: 100%;
    vertical-align: baseline;
    background: transparent;
}
body { line-height: 1; }
ol, ul { list-style: none; }
blockquote, q { quotes: none; }
blockquote:before, blockquote:after, q:before, q:after {
    content: '';
    content: none;
}
:focus { outline: 0; } /* remember to define focus styles! */
ins { text-decoration: none; } /* remember to highlight inserts somehow! */
del { text-decoration: line-through; } /* tables still need 'cellspacing="0"' in the markup */
table {
    border-collapse: collapse;
    border-spacing: 0;
}
/* tags */
body {
    background: #F9F9F9;
    color: #888;
    font-family: Arial, "微软雅黑", "MS Trebuchet", sans-serif;
    font-size: 75%
}
h1 {
    font-size: 32px;
}
h2 {
    /*color: #999;*/
    color: #999;
    font-size: 14px;
    margin: 0 0 20px 0;
}
p {
    line-height: 160%;
}
a {
    color: #69C;
    list-style: none;
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}
/* structure */
.container {
    margin: 0 auto;
    overflow: hidden;
    padding: 0 15px;
    width: 960px;
}
/* header */
#header {
    background: #EEE;
}
#header h1 {
    float: left;
}
#header h1 a {
    background: url(../images/logo.png) no-repeat scroll 0 0;
    float: left;
    height: 30px;
    text-indent: -9999px;
    width: 500px;
}
/* banner */
#header-top {
    border-bottom: 1px solid #DDD;
    padding: 0 0 15px 0;
    margin: 30px 0;
    overflow: hidden;
    width: 960px; /* ie6 hack */
}
#lang {
    float: right;
    padding: 20px 0 0 0;
}
#lang li {
    float: left;
}
#lang li a {
    font-size: 10px;
    float: left;
    margin: 0 0 0 20px;
}
#lang li a.current {
    color: #888;
}
/* intro */
#header-bottom {
    overflow: hidden;
    padding: 0 0 30px 0;
}
#tagline {
    float: left;
    margin: 0 40px 0 0;
    width: 540px; /* 560 */
}
#tagline h2 {
    font-size: 24px;
}
#tagline h2 strong {
    /*color: #69C;*/
}
#about {
    float: right;
    width: 380px;
}
/* work */
#content {
    background-color: #F9F9F9;
}
.showcase {
    border-bottom: 1px solid #DDD;
    margin: 30px 0 0;
    overflow: hidden;
    padding: 0 0 30px;
    width: 960px; /* ie hack */
}
.showcase div.right {
    display: inline; /* ie hack */
    float: left;
}
.showcase div.left {
    display: inline; /* ie hack */
    float: left;
    height: 211px;
    margin: 0 20px 0 0;
    position: relative;
    width: 290px;
}
.showcase div img {
    border: 2px solid #EEE;
    width: 630px;
    height: 190px;
    padding: 8px;
}
.showcase div img:hover {
    border: 2px solid #CDE;
}
.showcase div p {
    margin: 0 0 20px 0;
}
.showcase div ul#sites {
    position: absolute;
    bottom: 0;
    overflow: hidden;
    line-height: 160%;
}
.showcase div ul#sites li {
    float: left;
}
.showcase div ul#sites li a {
    border: 1px solid #9CF;
    color: #69C;
    float: left;
    padding: 0 5px;
    margin: 0 20px 0 0;
    text-decoration: none;
}
.showcase div ul#sites li a:hover {
    border: 1px solid #69C;
}
.showcase div ul#details {
    line-height: 160%;
}
/* footer */
#footer {
    background-color: #333;
    color: #BBB;
    clear: both;
}
#footer h2 {
    color: #EEE;
}
#footer p {
    color: #BBB;
}
/* contact */
#footer-top {
    border-bottom: 1px solid #444;
    line-height: 160%;
    overflow: hidden;
    padding: 30px 0;
    width: 960px; /* ie6 hack */
}
#footer-top div {
    overflow: hidden;
}
#contact {
    float: left;
    margin: 0 40px 0 0;
    overflow: hidden;
}
#contact form {
    margin: 20px 0 0;
}

#sendmail label {
    width: 250px;
    margin: 0 0 10px 0;
}
#sendmail label.error{
    color: #FF4444;
    margin: 0 0 20px 0;
}
#sendmail label {
    display: block;
    vertical-align: top;
    cursor: hand;
}
#name, #email, #message {
    border: 0;
    background-color: #444;
    font-family: Arial, "MS Trebuchet", sans-serif;
    color: #BBB;
    font-size: 12px;
    padding: 6px;
    margin: 0 0 10px;
    width: 380px;
}
#name:focus, #email:focus, #message:focus {
    background-color: #555;
}
#message {
    height: 200px;
    overflow: auto;
}
#button {
    background-color: #69C;
    border-color: #69C;
    border-style: solid;
    border-width: 1px;
    color: #FFFFFF;
    cursor: pointer;
    display: block;
    font-family: Arial, "MS Trebuchet", sans-serif;
    margin-top: 10px;
    padding: 2px;
    width: 100px
}
#button:hover {
    background-color: #49C;
    border-color: #49C;
}
/*\*//*/ form.contact legend { display: inline-block; } /* IE Mac legend fix */
#info {
    float: right;
    width: 303px;
    margin: 0 0 0 40px;
}
#tools {
    float: right;
    margin: 0 0 0 40px;
    width: 83px;
}
/* about */
#footer-bottom {
    font-size: 10px;
    margin: 15px auto;
}

编辑:…或者您知道任何css优化器将css选择器和属性嵌套在一起吗?

首先删除所有css漏洞,并将它们放在其他特定于浏览器的文件中,您将通过以下方式将其包括在内。

如果您有边距:0 0 20px 0;-您可以删除最后的0,因为这是与右侧相同的左边距

如果你用谷歌搜索css,有一些在线工具可以优化css(例如)。不过,在优化和可维护性之间有一条细线。如果删除所有注释等,则会使文件变小但不易维护。同样,您可以删除所有换行符以生成更小的文件,但不确定这是否更好

我可能不会使用重置


对我来说,你的CSS看起来已经很紧凑了。

你可以删除
/*\*/*/*/form.contact legend{display:inline block;}/*IE Mac legend fix*/
-甚至微软也不再支持Mac IE了。

你有5kb的CSS,如果你这样做的话就更少了。我认为,尝试进一步优化任何东西都比不上你花3秒钟的时间,真的。

似乎可以做到这一点。您可以在一系列不同的选项中进行选择。看看它,看看它是否对你有用

打开#按钮

可以更简洁地写为

border:1px solid #69c;

好问题。昨天我在想,一个整合CSS的工具绝对是了不起的。可能是从传统CSS创建文件的东西?:我不认为像这样的特定css文件比现在短很多。看起来拆分这么多css类是有正当理由的。“我可能不会使用重置。”-但是从现有样式表中删除重置有点冒险。很难说什么是可靠的,什么是不可靠的。是的,但我不会把它放在一开始/打算建议它,尽管你比我快:PBad点在那里。你不应该使用单独的样式表来包含黑客。为什么你要加载针对所有其他浏览器IE的黑客?
border:1px solid #69c;