Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css arrow of active LI with body image background?

Tags:

html

css

My objective is to hide the line below the triangle to have this outcome _____^_____ on my active menu. There are similar questions here at stackoverflow but those solutions doesn't fixed the issue I currently have. Pls help me play with it. Thanks! FIDDLE here.

body {
    background: #1abc9c url(//dmypbau5frl9g.cloudfront.net/assets/homepage/banner--themeforest-342995208860d6c90b98134db089ef84.jpg);
}
ul {
    width:100%;
    border-bottom:3px solid red
}
li {
    display:inline-block;padding:20px;
}
li a {
    display:block;position:relative;
}
li.active a:after {
    content:"";
    width:15px;
    height:15px;
    position:absolute;
    top:100%;
    left:0;
    right:0;
    margin:12px auto 0;
    border:solid red;
    border-width:3px 3px 0 0;  
    -moz-transform:rotate(315deg);
    -webkit-transform:rotate(315deg);
    -ms-transform:rotate(315deg);
}
  <ul>
    <li><a href="#">LINK1</a></li>
    <li><a href="#">LINK2</a></li>
    <li class="active"><a href="#">LINK3</a></li>
    <li><a href="#">LINK4</a></li>
  </ul>
like image 333
jamez88 Avatar asked Apr 05 '15 19:04

jamez88


1 Answers

This CSS code will fix it:

Updated fiddle: http://jsfiddle.net/L786rqfs/6/

You need to bring the border to the LI and chop it in a left and right side in the before and after content. For the finishing touch I bring also the border to UL after content so you keep it 100% over the page.

body {
    background: #1abc9c url(//dmypbau5frl9g.cloudfront.net/assets/homepage/banner--themeforest-342995208860d6c90b98134db089ef84.jpg);
}

ul {
    overflow: hidden; /* Clear float and hide ul:after content overflow */
    position: relative; /* Relative for ul:after content */
    width: 100%;
}

ul:after {
    content: "";
    border-bottom: 3px solid red;
    bottom: 0;
    position: absolute; /* Now it will start after the last LI */
    width: 100%;
}

li {    
    float: left;
    padding: 20px;
    position: relative;
}

li:before,
li:after {
    content: "";
    border-bottom: 3px solid red;    
    bottom: 0;
    position: absolute;
    width: 50%;
}

li:before {
    left: 0;
}

li:after {
    right: 0;
}

li.active:before,
li.active:after {
    width: calc(50% - 8px); /* Transparent part of the arrow */
}

li a {    
    display: block;
    position: relative;
}

li.active a:after {
    content: "";
    width: 15px;
    height: 15px;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin: 12px auto 0;
    border: solid red;
    border-width: 3px 3px 0;  
    -moz-transform: rotate(315deg);
    -webkit-transform: rotate(315deg);
    -ms-transform: rotate(315deg);
}
like image 151
Ben Besuijen Avatar answered Sep 22 '22 10:09

Ben Besuijen