How do I make a transparent border with CSS?

后端 未结 9 1309
时光说笑
时光说笑 2020-12-13 23:04

I have an li styled as follows:

li{
    display:inline-block;
    padding:5px;
    border:1px solid none;
}
li:hover{
    border:1px solid #FC0;         


        
相关标签:
9条回答
  • 2020-12-13 23:19

    You can use "transparent" as a colour. In some versions of IE, that comes up as black, but I've not tested it out since the IE6 days.

    http://www.researchkitchen.de/blog/archives/css-bordercolor-transparent.php

    0 讨论(0)
  • 2020-12-13 23:25

    hey this is the best solution I ever experienced.. this is CSS3

    use following property to your div or anywhere you wanna put border trasparent

    e.g.

    div_class { 
     border: 10px solid #999;
     background-clip: padding-box; /* Firefox 4+, Opera, for IE9+, Chrome */
    }
    

    this will work..

    0 讨论(0)
  • 2020-12-13 23:26

    This blog entry has a way to emulate border-color: transparent in IE6. The below example includes the "hasLayout" fix that is brought up in the blog entry comments:

    /* transparent border */
    .testDiv {
        width: 200px;
        height: 200px;
        border: solid 10px transparent;
    }
    /* IE6 fix */
    *html .testDiv {
        zoom: 1;
        border-color: #FEFEFE;
        filter: chroma(color=#FEFEFE);
    }
    

    Make sure that the border-color used in the IE6 fix is not used anywhere in the .testDiv element. I changed the example from pink to #FEFEFE because that seems even less likely to be used.

    0 讨论(0)
  • 2020-12-13 23:27

    Yep, you can use border: 1px solid transparent

    Another solution is to use outline on hover (and set the border to 0) which doesn't affect the document flow:

    li{
        display:inline-block;
        padding:5px;
        border:0;
    }
    li:hover{
        outline:1px solid #FC0;
    }
    

    NB. You can only set the outline as a sharthand property, not for individual sides. It's only meant to be used for debugging but it works nicely.

    0 讨论(0)
  • 2020-12-13 23:27

    Use transparent property

    border-color : transparent;
    
    0 讨论(0)
  • 2020-12-13 23:28

    Many of you must be landing here to find a solution for opaque border instead of a transparent one. In that case you can use rgba, where a stands for alpha.

    .your_class {
        height: 100px;
        width: 100px;
        margin: 100px;
        border: 10px solid rgba(255,255,255,.5);
    }
    

    Demo

    Here, you can change the opacity of the border from 0-1


    If you simply want a complete transparent border, the best thing to use is transparent, like border: 1px solid transparent;

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