方法一: border-left
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.boder_left {
width: 200px;
height: 40px;
line-height: 40px;
padding-left: 20px;
background-color: pink;
border-left: 5px solid black;
}
</style>
</head>
<body>
<div class="boder_left">
这是一个标题
</div>
</body>
</html>
效果图
方法二:伪元素(在前面添加一个矩形)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.boder_left {
width: 200px;
height: 40px;
line-height: 40px;
background-color: pink;
position: relative;
}
.boder_left::before {
position: absolute;
content: "";
display: inline-block;
width: 6px;
height: 30px;
background-color: #014790;
top: 5px;
border-radius: 3px;
}
.boder_left span {
padding-left: 20px;
}
</style>
</head>
<body>
<div class="boder_left">
<span>这是一个标题</span>
</div>
</body>
</html>
效果图
参考链接:https://developer.mozilla.org/zh-CN/docs/Web/CSS/border-radius