Posts Mentioning RSS Toggle Comment Threads | Keyboard Shortcuts

  • Jay Kwong 1:55 am on July 8, 2010 Permalink
    Tags: , , css3   

    Fancy Inset CSS Image Borders | Evan Byrne’ Writings 

    Before

    After



    The HTML Markup

    In a perfect world we would only use a single img tag with a class attribute. This is not a perfect world. Because the img tag does not support the CSS pseudo-element :after, we have to wrap our image in a span.

    <span class="fancy">< img src="dingo.jpg" /></span>

    The CSS

    The first step is to apply a simple reset to our span and img tags.

    span,img{padding:0;margin:0;border:0;}
    

    Next, we style the wrapper element.

    .fancy{
    position:relative;
    display:inline-block;
    font-size:0;
    line-height:0;
    }
    
    .fancy:after{
    position:absolute;
    top:1px;
    left:1px;
    bottom:1px;
    right:1px;
    border:1px solid rgba(255,255,255,0.5);
    outline:1px solid rgba(0,0,0,0.2);
    content:&amp;quot; &amp;quot;;
    }
    
     
  • Jay Kwong 7:06 am on June 28, 2010 Permalink | Reply
    Tags: , , ,   

    CSS3 Gradient Buttons 

    button states

    What Is So Cool About These Buttons?

    • Pure CSS: no image or Javascript is used.
    • The gradient is cross-browser supported (IE, Firefox 3.6, Chrome, and Safari).
    • Flexible and scalable: button size and rounded corners can be adjusted by changing the font size and padding values.
    • It has three button states: normal, hover, and active.
    • It can be applied to any HTML element: a, input, button, span, div, p, h3, etc.
    • Fallback: if CSS3 is not supported, it will display a regular button (no gradient and shadow).

    Preview

    The image below shows how the button will display in different browsers.

    preview

    Button States

    • normal state = gradient with border and shadow styles.
    • hover = darker gradient
    • active = gradient is reversed, 1px down, and darker font color as well.

    button states

    General Styles For The Button

    The following code is the general styles for the .button class. I use em value in the padding and border-radius property to make it scalable base on the font-size. To adjust the rounded corners and button size, simply change the border-radius, font-size and padding values. For example: I can make a smaller button by decreasing the font-size and padding values (see demo).

    For more details on border-radius, text-shadow, and box-shadow, read my article The Basics of CSS3.

    .button {
    	display: inline-block;
    	outline: none;
    	cursor: pointer;
    	text-align: center;
    	text-decoration: none;
    	font: 14px/100% Arial, Helvetica, sans-serif;
    	padding: .5em 2em .55em;
    	text-shadow: 0 1px 1px rgba(0,0,0,.3);
    	-webkit-border-radius: .5em;
    	-moz-border-radius: .5em;
    	border-radius: .5em;
    	-webkit-box-shadow: 0 1px 2px rgba(0,0,0,.2);
    	-moz-box-shadow: 0 1px 2px rgba(0,0,0,.2);
    	box-shadow: 0 1px 2px rgba(0,0,0,.2);
    }
    .button:hover {
    	text-decoration: none;
    }
    .button:active {
    	position: relative;
    	top: 1px;
    }
    

    button general styles

    Color Gradient Styles

    The code below is the CSS styling for the orange button. The first background line is a fallback for the non-CSS3 browsers, the second line is for Webkit browsers, the third line is for Firefox, and the last line is a gradient filter that is only read by Internet Explorer.

    For more details on CSS gradient, read my article Cross-Browser CSS Gradient.

    .orange {
    	color: #fef4e9;
    	border: solid 1px #da7c0c;
    	background: #f78d1d;
    	background: -webkit-gradient(linear, left top, left bottom, from(#faa51a), to(#f47a20));
    	background: -moz-linear-gradient(top,  #faa51a,  #f47a20);
    	filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#faa51a', endColorstr='#f47a20');
    }
    .orange:hover {
    	background: #f47c20;
    	background: -webkit-gradient(linear, left top, left bottom, from(#f88e11), to(#f06015));
    	background: -moz-linear-gradient(top,  #f88e11,  #f06015);
    	filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#f88e11', endColorstr='#f06015');
    }
    .orange:active {
    	color: #fcd3a5;
    	background: -webkit-gradient(linear, left top, left bottom, from(#f47a20), to(#faa51a));
    	background: -moz-linear-gradient(top,  #f47a20,  #faa51a);
    	filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#f47a20', endColorstr='#faa51a');
    }
    

    button general styles

    How To Use My Buttons?

    Lets say you like the blue button and want to use it on your page:

    • First, copy the .button and .blue CSS (view demo source code).
    • Then, add to the HTML element where you want the button to be (eg. <a href="#">Button</a>). The CSS classes can be applied to any element such as link, p, span, div, input, button, etc.

    applying

     
  • Jay Kwong 6:32 am on January 22, 2010 Permalink | Reply
    Tags: -moz-border-image, , ,   

    border-image 

    div.border {
    border: 5px solid #feb515;
    -moz-border-radius: 3px;
    -webkit-border-radius: 3px;
    -moz-border-image: url(border-image.png) 5 5 5 5 stretch;
    -webkit-border-image: url(border-image.png) 5 5 5 5 stretch;
    }
    

    via ZURB – Behind the Scenes: Building the New Visual Annotations.

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
esc
cancel