2015-10-14 94 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>