css - 创建带有两个切 Angular 的边框

标签 css border

我想为我的网站创建一个带有两个切 Angular 的边框。对于不同的 div 大小,我需要这个边框。

大约一个小时后,我让它以 200 像素的固定大小工作。但我不知道如何获得这种灵 active 。

这是一个 Demo

HTML

<div id="outer"><span>Some Text</span></div>

CSS

body {background: #000;}

#outer {
    width: 200px;
    height: 200px;
    position: relative;
    margin: 0 auto;
    margin-top: 50px;
    background: #0ff;
}

#outer:before {
    content: "";
    height: 200px;
    left: -15px;
    position: absolute;  
    border-top: 15px solid transparent;
    border-right: 15px solid #fff;
}

#outer:after {
    content: "";
    width: 200px;
    height: 200px;
    top: -15px;
    right: -215px;
    position: absolute;
    border-left: 15px solid #fff;
    border-bottom: 15px solid transparent;
}


#outer span {
    width: 200px;
    height: 200px;
    position: absolute;
    padding: 50px;
}

#outer span:before {
    display: block;
    content: "";
    width: 200px;
    top: -15px;
    left: 0;
    position: absolute;
    border-bottom: 15px solid #fff;
    border-left: 15px solid transparent;
}

#outer span:after {
    display: block;
    content: "";
    width: 200px;
    height: 200px;
    top: 200px;
    left: -15px;
    position: absolute;
    border-top: 15px solid #fff;
    border-right: 15px solid transparent;
}

有人知道更好的解决方案吗?谢谢

最佳答案

您几乎拥有它。我调整了 fiddle 以使用百分比值作为尺寸和位置。不过边框仍然有 15 像素宽:

演示:http://jsfiddle.net/b48AK/show
来源:http://jsfiddle.net/b48AK

body {background: #8aa; padding:0px; margin:0px}
#outer {
  background: #bfb;
  position:relative;
  margin:15px;
} 

#outer:before { 
  content: ""; 
  height: 100%;
  left: -15px;
  position: absolute;  
  border-top: 15px solid transparent;
  border-right: 15px solid #fff;
} 

#outer:after { 
  content: ""; 
  width: 100%;
  height: 100%;
  top: -15px;
  left: 100%;
  position: absolute; 
  border-left: 15px solid #fff;
  border-bottom: 15px solid transparent;
} 

#outer span:before {
  display: block;
  content: "";
  width: 100%;
  top: -15px;
  left: 0;
  position: absolute;
  border-bottom: 15px solid #fff;
  border-left: 15px solid transparent;
}

#outer span:after {
  display: block;
  content: "";
  width: 100%;
  height: 100%;
  top: 100%;
  left: -15px;
  position: absolute;
  border-top: 15px solid #fff;
  border-right: 15px solid transparent;
}

关于css - 创建带有两个切 Angular 的边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13545192/

相关文章:

css - 使复选框+标签在表单中正确对齐

css - 在 SSRS 中设置默认虚拟目录列表样式的最佳方式是什么?

jquery - 突出显示包含来自输​​入的搜索文本的 td

css - 添加边框会打乱布局

jquery - 单击 anchor 和轮播控件将关闭模式

java - 在弹出窗口中使用 TextBubbleBorder

css - 覆盖 :hover 的伪标签上的边框

css - 菜单 'border-right: none' 不工作

css - 使用 CSS 使表格的外边框颜色与单元格的边框颜色不同

html - 如何在 HTML 和 CSS 中水平对齐的图像下添加文本