Ich habe einer custom.css-Site eine Menge zusätzliches CSS hinzugefügt, und das Stylesheet war ein wenig durcheinander.Korrekte Formatierung für custom.css
Ich habe mich entschieden, das benutzerdefinierte Stylesheet (custom.css) in Abschnitte der Website zu zerlegen, um es sauber zu halten mit/* --- und Caps für jeden Block von CSS.
Kommentare wurden hinzugefügt, wo nicht sofort ersichtlich ist, was in dieser Stiländerung passiert.
Dann schließlich @media Anfragen wurden an der Unterseite jeden Taktabschnitt (anstatt eine langen Liste unten) hinzugefügt
Gibt es einen Industriestandard, wie Stylesheets formatiert werden soll und was die oben erstellen irgendwelche Probleme? Bedenkt, dass es auch ein unberührtes stylesheet.css gibt.
Hier ist ein kleines Beispiel dafür, was ich getan habe:
/*------------------------------------
MAIN CONTENT
------------------------------------*/
@import url('https://fonts.googleapis.com/css?family=Open+Sans');
body {
font-family: "Open Sans";
font-weight: 400;
font-style: normal;
font-size: 13px;
color:#000;
}
h1 {
font-size: 22px;
}
a {
color: #333;
}
/* Move * on account page */
.form-horizontal .has-feedback .form-control-feedback {
padding-top: 10px;
}
/* Sort line gaps in category box */
#columnLeft > .panel > .panel-body .nav > li > a {
padding: 1px 15px;
}
/* Widen side column when they appear to thin */
@media (min-width: 992px) and (max-width: 1265px) {
.col-md-pull-8 {
right: 60%;
}
.col-md-push-2 {
left: 20%;
}
.col-md-2 {
width: 20%;
}
.col-md-8 {
width: 60%;
}
}
/*------------------------------------
PRODUCT PAGE
------------------------------------*/
.page-header > h1 > a > span {
color:#000;
}
.page-header > h1 > small > span {
color:#000;
}
/* Remove filter by on Category and Distributors Page */
#bodyContent > .contentContainer > div > div.well.well-sm {
display:none;
}
.productlogo {
width: 90px !important;
}
/*------------------------------------
NAV MENUS
------------------------------------*/
i.fa.fa-chevron-down {
float: none;
}
i.fa.fa-bars {
float: left;
position: relative;
top: 7px;
}
/* Set mobile select button */
.navbar-default .navbar-toggle {
background-color: #333 !important;
color: white;
}
/* Enlarge side columns */
@media (min-width: 768px) and (max-width: 991px) {
#bs-navbar-collapse {
display: -webkit-box !important;
display: -ms-flexbox !important;
display: flex !important;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-direction: row;
flex-direction: row;
-ms-flex-pack: distribute;
justify-content: space-around;
}
}
@media (min-width:992px) {
/* Show category menu to 992px width */
#catMenu {
display: none;
}
}
/*------------------------------------
ACCOUNT HEADER BUTTONS
------------------------------------*/
#headerShortcuts {
margin-top: 10px;
}
.accountLinkList > li {
padding-left: 15px;
}
/* Slightly smaller cart buttons in top right of page */
@media (min-width:768px) and (max-width:1065px) {
#headerShortcuts {
width: 39%;
margin-bottom: 10px;
margin-top: 12px;
padding: 0;
}
}
/* Change font size and padding on cart buttons */
@media (max-width:425px) {
#headerShortcuts > .btn-group >.btn {
padding: 3px 2px;
font-size: 11px;
}
}
/*------------------------------------
OFFERS PROMO BOX
------------------------------------*/
/* Home Page Offers */
.offerscontainer {
margin:0 auto;
width:610px;
height:320px;
}
.offeroftheday {
float: left;
}
.freeshipping {
float: right;
}
.24hrdelivery {
float: left;
clear: left;
padding-top:15px;
}
@media (max-width: 770px) {
.offerscontainer {
width:100%;
margin: 0 auto;
height:auto;
}
.offeroftheday{
float: right;
display:none;
}
.freeshipping{
float: none;
}
.24hrdelivery {
float: none;
clear:both;
}
}
Kein "Industriestandard" an sich. Viele Leute verwenden jetzt Vorprozessoren wie SASS oder LESS, um ihr CSS besser zu organisieren und mehr logische Strukturen in ihren CSS-Dateien zu erstellen. Aber ich würde sagen, es hängt alles davon ab, was für Sie als Entwickler Sinn macht. –
Es ist alles eine Frage der Präferenz, einige Leute mögen die Einzeilige Stile mit jedem Selektor in einer neuen Zeile, manche mögen das Verschachteln pro Abschnitt und andere wie das Kommentarsystem. Ich würde sagen, gehen Sie mit dem, was Sie am einfachsten zu lesen und zu pflegen und dann, wenn Sie die Website bereitstellen, verwenden Sie eine verkleinerte Version – Pete