创建一个带箭头的响应式 CSS 按钮
Create a responsive CSS button with arrow
我正在尝试从 HTML 和 CSS 中的 photoshop 模型创建响应按钮。这是按钮模型:
我正在纠结如何让箭头变成白色 space 并在不同的屏幕尺寸下保持在那里。
我通过渐变创建分色,如下所示:
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 */
}
目前看起来像这样:
前进的最佳方式是什么?我想知道我是否应该只使用模型中按钮的屏幕截图,或者我是否应该在 CSS 中制作它。我怎样才能使按钮看起来像这样并响应?
试试这个:
.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>
使用伪元素: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>
我正在尝试从 HTML 和 CSS 中的 photoshop 模型创建响应按钮。这是按钮模型:
我正在纠结如何让箭头变成白色 space 并在不同的屏幕尺寸下保持在那里。
我通过渐变创建分色,如下所示:
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 */
}
目前看起来像这样:
前进的最佳方式是什么?我想知道我是否应该只使用模型中按钮的屏幕截图,或者我是否应该在 CSS 中制作它。我怎样才能使按钮看起来像这样并响应?
试试这个:
.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>
使用伪元素: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>