Is there a 'box-shadow-color' property?

后端 未结 7 1584
情深已故
情深已故 2020-12-04 10:31

I have the following CSS:

box-shadow: inset 0px 0px 2px #a00;

Now I am trying to extract that color to make the page colors \'skinnable\'.

相关标签:
7条回答
  • 2020-12-04 10:59

    Maybe this is new (I am also pretty crap at css3), but I have a page that uses exactly what you suggest:

    -moz-box-shadow: 10px 10px 5px #384e69;
    -webkit-box-shadow: 10px 10px 5px #384e69;
    box-shadow: 10px 10px 5px #384e69;}
    

    .. and it works fine for me (in Chrome at least).

    0 讨论(0)
  • 2020-12-04 11:02

    You could use a CSS pre-processor to do your skinning. With Sass you can do something similar to this:

    _theme1.scss:

    $theme-primary-color: #a00;
    $theme-secondary-color: #d00;
    // etc.
    

    _theme2.scss:

    $theme-primary-color: #666;
    $theme-secondary-color: #ccc;
    // etc.
    

    styles.scss:

    // import whichever theme you want to use
    @import 'theme2';
    
    -webkit-box-shadow: inset 0px 0px 2px $theme-primary-color;
    -moz-box-shadow: inset 0px 0px 2px $theme-primary-color;
    

    If it's not site wide theming but class based theming you need, then you can do this: http://codepen.io/jjenzz/pen/EaAzo

    0 讨论(0)
  • 2020-12-04 11:08

    Yes there is a way

    box-shadow 0 0 17px 13px rgba(30,140,255,0.80) inset
    
    0 讨论(0)
  • 2020-12-04 11:14

    No:

    http://www.w3.org/TR/css3-background/#the-box-shadow

    You can verify this in Chrome and Firefox by checking the list of computed styles. Other properties that have shorthand methods (like border-radius) have their variations defined in the spec.

    As with most missing "long-hand" CSS properties, CSS variables can solve this problem:

    #el {
        --box-shadow-color: palegoldenrod;
        box-shadow: 1px 2px 3px var(--box-shadow-color);
    }
    
    #el:hover {
        --box-shadow-color: goldenrod;
    }
    
    0 讨论(0)
  • 2020-12-04 11:15

    Actually… there is! Sort of. box-shadow defaults to color, just like border does.

    According to http://dev.w3.org/.../#the-box-shadow

    The color is the color of the shadow. If the color is absent, the used color is taken from the ‘color’ property.

    In practice, you have to change the color property and leave box-shadow without a color:

    box-shadow: 1px 2px 3px;
    color: #a00;
    

    Support

    • Safari 6+
    • Chrome 20+ (at least)
    • Firefox 13+ (at least)
    • IE9+ (IE8 doesn't support box-shadow at all)

    Demo

    div {
        box-shadow: 0 0 50px;
        transition: 0.3s color;
    }
    .green {
        color: green;
    }
    .red {
        color: red;
    }
    div:hover {
        color: yellow;
    }
    
    /*demo style*/
    body {
        text-align: center;
    }
    div {
        display: inline-block;
        background: white;
        height: 100px;
        width: 100px;
        margin: 30px;
        border-radius: 50%;
    }
    <div class="green"></div>
    <div class="red"></div>

    The bug mentioned in the comment below has since been fixed :)

    0 讨论(0)
  • 2020-12-04 11:15

    A quick and copy/paste you can use for Chrome and Firefox would be: (change the stuff after the # to change the color)

    -moz-border-radius: 10px;
    -webkit-border-radius: 10px;
    -khtml-border-radius: 10px;
    -border-radius: 10px;
    -moz-box-shadow: 0 0 15px 5px #666;
    -webkit-box-shadow: 0 0 15px 05px #666;
    

    Matt Roberts' answer is correct for webkit browsers (safari, chrome, etc), but I thought someone out there might want a quick answer rather than be told to learn to program to make some shadows.

    0 讨论(0)
提交回复
热议问题