繁体   English   中英

正确格式的custom.css

[英]Correct formatting for custom.css

我一直在向custom.css网站添加很多额外的CSS,样式表最终变得一团糟。

我决定将自定义样式表(custom.css)分成网站的各个部分,以/ * ---保持整洁,并为每段CSS设置上限。

已添加注释,但不能立即看出样式更改中发生了什么。

最后,在每个时钟部分的底部添加了@media查询(而不是底部的一长串)

样式表的格式是否存在行业标准,以上内容是否会引起任何问题? 请记住,还有一个不变的stylesheet.css。

这是我所做的一个小例子:

    /*------------------------------------
        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;
    }
    }

我认为没有任何行业标准,取决于您要如何设置样式表。

我通常做的如下

  • 在顶部调用导入(尽管我大多数时候都尽量避免在CSS上调用导入)

  • 然后添加我所有的通用样式

  • 然后为每个页面/部分添加所有自定义样式,并用注释框明确提及

  • 然后我有我的助手班

  • 然后添加媒体查询(有时我也将媒体查询放在单独的CSS文件中)

注意事项

  • 尽量不要重复自己,尽可能重用样式规则

  • 避免使用下划线,因为旧的浏览器存在下划线问题

  • 使用w3c验证程序进行验证,以确保您步入正轨

  • 如果您习惯使用Sass或Less,请尝试使用它,因为它可以嵌套并提高代码的可读性

希望能有所帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM