html - 如何在标题的底部中间添加一个半圆?

标签 html css shapes css-shapes

这是我想要的样子:

header with half circle at bottom

我意识到这是一个丑陋的模型,显然当我真正这样做时,比例看起来会更好,但我想知道您将如何使用 CSS 来实现这一点。

fiddle 在这里 http://jsfiddle.net/bU3QS/1/

<div class="header">
    </div>

.header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background: #000;
    z-index: 10000;
    height: 110px;
    overflow: hidden;
}

最佳答案

使用:after伪元素:

.header:after {
    content: '';
    position: absolute;
    background: black;
    width: 50px;
    height: 50px;
    z-index: 1;
    border-radius: 50%;    /* Makes the element circular */
    bottom: -25px;
    left: 50%;
    margin-left: -25px;
}

对于此解决方案,overflow: hidden; 已从 .header CSS 中删除。

这是一个 fiddle :http://jsfiddle.net/t97AX/

这是另一种方法,它不依赖于半圆的宽度来正确居中:

.header:after {
    content: '';
    position: relative;
    top: 100%;
    display: block;
    margin: 0 auto;
    background: red;
    width: 50px;
    height: 25px;
    border-radius: 0 0 50px 50px;
}

fiddle (为清楚起见,红色半圆):http://jsfiddle.net/x4mdC/

关于 :before:after 的更多信息:http://www.w3.org/TR/CSS2/selector.html#before-and-after

关于html - 如何在标题的底部中间添加一个半圆?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18033468/

相关文章:

html - 填充宽度时无法拉伸(stretch)div

html - 溢出 :hidden not working on mobile App

html - 我在网站的左侧和底部得到空白

processing - 当线条分割 Canvas 时,单独的形状 + 选择点以从数组中绘制形状

css - 如何用CSS制作这个双线形状?

浏览器的 HTML 框架标记 URL 未更改

javascript - 粘性导航栏 - 仅在移动设备上显示

css - 为什么 IE8 在我的图像 anchor 标记上添加底部边框?

css - 选择一个 anchor (<a>) 和一个具有相同 :target 的 ID-ed div

android - 可绘制资源中带有形状的文本