我正在寻找创建这些按钮的选项:
目前,我已经能够通过创建一个圆形面具来实现所显示的效果,该面具位于徽标和背景下面,但在按钮上方。但是,这会在尝试将导航固定到顶部时引起问题。
是否可以在没有遮罩的情况下创建这样的按钮,可能使用border-radius?
这是我到目前为止所做的:
/* Navigation */
#logo {
background-color: #f0f0f0;
position: relative;
height: 150px;
width: 150px;
margin: -172px auto;
border: 6px solid #ffffff;
border-radius: 200px;
box-shadow: 2px 2px 5px 2px rgba(0, 0, 0, .04);
z-index: 3;
}
#logo:active {
top: 2px;
}
#logo-mark {
margin: 0 auto;
max-width: 96px;
display: block;
-webkit-transition: .25s;
transition: .25s;
padding: 15px 0 0 0px;
opacity: 0.5;
-webkit-backface-visibility: hidden;
}
#logo-mark:hover {
opacity: 0.8;
}
#nav-mask {
background-color: #ececec;
position: relative;
height: 190px;
width: 190px;
margin: 0 auto;
border-radius: 200px;
z-index: 0;
}
#nav-wrapper {
background-color: #ececec;
width: 100%;
position: fixed;
}
#nav {
margin: 0 auto;
max-width: 400px;
height: 90px;
}
.btn {
background-color: #494f4f;
height: 50px;
width: 130px;
margin: 20px 20px 0 20px;
border-radius: 4px;
-webkit-transition: .25s;
transition: .25s;
opacity: 0.8;
z-index: 0;
}
.btn:hover {
background-color: #3c4141;
opacity: 1;
}
.btn:active {
background-color: #3c4141;
}
.btn-left {
text-align: left;
float: left;
}
.btn-right {
text-align: right;
float: right;
}
.btn-rightmost {
text-align: right;
}
.text-nav {
color: #fff;
font-style: normal;
font-weight: 600;
font-size: 18px;
margin: 10px 8px 0 8px;
}

<div id="nav-wrapper">
<div id="nav">
<a href="about.html" class="btn btn-left">
<h3 class="text-nav">About</h3>
</a>
<a href="#work" class="btn btn-right">
<h3 class="text-nav">Work</h3>
</a>
</div>
</div>
<div id="nav-mask"></div>
<a href="website">
<div id="logo">
<img id="logo-mark" src="http://www.placehold.it/96">
</div>
</a>
&#13;
答案 0 :(得分:2)
以下是我使用:before
and :after
pseudo elements对您的设计的看法以及所需的最低HTML。它使用了掩蔽概念,但它不会破坏。
使用导航的:after
伪元素创建两个按钮上的曲线。在导航栏上使用overflow: hidden
切断圆圈。它的位置为position: absolute
,不会偏离其位置。
导航被赋予position: relative
,以便圆圈将自己定位与其相关。
看起来像这样:
使用填充将链接推开。没有伪元素掩码,它们看起来像这样:
图像被赋予position: absolute
并且位于left: 50%
,宽度为负边距(包括边框),以使其处于死点。
标题为position: relative
,以便徽标与其相关。
链接使用display: inline-block
和vertical-align: middle
进行居中。这要归功于:before
伪元素垂直居中技巧。这会将内联元素排成一行,如下所示:
header nav:before {
content: '';
height: 100%;
display: inline-block;
vertical-align: middle;
}
文字使用line-height: 50px
与链接height: 50px
匹配的链接居中。
通过在内联元素之间不留空格来防止内联间隙,如下所示:
<nav><a href="#">About</a><a href="#">Work</a></nav>
Here is a write-up on preventing this gap over on CSS Tricks
* {
font-family: arial;
margin: 0;
padding: 0;
box-sizing: border-box;
}
header {
background: #EEE;
height: 80px;
display: block;
padding: 0 25px;
position: relative;
width: 377px;
}
header nav {
height: 100%;
position: relative;
overflow: hidden;
}
header nav:before {
content: '';
height: 100%;
display: inline-block;
vertical-align: middle;
}
header nav:after {
content: '';
position: absolute;
top: 0;
left: 50%;
width: 170px;
height: 170px;
margin-left: -85px;
border-radius: 50%;
background: #EEE;
}
header nav a {
height: 50px;
display: inline-block;
background: #666;
color: #FFF;
text-decoration: none;
font-weight: bold;
line-height: 50px;
padding: 0 10px 0;
vertical-align: middle;
}
header nav a:first-child {
padding: 0 100px 0 20px;
border-radius: 3px 0 0 3px;
}
header nav a:last-child {
padding: 0 20px 0 100px;
border-radius: 0 3px 3px 0;
}
header img {
position: absolute;
top: 15px;
left: 50%;
margin-left: -70px;
border-radius: 50%;
border: solid 5px #FFF;
}
<header>
<nav><a href="#">About</a><a href="#">Work</a></nav>
<img src="http://www.placehold.it/130" />
</header>
而不是宽度,由于display: block
(默认值),标题可以占据宽度的100%
所有内容都位于标题内的text-align: center
* {
font-family: arial;
margin: 0;
padding: 0;
box-sizing: border-box;
}
header {
background: #EEE;
height: 80px;
display: block;
padding: 0 25px;
position: relative;
text-align: center;
}
header nav {
height: 100%;
position: relative;
overflow: hidden;
}
header nav:before {
content: '';
height: 100%;
display: inline-block;
vertical-align: middle;
}
header nav:after {
content: '';
position: absolute;
top: 0;
left: 50%;
width: 170px;
height: 170px;
margin-left: -85px;
border-radius: 50%;
background: #EEE;
}
header nav a {
height: 50px;
display: inline-block;
background: #666;
color: #FFF;
text-decoration: none;
font-weight: bold;
line-height: 50px;
padding: 0 10px 0;
vertical-align: middle;
}
header nav a:first-child {
padding: 0 100px 0 20px;
border-radius: 3px 0 0 3px;
}
header nav a:last-child {
padding: 0 20px 0 100px;
border-radius: 0 3px 3px 0;
}
header img {
position: absolute;
top: 15px;
left: 50%;
margin-left: -70px;
border-radius: 50%;
border: solid 5px #FFF;
}
<header>
<nav><a href="#">About</a><a href="#">Work</a></nav>
<img src="http://www.placehold.it/130" />
</header>
答案 1 :(得分:0)
*{box-sizing: border-box; padding: 0; margin: 0}
figure{
width: 480px;
height:320px;
margin: 20px auto;
position: relative;
background: red
}
img{
z-index:2;
position: absolute;
top: 40px;
margin-left: -75px;
left: 50%;
width: 150px;
height: 150px;
border-radius: 50%;
background: #E4E4E4;
box-shadow: inset 0 0 14px 0 #333,0 0 0 4px white, 0 0 18px #333;
}
figcaption{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100px;
background: #E4E4E4;
z-index: 1;
box-shadow: inset 0 -3px 6px rgba(51, 51, 51, 0.34);
}
figcaption div{
line-height: 65px;
color: white;
position: relative;
overflow: hidden;
z-index: 2;
width: 178px;
height: 64px;
margin-top: 20px;
}
figcaption div:nth-of-type(1),figcaption div:nth-of-type(2){
border-radius: 4px;
}
figcaption div:nth-of-type(1){
text-indent: 36px;
margin-left: 20px;
float: left
}
figcaption div:nth-of-type(2){
text-indent: 80px;
margin-right: 20px;
float: right
}
figcaption div:nth-of-type(1):before,figcaption div:nth-of-type(2):before{
z-index: -2;
content: '';
position: absolute;
width: 116px;
height: 164px;
border-radius: 50%;
box-shadow: 0 0 0 400px #444
}
figcaption div:nth-of-type(1):before{
right: -61px;
bottom: -100px
}
figcaption div:nth-of-type(2):before{
left: -61px;
bottom: -100px
}
figcaption a{
font-size: 20px;
font-weight: 900;
z-index: 999999999999;
}
<figure>
<img src="" />
<figcaption>
<div><a>About</a></div>
<div><a>Work</a></div>
<figcaption>
</figure>
答案 2 :(得分:0)
我会这样做:http://jsfiddle.net/56axt9z0/1/
您只需要重叠div
个border-radius
等于width
/ height
一半的div
来获得循环{{1}}