CSS 思维

泾渭分明

两个元素中的间隔属于谁?

Padding
Margin
Border

Box model

狡兔三窟

元素、Class、属性是什么关系?

如何创建class

  • 将样式分类为位置、结构、皮肤、字体
  • 将不同类的样式用花括号包起来
  • 以其功能或场景为这些样式组命名,作为class name

position display overflow float

width height margin padding border

background box-shadow color

font-size white-space letter-space word-wrap

OOCSS

分离结构与皮肤

分离容器与内容

<div class="container">
    <div class="section header">
        <div class="content border background"></div>
    </div>
    <div class="section main">
        <div class="content">
            <div class="section">
                <i class="icon icon-xxx icon-big"></i>
                <h1 class="title"></h1>
            </div>
            <div class="section">
                <ul class="list">
                    <li class="item red"></li>
                    <li class="item yellow half active"></li>
                    <li class="item blue half"></li>
                    <li class="item black"></li>
                </ul>
            </div>
        </div>
    </div>
</div>

在其位 谋其事

选择器是什么?

选择器的内涵

  • div > span 子代选择器 - 是我儿子就得...
  • a + span 兄弟选择器 - 旁边的兄弟,你必须...
  • wrap * 后代通配选择器 - 在我里面的全都得...
  • select.text 标签选择器 - 又是text又是select,那你还不得...
  • .item 类选择器 - 这类东西都是...
  • #one ID选择器 - 毫无内涵...

似是而非

两段CSS看起来一样?

.button {
    overflow: hidden;
    position: relative;
    display: inline-block;
    width: 120px;
    height 60px;
    margin: 2%;
    padding: 0 20px;
    color: #45F933;
    font-size: 1em;
    font-weight: 300;
    font-family: inherit;
    font-style: normal;
    background: #1e5799; /* Old browsers */
    background: -moz-linear-gradient(top, #1e5799 0%, #2989d8 50%, #207cca 51%, #7db9e8 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#1e5799), color-stop(50%,#2989d8), color-stop(51%,#207cca), color-stop(100%,#7db9e8)); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* IE10+ */
    background: linear-gradient(to bottom, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#7db9e8',GradientType=0 ); /* IE6-9 */
}
.navigator {
    overflow: hidden;
    position: relative;
    display: block;
    min-width: 120px;
    height 60px;
    margin: 2%;
    padding: 0 20px;
    color: #45F933;
    font-size: 1em;
    font-weight: 300;
    font-family: inherit;
    font-style: normal;
    background: #1e5799; /* Old browsers */
    background: -moz-linear-gradient(top, #1e5799 0%, #2989d8 50%, #207cca 51%, #7db9e8 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#1e5799), color-stop(50%,#2989d8), color-stop(51%,#207cca), color-stop(100%,#7db9e8)); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* IE10+ */
    background: linear-gradient(to bottom, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#7db9e8',GradientType=0 ); /* IE6-9 */
}

The End

Thanks

CSS思维

By Zhengzheng ZHANG

CSS思维

  • 1,823