Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skewed background and hover-effect with hidden overflow

I am working on a CSS3-navigation, but I have some troubles with the overflow of the hover-effect. I tried to add overflow:hidden - without success.

This is what it looks like: enter image description here

And this is what it should look like: enter image description here

HTML:

<header>
<div id="header-top">
    <nav id="main-navigation" role="navigation">
        <ul class="menu">
          <li><a href="#">Home</a></li>
          <li><a href="#">About</a></li>
          <li><a href="#">Events</a></li>
          <li><a href="#">Artists</a></li>
        </ul>
    </nav>
</div>

CSS:

#header-top {
    height: 70px;
    left: 0;
    position: fixed;
    right: 0;
    top: 0;
    z-index: 100;
}
#header-top:after {
    background: rgba(0,0,0,0.35);
    content: "";
    height: 120px;
    position: absolute;
    top: -50px;
    left: 0px;
    transform: skewY(-4deg);
    width: 100%;
    z-index: -1;
}
#main-navigation ul {
    display: inline;
    float: right;
    padding: 0;
    margin: 0;
}
#main-navigation ul li {
    display: inline;
    line-height: 30px;
}
#main-navigation ul li a {
    display: inline-block;
    font-size: 14px;
    font-weight: 400;
    color: #fff;
    padding: 20px;
}
#main-navigation ul li a:hover {
    padding: 20px;
    background-color: red;
}

Here is a fiddle: http://jsfiddle.net/v9dfjq4L/1/

Thanks in advance!

like image 783
Chris Avatar asked Aug 12 '14 11:08

Chris


3 Answers

put the background color on the header and use the :after element to clip the bottom of the #header-top. http://jsfiddle.net/ovtphrqL/ enter image description here

#header-top:after {
    background: rgba(255, 255, 255, 1);
    content: "";
    height: 120px;
    position: absolute;
    top: 74px;
    left: 0px;
    transform: skewY(-3deg);
    width: 100%;
    z-index: 5;
}
like image 142
roo2 Avatar answered Nov 20 '22 21:11

roo2


I would suggest you to play with clip-path and mask. Here are some useful links:

Link 1

Link 2

like image 30
Mihey Egoroff Avatar answered Nov 20 '22 20:11

Mihey Egoroff


Problem explanation:

overflow: hidden will indeed not work, because you applied the skewY to the :after element, which doesn't influence the rest of the content of #header-top.

However, I found thissolution to your problem:

Remove the :after thing. Apply the skewY(-4deg) and background-color to the <nav>, and invert this transform for the inner <ul> using skewY(4deg). Now, overflow: hidden will work when applied to the <nav>.

A few new problems turn up: a little white triangle in the left top corner (fix: padding-top and negative margin-top for the <nav>), and the red hover isn't high enough for some items (fix: use a bigger padding-bottom).

Don't forget to use a crossbrowser fallback for transform (-webkit-, -moz-, -o-).

Applied solution:

This solution is applied in this JSFiddle: http://jsfiddle.net/v9dfjq4L/9/

like image 1
jessedvrs Avatar answered Nov 20 '22 22:11

jessedvrs