Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to make pointy buttons (apple like) with CSS3?

Tags:

css

forms

I want to make a button like the iPhone back button just with CSS3.

Is it possible? How?

You can see my objective here:

iPhone back button

like image 841
Mateus Pinheiro Avatar asked Jul 22 '11 12:07

Mateus Pinheiro


People also ask

Can you create buttons in CSS?

To create text buttons first, we create simple buttons in HTML using a button tag. After creating the button we apply CSS and change its properties to make it look like a text button. To make it look like a text button we remove its default border and background.

How do I style a button in Javascript?

Use input[type="button"] as a selector, and add whatever you want to that.


1 Answers

This is one possible solution, using primarily CSS2 (with just a touch of optional CSS3 for border-radius and box-shadow). This is a limited, straightforward solution that seems to work in current versions (as of Nov 2012) of Chrome and Firefox, and likewise renders nearly identically in IE7-9. I don't have IE10 to test, but one can reasonably assume it is fine.

I wrote "limited" because these buttons must use solid background-colors in order to render identically across browsers. Also, the box-shadow does not fully extend to the "point," but used sparingly it may not be objectionable. Box-shadow is optional anyway, since it is unsupported on old IE unless augmented with something like CSS3Pie.

http://jsfiddle.net/yHprm/11/

.wiz-buttons > a {
  position: relative;
  display: block;
  font: normal 14px Arial;
  text-decoration: none;
  cursor: pointer;
}
.wiz-buttons > a > .button {
  min-width: 75px;
}
/* Next Button */

.wiz-buttons > .next {
  color: #FFF;
}
.wiz-buttons > .next > .arrow-inner {
  display: block;
  position: absolute;
  top: 1px;
  right: 3px;
  z-index: 2000;
  width: 0;
  height: 0;
  border: 14px solid transparent;
  border-left-color: #E38A13;
}
.wiz-buttons > .next > .arrow {
  display: block;
  float: right;
  width: 0;
  height: 0;
  border: 15px solid transparent;
  border-left-color: #CC790B;
}
.wiz-buttons > .next > .button {
  display: block;
  float: right;
  line-height: 20px;
  background-color: #E38A13;
  border: 2px solid #CC790B;
  border-right: 0;
  padding: 3px 3px 3px 9px;
  text-align: center;
  -webkit-border-radius: 2px 0 0 2px;
  -moz-border-radius: 2px 0 0 2px;
  border-radius: 2px 0 0 2px;
  filter: progid: DXImageTransform.Microsoft.gradient(enabled=false);
  -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
  -moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
}
.wiz-buttons > .next:hover > .arrow {
  border-left-color: #ad6608;
}
.wiz-buttons > .next:hover > .arrow-inner {
  border-left-color: #CC790B;
}
.wiz-buttons > .next:hover > .button {
  background-color: #CC790B;
  border-color: #b66c09;
}
/* Previous Button */

.wiz-buttons > .previous {
  color: #666;
}
.wiz-buttons > .previous > .arrow-inner {
  display: block;
  position: absolute;
  top: 1px;
  left: 3px;
  z-index: 2000;
  width: 0;
  height: 0;
  border: 14px solid transparent;
  border-right-color: #f4f4f4;
}
.wiz-buttons > .previous > .arrow {
  display: block;
  float: left;
  width: 0;
  height: 0;
  border: 15px solid transparent;
  border-right-color: #e8e8e8;
}
.wiz-buttons > .previous > .button {
  display: block;
  float: left;
  line-height: 20px;
  background-color: #f6f6f6;
  border: 2px solid #eaeaea;
  border-left: 0;
  padding: 3px 9px 3px 3px;
  text-align: center;
  -webkit-border-radius: 0 2px 2px 0;
  -moz-border-radius: 0 2px 2px 0;
  border-radius: 0 2px 2px 0;
  filter: progid: DXImageTransform.Microsoft.gradient(enabled=false);
  -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
  -moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
}
.wiz-buttons > .previous:hover > .arrow {
  border-right-color: #e1e1e1;
}
.wiz-buttons > .previous:hover > .arrow-inner {
  border-right-color: #eaeaea;
}
.wiz-buttons > .previous:hover > .button {
  background-color: #eaeaea;
  border-color: #e3e3e3;
}
<div class="wiz-buttons">
  <a class="previous" href="#">
    <span class="arrow"></span>
    <span class="arrow-inner"></span>
    <span class="button">Previous</span>
  </a>
  <a class="next" href="#">
    <span class="arrow"></span>
    <span class="arrow-inner"></span>
    <span class="button">Next</span>
  </a>
</div>

I hope someone finds this useful.

like image 67
Aaron Mendez Avatar answered Oct 19 '22 20:10

Aaron Mendez