【问题标题】:Display hex color created by sass显示由 sass 创建的十六进制颜色
【发布时间】:2014-08-19 21:05:03
【问题描述】:

我这里有一个简单的页面:

http://www.ttmt.org.uk/color/

中心块颜色保存为sass中的变量

两边方块的颜色是用 sass 的变亮和变暗创建的。

是否可以显示sass创建的这些较浅和较深颜色的实际十六进制数。

颜色的十六进制显示在输出 css 中,但我希望能够动态执行并在块中显示十六进制颜色。

我在 scss 文件中有颜色

    $base-blue: #267EC8;

    // Blue

    .at-blue{
        background-color: $base-blue;
    }

    .at-blue-lighter{
        background-color: lighten($base-blue, 20%);
    }

    .at-blue-light{
        background-color: lighten($base-blue, 10%);
    }

    .at-blue-dark{
        background-color: darken($base-blue, 10%);  
    }

    .at-blue-darker{
        background-color: darken($base-blue, 20%);  
    }

然后我在html中使用类名

    <div class="my_Box at-blue-lighter" >.at-blue-lighter<span></span></div>
    <div class="my_Box at-blue-light" >.at-blue-light<span></span></div>
    <div class="my_Box at-blue" >.at-blue <span></span></div>
    <div class="my_Box at-blue-dark" >.at-blue-dark<span></span></div>
    <div class="my_Box at-blue-darker" >.at-blue-darker<span></span></div>

并在单独的 scss 文件中设置框的样式

    .my_Box{
        text-align: center;
        height: 120px;
        float: left;
        padding: 10px;
        margin: 0 30px 0 0;
        width: 120px;

        span{
            display: block;
            font-size: 1.2em;
            margin: 10px 0 0 0;
        }
    }

【问题讨论】:

    标签: colors sass


    【解决方案1】:

    您可以使用content 显示它:http://jsfiddle.net/A9rML/

    $color : rgb(38, 126, 200);
    
    div{
        background-color: $color;
        &:after{
    
            content: "#{$color}";
            font-size: 42px;
            color: white;
        }
        width: 200px;
        height: 200px;
    }
    

    【讨论】:

    • JAre,这看起来很完美,但我是在单独的 scss 文件上动态创建颜色,但我不知道该怎么做。我已经用更多代码更新了我的问题。
    • @ttmt 您可以设置.at-blue-lighter{font size bg-color, text color and so on} 并在文件中使用颜色.at-blue-lighter:after{content: "#{$some-color}";} 然后after 将继承.at-blue-lighter 的字体大小和颜色等样式
    猜你喜欢
    • 2014-06-12
    • 2016-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-08
    • 2014-08-08
    • 2014-07-03
    • 2019-06-16
    相关资源
    最近更新 更多