Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
327 views
in Technique[技术] by (71.8m points)

html - Ribbon with a "3D" effect

I have the following code for my menu:

HTML:

<div class="container wrapper">
<nav>
    <ul class="menu">
        <li><a href="#">Home</a></li>
        <li><a href="#">page1</a></li>
        <li><a href="#">page2</a></li>
    </ul>
</nav>

And the CSS:

.wrapper{
    padding:20px;
    background:#d3d3d3;
    height:200px;

}
.menu{
    background:#7F7979;
}
.menu li{
    padding-top: 20px;
    padding-bottom: 20px;
    padding-left: 15px;
    display: inline-block;
}
.menu li a{
    color:white;
}
nav ul{
    list-style:none;
    margin:0
        padding:0;
}

What I want to achieve is at the right and left corners to look like it comes from behind the container (like a 3D effect if we can call it this way). Haven't tried anything since I don't have any idea how to achieve this.

I googled a bit but didn't find any website to inspect the code. If someone knows any, please point me out.

And plus, how can I do this by ignoring the container padding? Is it possible to make it with my menu inside this container which has a padding and still forcing the margins to go outside it?

NOTE: I'm not trying to someone do this for me, I'm trying to figure out what CSS properties should I use to achieve what I want.

To better explain what I wanted:

menu

corner

If it helps, my demo:

demo

Thank you so much for pointing me the right direction.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use borders on pseudo elements to make the 2 darker triangles on the top left and right of your menu bar.

To make the menu bar wider than it's container, you can use negative left/right margins :

DEMO

header{
    width:80%;
    margin: 0 auto;
    background:#D3D3D3;
    padding:100px 0 200px;
}
nav{
    position:relative;
    height:50px;
    background: #7E7979;
    margin: 0 -25px;
}
nav:before, nav:after{
    content:'';
    position:absolute;
    top:-10px;
    border-bottom:10px dotted #5C5C5B;
}
nav:before{
    left:0;
    border-left:25px solid transparent;
}
nav:after{
    right:0;
    border-right:25px solid transparent;
}
<header>
    <nav></nav>
</header>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...