html - custom.css 的正确格式

标签 html css media-queries

我一直在向 custom.css 站点添加大量额外的 CSS,结果样式表有点乱。

我已决定将自定义样式表 (custom.css) 分成网站的多个部分,以使用/*--- 和每个 CSS block 的大写来保持其整洁。

在不能立即看出样式更改中发生了什么的地方添加了评论。

最后,@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 上调用导入)

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

  • 然后为每个页面/部分添加所有自定义样式,并用评论 block 清楚地提及

  • 然后我有我的助手类

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

注意事项

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

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

  • 使用 w3c 验证器进行验证以确保您走上正轨

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

希望对您有所帮助!

关于html - custom.css 的正确格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37545142/

相关文章:

html - 图像前的空白

javascript - 如何使用 JavaScript 根据用户输入的值检查数组值?

html - 如何使用 bootsrap3 嵌入 youtube 播放器和 facebook api?

css - Firefox 中的 svg 圆 Angular 剪裁(在 ie9 和 chrome 中工作正常)

css - 手机网站的理想视口(viewport)尺寸

html - 删除绝对定位 div 周围的空白空间

html - 将静态 Bootstrap 网站转换为响应式网站

javascript - Textarea block 重音字母和 alt 代码符号

html - 在中小型设备的轮播中显示一行中的一项

css - 如何使用 Flexbox 中的媒体查询控制每行的元素数?