2014-09-19 48 views
-3

你好,我只是想知道我将如何做到两个元素具有相同的风格,但也有一些样式不同的例子,我想如何编译。SASS元素相同的风格,但有些不同

.bubble-right, 
.bubble-left { 
    font-size: 16px; 
    padding: 50px 40px; 
    text-align: center; 
    color: white; 
    width: 225px; 
    height: 224px; 
    font-weight: bold; 
    background-image: url('../images/Speech-bubble-FDEB1.png'); 
} 

.bubble-right { 
    float: right; 
    margin: 0 0 25px 25px; 
} 

.bubble-left { 
    float: left; 
    margin: 0 25px 25px 0; 
} 
+0

制作一个通用的'bubble'类,然后制作一个包含差异的'bubble-left'和'bubble-right'。 – gunr2171 2014-09-19 15:17:34

回答

1

就像gunr2171说,你会作出沿下面的代码行的东西。两个元素将共享泡沫类,并且每个单独的元素将具有作为另一个类的泡泡向左或向右泡泡。我创建了以下scss格式的示例:

.bubble{ 
    font-size: 16px; 
    padding: 50px 40px; 
    text-align: center; 
    color: white; 
    width: 225px; 
    height: 224px; 
    font-weight: bold; 
    background-image: url('../images/Speech-bubble-FDEB1.png'); 
    &.bubble-left{ 
     float: left; 
     margin: 0 25px 25px 0; 
    } 

    &.bubble-right { 
     float: right; 
     margin: 0 0 25px 25px; 
    } 
} 
+1

是的,这是做到这一点。如果你想更清理它,你可以把'&.bubble-left'改成'&-left',而右边则是相同的。 – somethinghere 2014-09-19 15:27:43

1

非常务实:

.bubble { 
    font-size: 16px; 
    margin-bottom: 25px; 
    padding: 50px 40px; 
    text-align: center; 
    color: white; 
    width: 225px; 
    height: 224px; 
    font-weight: bold; 
    background-image: url('../images/Speech-bubble-FDEB1.png'); 
} 

.bubble-right { 
    @extend .bubble; 
    float: right; 
    margin-left: 25px; 
} 

.bubble-left { 
    @extend .bubble; 
    float: left; 
    margin-right: 25px; 
} 
相关问题