CSS Inset Borders

前端 未结 12 1644
没有蜡笔的小新
没有蜡笔的小新 2020-12-02 15:26

I need to create a solid color inset border. This is the bit of CSS I\'m using:

border: 10px inset rgba(51,153,0,0.65);

Unfortunately that cr

相关标签:
12条回答
  • 2020-12-02 15:42

    I know this is three years old, but thought it might be helpful to someone.

    The concept is to use the :after (or :before) selector to position a border within the parent element.

        .container{
            position:relative; /*Position must be set to something*/
        }
    
        .container:after{
            position:relative;
            top: 0;
            content:"";
            left:0;
            height: 100%; /*Set pixel height and width if not defined in parent element*/
            width: 100%; 
    
            -webkit-box-sizing:border-box;
            -moz-box-sizing:border-box;
            -ms-box-sizing:border-box;
            box-sizing:border-box;
    
            border:1px solid #000; /*set your border style*/
    
        }
    
    0 讨论(0)
  • 2020-12-02 15:45

    So I was trying to have a border appear on hover but it moved the entire bottom bar of the main menu which didn't look all that good I fixed it with the following:

    #top-menu .menu-item a:hover {
        border-bottom:4px solid #ec1c24;
        padding-bottom:14px !important;
    }
    #top-menu .menu-item a {
        padding-bottom:18px !important;
    }
    

    I hope this will help someone out there.

    0 讨论(0)
  • 2020-12-02 15:47

    You can do this:

    .thing {
      border: 2px solid transparent;
    }
    .thing:hover {
      border: 2px solid green;
    }
    
    0 讨论(0)
  • 2020-12-02 15:48

    I don't know what you are comparing to.

    But a super simple way to have a border look inset when compared to other non-bordered items is to add a border: ?px solid transparent; to whatever items do not have a border.

    It will make the bordered item look inset.

    http://jsfiddle.net/cmunns/cgrtd/

    0 讨论(0)
  • 2020-12-02 15:53

    It's an old trick, but I still find the easiest way to do this is to use outline-offset with a negative value (example below uses -6px). Here's a fiddle of it—I've made the outer border red and the outline white to differentiate the two:

    .outline-offset {
    width:300px;
    height:200px;
    background:#333c4b;
    border:2px solid red;
    outline:2px #fff solid;
    outline-offset:-6px;
    }
    
    <div class="outline-offset"></div>
    
    0 讨论(0)
  • 2020-12-02 15:57

    I would recomnend using box-sizing.

    *{
      -webkit-box-sizing:border-box;
      -moz-box-sizing:border-box;
      -ms-box-sizing:border-box;
      box-sizing:border-box;
    }
    
    #bar{
      border: 10px solid green;
      }
    
    0 讨论(0)
提交回复
热议问题