如何使这个CSS汉堡菜单完全可点击?

时间:2014-10-01 21:28:16

标签: html css menu css-shapes

我正在开发一个纯CSS汉堡包菜单图标,到目前为止它工作得很好,除了线条之间的间隙不可点击。如何修改此代码,以便整个按钮可以单击而不仅仅是行?

<a href="#" title="Open Menu" class="menu"></a>

.menu {
    width:30px;
    height:5px;
    background-color:#000;
    position:relative;
    display:inline-block;
}
    .menu:after, .menu:before {
        content: '';
        width: 100%;
        height:5px;
        background-color:#000;
        position:absolute;
    }
    .menu:after {
        top:10px;
        left:0;
    }
    .menu:before {
        top:20px;
        left:0;
    }

这里是JSFiddle

谢谢!

1 个答案:

答案 0 :(得分:8)

就这样做

DEMO - 1 (边框顶部或底部)

&#13;
&#13;
.menu {
    width:30px;
    height:20px;
    position:relative;
    display:inline-block;
    border-top:4px solid black;
}
	.menu:after, .menu:before {
	    content: '';
	    width: 100%;
	    height:4px;
	    background-color:#000;
	    position:absolute;
	}
	.menu:after {
	    bottom:0px;
	    left:0;
	}
	.menu:before {
	    top:6px;
	    left:0;
	}
&#13;
<a href="#" title="Open Menu" class="menu"></a>
&#13;
&#13;
&#13;

DEMO -2 (box-shadow)

&#13;
&#13;
.menu {
    width:30px;
    height:20px;
    position:relative;
    display:inline-block;
    box-shadow:inset 0 4px 0 black;
}
	.menu:after, .menu:before {
	    content: '';
	    width: 100%;
	    height:4px;
	    background-color:#000;
	    position:absolute;
	}
	.menu:after {
	    bottom:0px;
	    left:0;
	}
	.menu:before {
	    top:8px;
	    left:0;
	}
&#13;
<a href="#" title="Open Menu" class="menu"></a>
&#13;
&#13;
&#13;

DEMO - 3 (仅限:混合框阴影插入之前或之后)

&#13;
&#13;
.menu {
    width:30px;
    height:20px;
    position:relative;
    display:inline-block;
    box-shadow:inset 0 4px 0 black,inset 0 -4px 0 black;
}
	.menu:after{
	    content: '';
	    width: 100%;
	    height:4px;
	    background-color:#000;
	    position:absolute;
        top:8px;
	    left:0;
	}
&#13;
<a href="#" title="Open Menu" class="menu"></a>
&#13;
&#13;
&#13;

DEMO - 4

&#13;
&#13;
.menu {
    width:30px;
    height:14px;
    position:relative;
    display:inline-block;
    border-top: 4px solid black;
    border-bottom: 4px solid black;
}
	.menu:after{
	    content: '';
	    width: 100%;
	    height:4px;
	    background-color:#000;
	    position:absolute;
        top:5px;
	    left:0;
	}
&#13;
<a href="#" title="Open Menu" class="menu"></a>
&#13;
&#13;
&#13;

DEMO - 5 (使用背景图片)

&#13;
&#13;
.menu {
width: 30px;
height: 26px;
position: relative;
display: inline-block;
background-size: 10px 10px;
background-image: -webkit-linear-gradient(rgba(0, 0, 0, 1) 50%, transparent 50%, transparent);
background-image: -moz-linear-gradient(rgba(0, 0, 0, 1) 50%, transparent 50%, transparent);
background-image: linear-gradient(rgba(0, 0, 0, 1) 50%, transparent 50%, transparent);
}
&#13;
<a href="#" title="Open Menu" class="menu"></a>
&#13;
&#13;
&#13;