2015-10-14 54 views
0
創建一個響應式CSS按鈕

我試圖從HTML和CSS中的photoshop模型創建響應按鈕。這裏是按鈕樣機:用箭頭

enter image description here

我與如何獲得的箭頭空白掙扎,並通過不同的屏幕尺寸呆在那裏。

我創建通過漸變的顏色分離,就像這樣:

HTML

<button> All Team Members </button> 

CSS

button { 
    /* Permalink http://colorzilla.com/gradient-editor/#990033+0,990033+50,990033+86,ffffff+86,ffffff+100 */ 
    width: 70%; 
    font-size: .6em; 
    font-size: 3.4vw; 
    padding: 2%; 
    color: #ffffff; 
    outline-color: #990033; 
    background: rgb(153,0,51); /* Old browsers */ 
    background: -moz-linear-gradient(left, rgba(153,0,51,1) 0%, rgba(153,0,51,1) 50%, rgba(153,0,51,1) 86%, rgba(255,255,255,1) 86%, rgba(255,255,255,1) 100%); /* FF3.6+ */ 
    background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(153,0,51,1)), color-stop(50%,rgba(153,0,51,1)), color-stop(86%,rgba(153,0,51,1)), color-stop(86%,rgba(255,255,255,1)), color-stop(100%,rgba(255,255,255,1))); /* Chrome,Safari4+ */ 
    background: -webkit-linear-gradient(left, rgba(153,0,51,1) 0%,rgba(153,0,51,1) 50%,rgba(153,0,51,1) 86%,rgba(255,255,255,1) 86%,rgba(255,255,255,1) 100%); /* Chrome10+,Safari5.1+ */ 
    background: -o-linear-gradient(left, rgba(153,0,51,1) 0%,rgba(153,0,51,1) 50%,rgba(153,0,51,1) 86%,rgba(255,255,255,1) 86%,rgba(255,255,255,1) 100%); /* Opera 11.10+ */ 
    background: -ms-linear-gradient(left, rgba(153,0,51,1) 0%,rgba(153,0,51,1) 50%,rgba(153,0,51,1) 86%,rgba(255,255,255,1) 86%,rgba(255,255,255,1) 100%); /* IE10+ */ 
    background: linear-gradient(to right, rgba(153,0,51,1) 0%,rgba(153,0,51,1) 50%,rgba(153,0,51,1) 86%,rgba(255,255,255,1) 86%,rgba(255,255,255,1) 100%); /* W3C */ 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#990033', endColorstr='#ffffff',GradientType=1); /* IE6-9 */ 
} 

它目前看起來是這樣的:

enter image description here

前進的最佳方法是什麼?我想知道是否應該使用模型中的按鈕截圖,或者如果我應該使用CSS來製作它。我怎樣才能使按鈕看起來像這樣,並做出反應?

回答

0

使用僞元素:before:after,使背景和箭頭。如果您需要不同形狀的箭頭,請使用Font Awesome等。

button { 
 
    font-size: 3vw; 
 
    padding: 2vw; 
 
    color: #ffffff; 
 
    background: #903; 
 
    border: 0; 
 
    position: relative; 
 
    padding-right: 8vw; 
 
} 
 
button:before { 
 
    content: ''; 
 
    width: 6vw; 
 
    position: absolute; 
 
    right: 0; 
 
    top: 0; 
 
    bottom: 0; 
 
    background: white; 
 
    border: 1px solid #903; 
 
} 
 
button:after { 
 
    content: '❯'; 
 
    position: absolute; 
 
    right: 2vw; 
 
    color: #903; 
 
}
<button>All Team Members</button>

jsfiddle

0

試試這個:

.btn {padding:10px 40px 10px 20px; 
    width:70%; 
    border-radius:3px; 
    border:2px solid inherit; 
border-color: #eeeeee; 
    background-color:rgb(153,0,51); 
    background-position:center right; 
    background-repeat:no-repeat; 
    text-align:center; 
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#990033', endColorstr='#ffffff',GradientType=1); /* IE6-9 */ 
    font-size: .6em 

    } 
    .white_txt {color:#ffffff!important;} 
    .purple_btn {border:2px solid #eeeeee;border-radius:3px;} 

<div class="purple_btn btn"> 
    <div class="white_txt">All Team Members</div> 
</div>