html - DIV 内带有背景的元素,圆角溢出
问题描述
我把头撞在 HTML/CSS 墙上。我试图在带有圆角的 DIV 顶部放置一个彩色标题。标题的背景超出了包含 DIV 的圆角范围。
我尝试将 abackground-clip:padding-box
应用于 theDIV
和H1
' 样式但没有任何效果。我尝试将 aborder-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>
(也在小提琴中)
解决方案
检查此代码,这是您要找的东西吗?
overflow: hidden
隐藏任何越过.outer_box
边界的东西
只是padding: 10px;
为了让它看起来不错。
<!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;
overflow: hidden;
}
.title {
width: 100%;
background: #00f;
color: #fff;
margin-top:0;
background-clip: padding-box;
padding: 10px;
}
</style>
</head>
<body>
<div class="outer_box">
<h1 class="title">Here's a title</h1>
<p>Here's some content.</p>
</div>
</body>
</html>
推荐阅读
- javascript - 在 Chrome 中关闭标签时如何切换到正在运行的程序
- kubernetes - 如何在 Kubernetes 上制作可靠、可扩展的 redis
- c# - 如何通过打开上下文操作菜单从 ListView 中获取所选项目?(Xamarin.Forms)
- python - 如何在前馈神经网络中使用 RGB 值?
- javascript - 如何强制用户启用 Java 脚本?
- r - 如何在 R 中解决“与 api.twitter.com:443 相关的未知 SSL 协议错误”
- html - 轮播无法将图像 div 移到中心
- java - 如何在独立的命令行应用程序(jar-with-dependencies)中关闭所有日志记录(即使是依赖项)
- excel - 确定受保护的视图选项在文档中是否处于活动状态
- mysql - 将 clearDB 数据库备份到本地