CSS3按钮有两种颜色

时间:2015-01-07 12:14:01

标签: html css css3 button

我想问一下用css创建这样的按钮的最佳方法是什么:

enter image description here

我试图用左右浮动创建这样的按钮,但是当我放大和缩小按钮的右侧时,它会下降。有没有更好的方法来实现这一目标?

fiddle link

<div style="width:270px">
    <div class="button">
        <div>
            <div>text</div>
            <div>text</div>
        </div>
        <div><div></div></div>
    </div>
</div>

.button {
    height: 80px;
    cursor: pointer;
}

.button:after {
    content: ".";
    display: block;
    clear: both;
    visibility: hidden;
    line-height: 0;
    height: 0;
}

.button > div:first-child {
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
    border: 1px solid #008f70;
    background-color: #00b48c;
    text-align: right;
    float: left;
    padding: 15px;
    width: 165px;
}

.button > div:first-child > div:first-child {
    color: #b8e3d6;
    font-size: 12pt;
}

.button > div:first-child > div:last-child {
    color: #fff;
    font-weight: bold;
    font-size: 20pt;
}

.button > div:last-child {
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
    float: right;
    margin-right: 9px;
    background-color: #008f70;
    width: 64px;
    height: 81px;
    position: relative;
}

3 个答案:

答案 0 :(得分:4)

所需要的一切:

&#13;
&#13;
button.styled{
  color:#fff;
  background:#00B48C;     /* CHANGE ONLY THIS ONE AND SEE IT HAPPEN ;) */
  padding:10px 45px 10px 15px;
  border-radius:4px;
  /* Do not edit below */
  border:0;
  position:relative;
  overflow:hidden;
  box-shadow:inset 0 0 0 1px rgba(0,0,0,0.2);
}
button.styled:after{
  background: rgba(0,0,0,0.2);
  padding:11px;
  content:'\25be'; /* \25bc \25be */
  /* Do not edit below */
  position:absolute;
  right:0;
  top:0;
}
&#13;
<button class="styled">Hello World</button>
&#13;
&#13;
&#13;

有关更多UTF-8字符,请参阅:https://stackoverflow.com/a/25986009/383904

答案 1 :(得分:1)

使用div删除重复的text,并使用padding将顶部和底部div添加到其他text

您可以使用Font Awesome在下拉列表中显示插入符号。

&#13;
&#13;
.button {
  height: 80px;
  cursor: pointer;
}

.button:after {
  content: ".";
  display: block;
  clear: both;
  visibility: hidden;
  line-height: 0;
  height: 0;
}

.button > div:first-child {
  border-top-left-radius: 4px;
  border-bottom-left-radius: 4px;
  border: 1px solid #008f70;
  background-color: #00b48c;
  text-align: right;
  float: left;
  padding: 22px 15px 26px 15px; /* add top and bottom border */
  width: 165px;
}

.button > div:first-child > div:first-child {
  color: #b8e3d6;
  font-size: 12pt;
}

.button > div:first-child > div:last-child {
  color: #fff;
  font-weight: bold;
  font-size: 20pt;
}

.button > div:last-child {
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
  float: right;
  margin-right: 9px;
  background-color: #008f70;
  width: 64px;
  height: 81px;
  position: relative;
}

i{
  margin-left: 45%;
  margin-top: 45%;
  color: white;
}
&#13;
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">

<div style="width:270px">
  <div class="button">
    <div>
      <div>text</div>
    </div>
    <div><div><i class="fa fa-caret-down"></i></div></div> <!-- add the caret -->
  </div>
</div>
&#13;
&#13;
&#13;

Updated jsFiddle

Source

答案 2 :(得分:1)

您只能使用一个元素pseudo元素:before:after

button {
  border-radius: 4px 0px 0px 4px;
  border-width: 1px;
  border-color: #008f70;
  border-style: solid;
  background-color: #00b48c;
  text-align: right;
  padding: 15px;
  width: 165px;
  position: relative;
  color: white;
}
button:before {
  content: '\25BE';
  position: absolute;
  right: -32px;
  z-index: 1;
  font-size: 16px;
  top: 50%;
  color: white;
  transform: translatey(-50%);
}
button:after {
  content: '';
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
  margin-right: 9px;
  background-color: #008f70;
  width: 54px;
  position: absolute;
  top: -1px;
  left: 100%;
  bottom: -1px
}
button:focus {
  outline: 0;
  box-shadow: none;
}
<button>test</button>