4

Here is how I want it to look:

header with half circle at bottom

I realize this is an ugly mockup and obviously when I do it for real the proportions will look better, but I am wondering how you would go about doing this with CSS.

fiddle is here 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;
}
4

3 回答 3

7

Use the :after pseudo element:

.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;
}

For this solution, overflow: hidden; has been removed from the .header CSS.

Here's a fiddle: http://jsfiddle.net/t97AX/

Here's another approach, that doesn't rely on the width of the semicircle to center it properly:

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

The fiddle (semicircle red for the sake of clarity): http://jsfiddle.net/x4mdC/

More on :before and :after: http://www.w3.org/TR/CSS2/selector.html#before-and-after

于 2013-08-03T13:52:46.510 回答
2

Use :after and border-radius to create the semicircle.

.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background-color: #000;
    height: 110px;
    }
.header:after {
    content: '';
    background-color: red;
    position: absolute;
    display: block;
    width: 100px;
    top: 110px;
    left: 50%;
    margin-left: -50px;
    height: 50px;
    border-radius: 0 0 50px 50px;
}

Demo: http://jsfiddle.net/bU3QS/2/

于 2013-08-03T13:56:44.630 回答
-1
<div class="header">
    <div class="circle">
    </div>
    </div>
.header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background: #000;
    height: 110px;
}

.circle {
    height: 100px;
    width: 100px;
    border-radius: 100px;
    background-color: black;
    margin: auto;
    position: relative;
    top:45px;
}

在行动:http: //jsfiddle.net/NickWilde/ngcce/

于 2013-08-03T13:51:17.647 回答