只要部分左边框,css怎么写?

只想要红色部分的边框,怎么写?最好不用伪类image.png

阅读 4.1k
5 个回答
  1. dom 嵌套,里面小盒子设置左边框
  2. after 等方法,absolute定位
  3. box-shadow, 效果应该还是有细微的偏差的

父级div套用子级div,设置好border padding 与margin,只显示子级左边框不同颜色就好了。如下

`
<!DOCTYPE html>
<html>
<head>

<style>
  .out {
    padding: 10px 10px 10px 0;
    border-color: black;
    border-style: solid;
  }
  .in {
    margin-left: -3px;
    border-left-style: solid;
    : solid;
    border-left-color: coral;
  }
</style>

</head>
<body>

<h1>A heading with a colored left border</h1>
<div class='out'>
  <div class='in'>The border-left-color can be specified with a color name</div>
</div>

</body>
</html>
微信截图_20200516133816.png`

如果不是“一定不要伪类(其实是伪元素)”,那么建议用伪元素,其它办法我觉得没有非常合适的。

不知道两个DIV 嵌套起来, 调整一个Div的border-left可以达到你要的效果不

1:使用伪类;
2:增加外部容器并设置 border,当前元素当成文本容器并设置 border-left;
3:内部增加子元素,替代伪类;
4:使用 border-image

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题