【发布时间】:2020-06-25 12:43:48
【问题描述】:
我的头撞到了 HTML/CSS 墙上。我试图在带有圆角的 DIV 顶部放置一个彩色标题。标题的背景超出了包含 DIV 的圆角范围。
我尝试将background-clip:padding-box 应用于DIV 和H1 的样式,但没有任何效果。我已经尝试将border-radius 应用到H1,但由于高度不同,所以边角不会对齐以达到预期的效果。
任何想法我在这里缺少什么?
<!DOCTYPE html>
<html>
<head>
<title>Rounded Edges With Background</title>
<style>
body,
html {
width: 100%;
height: 100%;
}
.outer_box {
width: 500px;
background: #fff;
border: 2px solid #000;
border-radius: 25px;
}
.title {
width: 100%;
background: #00f;
color: #fff;
margin-top:0;
background-clip: padding-box;
}
</style>
</head>
<body>
<div class="outer_box">
<h1 class="title">Here's a title</h1>
<p>Here's some content.</p>
</div>
</body>
</html>
(也在fiddle中)
【问题讨论】: