CSS Inset Borders

前端 未结 12 1698
没有蜡笔的小新
没有蜡笔的小新 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:38

    Simple SCSS solution with pseudo-elements

    Live demo: https://codepen.io/vlasterx/pen/xaMgag

    // Change border size here
    $border-width: 5px;
    
    .element-with-border {
    	display: flex;
    	height: 100px;
    	width: 100%;
    	position: relative;
    	background-color: #f2f2f2;
    	box-sizing: border-box;
    	
    	// Use pseudo-element to create inset border
    	&:before {
    		position: absolute;
    		content: ' ';
    		display: flex;
    		border: $border-width solid black;
    		left: 0;
    		right: 0;
    		top: 0;
    		bottom: 0;
    		border: $border-width solid black;
    		// Important: We must deduct border size from width and height
    		width: calc(100% - $border-width); 
    		height: calc(100% - $border-width);
    	}
    }
    Lorem ipsum dolor sit amet

提交回复
热议问题