2016-12-06 84 views
0

我花了很多時間試圖想出一個解決方案,在CSS中創建一個繼承漸變背景的三角形,最後,我非常接近,但我不確定如何刪除在背景中的白色背景線性漸變樣式。用線性漸變強制在CSS三角形上的透明背景

我做了一個jsfiddle很容易地看到什麼,我想實現...

enter image description here

相關樣式這種線性漸變是在小提琴,也是風格部分的最末端下面: -

.inner-nav li.active a:after, .inner-nav li.current-menu-item a:after { 
    border-color: transparent transparent transparent rgb(91,181,200); 
    background: rgb(91,181,200); 
    background:  url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJod…EiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+); 
    background: -moz-linear-gradient(top, rgba(91,181,200,1) 0%, rgba(62,165,187,1) 100%); 
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(91,181,200,1)), color-stop(100%,rgba(62,165,187,1))); 
    background: -webkit-linear-gradient(top, rgba(91,181,200,1) 0%,rgba(62,165,187,1) 100%); 
    background: -o-linear-gradient(top, rgba(91,181,200,1) 0%,rgba(62,165,187,1) 100%); 
    background: -ms-linear-gradient(top, rgba(91,181,200,1) 0%,rgba(62,165,187,1) 100%); 
    background: linear-gradient(to bottom, rgba(91,181,200,1) 0%,rgba(62,165,187,1) 100%); 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#5bb5c8', endColorstr='#3ea5bb',GradientType=0); 
    background: linear-gradient(60deg, transparent 63%, rgb(255, 255, 255) 63%), linear-gradient(-60deg, transparent 63%, rgb(255, 255, 255) 63%), linear-gradient(to right, rgba(91,181,200,1) 0%, rgba(62,165,187,1) 100%); 
    transform: rotate(90deg); 
} 

是否有可能修改現有的風格來完成這個或我需要重新開始不同的方法?

+1

使用SVG ...簡單得多。 –

回答

1

達到這種效果的一個簡單方法是取一個正方形並旋轉它。

我對css的唯一更改是在「.inner-nav li.active a:after,.inner-nav li.current-menu-item a:after」選擇器之後。

.inner-nav { 
 
    float: left; 
 
    display: block; 
 
    width: 300px; 
 
    position: relative; 
 
    z-index: 50; 
 
    z-index: 1; 
 
} 
 

 
.inner-nav li { 
 
    padding: 0 !important; 
 
    float: left; 
 
    display: block; 
 
    height: 42px; 
 
    width: 100%; 
 
    margin: 0 0 1px; 
 
    font-size: 14px; 
 
    font-weight: 600; 
 
    line-height: 42px; 
 
    text-shadow: 0 1px 1px rgba(0,0,0,0.15); 
 
    background: rgb(193,182,174); 
 
    background: -moz-linear-gradient(top, rgba(193,182,174,1) 0%, rgba(186,172,163,1) 100%); 
 
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(193,182,174,1)), color-stop(100%,rgba(186,172,163,1))); 
 
    background: -webkit-linear-gradient(top, rgba(193,182,174,1) 0%,rgba(186,172,163,1) 100%); 
 
    background: -o-linear-gradient(top, rgba(193,182,174,1) 0%,rgba(186,172,163,1) 100%); 
 
    background: -ms-linear-gradient(top, rgba(193,182,174,1) 0%,rgba(186,172,163,1) 100%); 
 
    background: linear-gradient(to bottom, rgba(193,182,174,1) 0%,rgba(186,172,163,1) 100%); 
 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#c1b6ae', endColorstr='#baaca3',GradientType=0); 
 
    -webkit-transition: all 0.3s linear; 
 
    -moz-transition: all 0.3s linear; 
 
    -o-transition: all 0.3s linear; 
 
    -ms-transition: all 0.3s linear; 
 
    transition: all 0.3s linear; 
 
} 
 

 
.inner-nav li { 
 
    background: rgb(240,192,96); 
 
    background: -moz-linear-gradient(top, rgba(240,192,96,1) 0%, rgba(240,216,144,1) 100%); 
 
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(240,192,96,1,1)), color-stop(100%,rgba(240,216,144,1))); 
 
    background: -webkit-linear-gradient(top, rgba(240,192,96,1,1) 0%,rgba(240,216,144,1) 100%); 
 
    background: -o-linear-gradient(top, rgba(240,192,96,1,1) 0%,rgba(240,216,144,1) 100%); 
 
    background: -ms-linear-gradient(top, rgba(240,192,96,1,1) 0%,rgba(240,216,144,1) 100%); 
 
    background: linear-gradient(to bottom, rgba(240,192,96,1,1) 0%,rgba(240,216,144,1) 100%); 
 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#F0C060', endColorstr='#F0D890',GradientType=0); 
 
    -webkit-transition: all 0.3s linear; 
 
    -moz-transition: all 0.3s linear; 
 
    -o-transition: all 0.3s linear; 
 
    -ms-transition: all 0.3s linear; 
 
    transition: all 0.3s linear; 
 
} 
 

 
.inner-nav li i { 
 
    position: absolute; 
 
    left: 0; 
 
    font-size: 22px; 
 
    padding: 10px 0 0 15px; 
 
    color: #ffffff; 
 
    height: 42px; 
 
} 
 

 
.fa { 
 
    display: inline-block; 
 
    font: normal normal normal 14px/1 FontAwesome; 
 
    font-size: inherit; 
 
    text-rendering: auto; 
 
    -webkit-font-smoothing: antialiased; 
 
    -moz-osx-font-smoothing: grayscale; 
 
} 
 

 
.inner-nav li a { 
 
    float: left; 
 
    display: block; 
 
    color: #fff; 
 
    padding: 0 0 0 41px; 
 
    width: 100%; 
 
    height: 100%; 
 
    position: relative; 
 
    font-weight: 600; 
 
} 
 

 
.inner-nav li a { 
 
    padding-left: 45px !important; 
 
} 
 

 
.inner-nav .description a:before { 
 
    content: "\e88f"; 
 
} 
 
.inner-nav li a:before { 
 
    font-family: 'Material Icons'; 
 
    font-size: 24px; 
 
    font-weight: 400; 
 
    position: absolute; 
 
    top: 0; 
 
    left: 10px; 
 
} 
 

 
.inner-nav li.active, .inner-nav li.active:hover, .inner-nav li.current-menu-item, .inner-nav li.current-menu-item:hover { 
 
    background: rgb(91,181,200); 
 
    background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJod…EiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+); 
 
    background: -moz-linear-gradient(top, rgba(91,181,200,1) 0%, rgba(62,165,187,1) 100%); 
 
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(91,181,200,1)), color-stop(100%,rgba(62,165,187,1))); 
 
    background: -webkit-linear-gradient(top, rgba(91,181,200,1) 0%,rgba(62,165,187,1) 100%); 
 
    background: -o-linear-gradient(top, rgba(91,181,200,1) 0%,rgba(62,165,187,1) 100%); 
 
    background: -ms-linear-gradient(top, rgba(91,181,200,1) 0%,rgba(62,165,187,1) 100%); 
 
    background: linear-gradient(to bottom, rgba(91,181,200,1) 0%,rgba(62,165,187,1) 100%); 
 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#5bb5c8', endColorstr='#3ea5bb',GradientType=0); 
 
    width: 110%; 
 
} 
 

 
.inner-nav li.active a:after, .inner-nav li.current-menu-item a:after { 
 
    content: ""; 
 
    position: absolute; 
 
    top: 0; 
 
    right: 3px; 
 
    width: 42px; 
 
    height: 42px; 
 
    /* border-style: solid; */ 
 
    /* border-width: 21px 0 21px 21px; */ 
 
} 
 

 
.inner-nav li.active a:after, .inner-nav li.current-menu-item a:after { 
 
    position: absolute; 
 
    top: 6px; 
 
    right: 30px; 
 
    width: 30px; 
 
    height: 30px; 
 
    -webkit-transform: rotate(135deg); 
 
    -ms-transform: rotate(135deg); 
 
    transform: rotate(135deg); 
 
    background: linear-gradient(45deg, rgba(91,181,200,1) 0%,rgba(62,165,187,1) 100%); 
 
}
<nav class="inner-nav"> 
 
      <ul> 
 
       <li class="description active" id=""><i class="fa fa-info-circle"></i><a href="#description" title="Description">Description</a></li><li class="facilities" id=""><i class="fa fa-tasks"></i><a href="#facilities" title="Facilities">Facilities</a></li><li class="availability" id=""><i class="fa fa-clock-o"></i><a href="#availability" title="Availability">Availability</a></li>    <li class="pricing"> 
 
        <i class="fa fa-gbp"></i><a href="#pricing" title="Pricing">Pricing</a> 
 
       </li> 
 
      </ul> 
 
     </nav>

+0

我試着旋轉一個正方形,但我無法繞過線性漸變旋轉,同時保持與李的其餘部分相同的方向的漸變,但是這完全可以實現 - 謝謝。 – zigojacko