Showing posts with label CSS_CSS3. Show all posts
Showing posts with label CSS_CSS3. Show all posts

Sunday, January 11, 2015

CSS Buttons With Icons But No Images

Since reading the article Just some other awesome CSS3 buttons I become interested about how you can use this effect to get icons on buttons without using any images.
As a web developer I don't really get on with images and if I can avoid using them I will, so when I saw this trick about displaying icons in a button without using any images I wanted to explorer what other icons you can use just by using CSS.
I discovered that there are loads and loads of icons that can be used in your CSS by using Hexadecimal entities.
There are lots of places I found to get the codes for these icons here is a list of places I used to get the most useful icons for this example.

From these lists I was able to find all sorts of different codes which could be useful on your websites.
Now we have got the codes for the icons we want I am going to show you how to put them into a button just by using CSS and the :before selector to add content to your class.

Creating The Button

First we need to create the button in this example we are just using a simple CSS3 rounded corner rectangle as the button.
Copy the CSS below to use as your button.
.buttons
{
  display: inline-block;
  background: #eeeeee; /* Old browsers */
  background: -moz-linear-gradient(top, #eeeeee 0%, #eeeeee 100%); /* FF3.6+ */
  background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#eeeeee), color-stop(100%,#eeeeee)); /* Chrome,Safari4+ */
  background: -webkit-linear-gradient(top, #eeeeee 0%,#eeeeee 100%); /* Chrome10+,Safari5.1+ */
  background: -o-linear-gradient(top, #eeeeee 0%,#eeeeee 100%); /* Opera11.10+ */
  background: -ms-linear-gradient(top, #eeeeee 0%,#eeeeee 100%); /* IE10+ */
  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#eeeeee', endColorstr='#eeeeee',GradientType=0 ); /* IE6-9 */
  background: linear-gradient(top, #eeeeee 0%,#eeeeee 100%); /* W3C */
  border: 1px solid #a1a1a1;
  padding: 0 2em;
  margin: 0.5em;
  font: bold 1em/2em Arial, Helvetica;
  text-decoration: none;
  color: #333;
  border-radius: .2em;
}

Add The :before Selector

Now we have created the button we need to add the before selector so we can use this to add content to your button.
All we need to do on this is add a padding and margin to position the before selector in the correct location.
Copy the below CSS to use for the before:selector.
.buttons:before
{
  float: left;
  width: 1em;
  text-align: center;
  font-size: 1.7em;
  margin: 0 0.5em 0 -1em;
  padding: 0 .2em;
  pointer-events: none;
}
Now in order to put an icon in using the CSS we need to add the CSS property of content: "content".
Now we have got content in the before selector we can create new CSS classes for the different content we want to use.
Below are the different icons which I've found and you can use on your pure CSS icon buttons.

Form Buttons

Form Buttons
Here are the button you could use on forms.
/*Forms*/
.add:before    { content: "\271A"; }
.edit:before   { content: "\270E"; }
.delete:before { content: "\2718";}
.save:before   { content: "\2714";}
.email:before  { content: "\2709";}
.cross:before  { content: "\2716"; }

Currency Buttons

Currency
If you would like to display some currency in the buttons.
/*Currency*/
.dollar:before { content:"\0024"; }
.euro:before   { content:"\20AC"; }
.pound:before  { content: "\00A3"; }
.cent:before   { content: "\20B5"; }

Temperature Buttons

Temperature
Display temperature symbols for celsius and fahrenheit.
/*Temp*/
.celsius:before    { content: "\2103"; }
.fahrenheit:before { content: "\2109"; }

Maths Symbols Buttons

Maths
There are lots of different maths symbols here are some which I think will be useful.
/*Math & Factions*/
.pi:before            { content: "\213C"; }
.one_thrid:before     { content: "\2153"; }
.two_thrid:before     { content: "\2154"; }
.one_fifth:before     { content: "\2155"; }
.two_fifth:before     { content: "\2156"; }
.three_fifth:before   { content: "\2157"; }
.four_fifth:before    { content: "\2158"; }
.one_sixth:before     { content: "\2159"; }
.five_sixth:before    { content: "\215A"; }
.one_eighth:before    { content: "\215B"; }
.three_eighth:before  { content: "\215C"; }
.five_eighth:before   { content: "\215D"; }
.seven_eighth:before  { content: "\215E"; }
.quarter:before       { content: "\00BC"; }
.half:before          { content: "\00BD"; }
.three_quarter:before { content: "\00BE"; }

Arrows Buttons

Arrows
You can display different arrow types.
/*Arrows*/
.next:before             { content: "\279C"; }
.left_arrow:before       { content: "\2190"; }
.up_arrow:before         { content: "\2191"; }
.right_arrow:before      { content: "\2192"; }
.down_arrow:before       { content: "\2193"; }
.up_left_arrow:before    { content: "\2196"; }
.up_right_arrow:before   { content: "\2197"; }
.down_left_arrow:before  { content: "\2199"; }
.down_right_arrow:before { content: "\2198"; }

Misc Buttons

Misc
There are loads more icons to use here are some of the most useful.

/*Symbols*/
.like:before               { content: "\2764"; }
.star:before               { content: "\2605"; }
.spark:before              { content: "\2737"; }
.play:before               { content: "\25B6"; }
.watch:before              { content: "\231A"; }
.blacksun:before           { content: "\2600"; }
.cloud:before              { content: "\2601"; }
.umbrella:before           { content: "\2602"; }
.snowman:before            { content: "\2603"; }
.blackstar:before          { content: "\2605"; }
.whitestar:before          { content: "\2606"; }
.blackphone:before         { content: "\260E"; }
.whitephone:before         { content: "\260F"; }
.saltire:before            { content: "\2613"; }
.hot_drink:before          { content: "\2615"; }
.skull:before              { content: "\2620"; }
.radioactive:before        { content: "\2622"; }
.biohazard:before          { content: "\2623"; }
.peace:before              { content: "\262E"; }
.yingyang:before           { content: "\262F"; }
.frowning_face:before      { content: "\2639"; }
.smiling_face:before       { content: "\263A"; }
.first_quarter_moon:before { content: "\263D"; }
.last_quarter_moon:before  { content: "\263E"; }
.wheelchair:before         { content: "\267F"; }
.recycle:before            { content: "\267D"; }
.recycle2:before           { content: "\267C"; }
.music_note:before         { content: "\266C"; }
.warning:before            { content: "\26A0"; }
.male_and_female:before    { content: "\26A4"; }
.scissors:before           { content: "\2701"; }
.airplane:before           { content: "\2708"; }
.snow:before               { content: "\2042"; }

Wednesday, January 16, 2013

CSS3 Opacity Declarations

/* opacity */
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; /* IE 8 */
    filter: alpha(opacity=0); /* IE 5-7 */
    -khtml-opacity: 0; /* Safari 1.x */
    -moz-opacity: 0; /* Netscape */
    opacity: 0; /* Good browsers */

Thursday, October 11, 2012

How to create a number list 1, 2, 3, and Sub number list 1.1, 1.2, 1.3 … HTML list?

CSS Code:
ul.numeric-decimals { counter-reset:section; list-style-type:none; }
ul.numeric-decimals li { list-style-type:none; }
ul.numeric-decimals li ul { counter-reset:subsection; }
ul.numeric-decimals li:before{
    counter-increment:section;
    content:counter(section) ". ";/*content:"Section " counter(section) ". ";*/
}
ul.numeric-decimals li ul li:before {
    counter-increment:subsection;
    content:counter(section) "." counter(subsection) " ";
}


Html Code:
<ul class="numeric-decimals">
  <li>Cats
    <ul>
      <li>Birds</li>
      <li>Rats</li>
    </ul>
  </li>
  <li>Dogs
    <ul>
      <li>Birds</li>
      <li>Rats</li>
    </ul>
  </li>
  <li>Rabbits</li>
  <li>Ants
    <ul>
      <li>Lions</li>
      <li>Rats</li>
    </ul>
  </li>
  <li>Ducks</li>
</ul>

Tuesday, October 2, 2012

3 ways of inserting CSS media queries

CSS media queries can be added to CSS in all of the ways you're able to define it:

External stylesheet:
<link rel="stylesheet" type="text/css" href="smallscreen.css" media="only screen and (max-width: 480px)" />

Imported stylesheet within the <style> element:
@import "smallscreen.css" only screen and (max-width: 480px);

Within the <style> element as a media rule:
 <style type="text/css">
  @media only screen and (max-width: 480px){
    /* rules defined inside here are only applied to browsers that support CSS media queries and the browser window is 480px or smaller */
  }
</style>

Source from: http://www.javascriptkit.com/dhtmltutors/cssmediaqueries.shtml

Wednesday, September 26, 2012

CSS media queries and IE fix

Take a peek at adapt.js is a lightweight JavaScript file that determines which CSS file to load before the browser renders a page.
Make sure you try respond.js - a fast & lightweight polyfill for min/max-width CSS3 Media Queries (for IE 6-8, and more)

If you want to be able to correctly display a fluid design on multiple resolutions (including mobile) then you will probably use CSS Media Queries. CSS Media Queries are not complicated to use and were introduced by CSS3 specifications as an extension of CSS 2.1 media types.

Note that HTML4 supports media types like handheld, but this is poorly supported, old mobiles don't detect it, the modern devices completely ignore it.

CSS Media Queries work fine on modern browsers (IE9, FF, Chrome, Safari, Opera) and on mobile devices (iPhone, Android, Opera Mobile & Mini, Blackberry, IE Mobile 7, etc.)

And of course they don't work on IE < 9.0, but I have a solution that I'm already using on production servers. I wrote a small JavaScript file that reads all the <link> elements from DOM, checks which of them are destined for the current device resolution and applies them.

...
<head>
<!-- Your .css files. IE6, IE7 and IE8 ignore the media="only all ..." files. -->
   <link rel="stylesheet" type="text/css" href="core.css" />
   <link rel="stylesheet" type="text/css" href="smartphone.css" media="only all and (max-width: 480px)" id="stylesheet-480" />
   <link rel="stylesheet" type="text/css" href="tablets.css" media="only all and (min-width: 480px) and (max-width: 1024px)" id="stylesheet-1024" />
   <link rel="stylesheet" type="text/css" href="wide.css" media="only all and (min-width: 1200px)" id="stylesheet-1280" />

<!-- The mighty fix which chooses the correct stylesheet file based on the
screen resolution, and strips the 'media' attribute so IE6, IE7 and IE8
can read/interpret it -->

<!--[if lt IE 9]>
   <script type="text/javascript" src="/js/css-media-query-ie.js"></script>
<![endif]-->

</head>
...


Source From: http://ghita.org/tipoftheday/css-media-queries-for-ie

Thursday, August 2, 2012

CSS3 Gradient Button Without Images


<!DOCTYPE HTML>
<html>
<head>
<title>Untitled Document</title>
<style type="text/css">
.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;
}
.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');
}
</style>
</head>
<body>
<div class="button orange" style="width:100px;">Collabor</div>
<input type="button" class="button orange" name="Collabor" value="collabor"/>
</body>
</html>

Saturday, July 28, 2012

CSS Background transparency without affecting child elements, through RGBa and filters

The solution!

.alpha60 {
/* Fallback for web browsers that doesn't support RGBa */
background: rgb(0, 0, 0);
/* RGBa with 0.6 opacity */
background: rgba(0, 0, 0, 0.6);
}


A little caveat

Shockingly enough (erm), no version of Internet Explorer supports RGBa colors (i.e. not IE 6, IE 7 or IE 8 at the time of this writing). However, and lucky for us, in year 2000 Microsoft went crazy with implementing various filters in IE. One of them are the gradient filter, and what we can do is use that and just define the same start and end color. “Ok, but how do I get the transparency”, you might be thinking now. The answer to that is that you will declare that as part of the color hex value. A CSS gradient filter achieving the same effect as the CSS code above would look like this:



.alpha60 {
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#99000000, endColorstr=#99000000);
}



Source From: http://robertnyman.com/2010/01/11/css-background-transparency-without-affecting-child-elements-through-rgba-and-filters/


---------------------------------------
Sample Code::::

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>www.fouressinsurance.com</title>
<style>
    .main{
        height:300px;
        width:100px;
        background: rgba(0, 0, 0, 0.5);
        filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#99000000, endColorstr=#99000000);
}
    .inner{ color:#ff0000; opacity:100%; }
</style>
</head>

<body style="background:#fff">
<div class="main">
    <div class="inner">Hyderabad Web Designer www.hydwebdesigner.com</div>
</div>
 </body>
</html>
 

---------------------------------------

Thursday, July 5, 2012

IE9 - IE10pp4 CSS Hack


#element {
    color:orange;
}
#element {
    *color: white;    /* IE6 + 7, doesn't work in IE8/9 as IE7 */
}
#element {
    _color: red;     /* IE6 */
}
#element {
    color: green\0/IE8+9; /* IE8 + 9 + IE10pp4  */
}
:root #element { color:pink \0/IE9; }  /* IE9 + IE10pp4 */

Tuesday, June 19, 2012

Rotate text through CSS


.text{
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
/*filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);*/ /* Option for 90deg, -90deg */
filter: progid:DXImageTransform.Microsoft.Matrix(M11=0.70710678, M12=0.70710678, M21=-0.70710678, M22=0.70710678); /* It for any deg */
display:block;
position:relative;
margin-left:100px;
margin-left:50px\9;
font-family:Arial, Helvetica, sans-serif;
font-weight:normal;
font-size:20px;
}

Thursday, June 14, 2012

Selector css: class, id, pseudo-class, pseudo-element


An important aspect in using css is to be able to select an element to apply to it the css style.
This selection can be done based on the position of the element in the page’s structure (css selector), on a specific name given to the element (class and id) or on information other then the page structure or name (pseudo-class and pseudo-element).
To facilitate the reading of this article, I added the index of selection methods classified as css selectorclass and idpseudo-class e pseudo-element:

Css selector:

  • Selector * : select every single elements of the page
  • Type selector : select directly a specific html element
  • Descendant selector : select an element descendant from another
  • Selector > : select the direct child and of first level fo an element
  • Selector + : select an element directly adjacent to another
  • Selector [atr] : select an element with a specific attribute or an attribute with a specific

.class e #id:

  • .class : select an element based on a specific class name
  • #id : select an element based on a specific identification name (id)

Pseudo-class:

Pseudo-element:

  • :first-line : define the css style of the first line of an element
  • :first-letter : define the css style of the first letter of an element
  • :before and :after : define the css style of a content generated before or after an element

Css selector

1. Selector *

Selector * said universal select every single element of the page.
Example of css rule:
* {
font-style: italic;
color: red;
}
In this example, all the page fonts will be in italic and colored red.

2. Type selector

The type selector allows you to select an html element directly.
Example of css rule:
h1{
font-style: italic;
color: red;
}
In this example, all the element h1 will be in italic and colored red.

3. Descendant selector

The descendant selector select the child elements of another element
Example of css rule:
p span{
font-style: italic;
color: red;
}
In this example, all the span elements inside a paragraph will be in italic and colored red.
Example of css rule:
#myDiv a{
font-style: italic;
color: red;
}
In this example, all the links inside the div with the id name myDiv will be in italic and colored red.

4. Selector >

The selector > select the direct child of first level of an element

NB: NOT compatible with Internet Explorer 6 and inferior version
Example of css rule:
body > p{
font-style: italic;
color: red;
}
Example HTML:
<body>
<p>I am a direct child of first level of body</p>
<div>
<p>I am not a child of first level of body but a paragraph of second level</p>
</div>
</body>
In this example, only the paragraphs directly inside body will be italic and colored red.
Instead, if the paragraphs are inside another element, they are not considered as first child of first level and the css rules will not be applied to them.

5. Selector +

The selector + select an element directly adjacent to another.
Example of css rule:
div + p{
font-style: italic;
color: red;
}
Example HTML:
<div>I am an element div</div>
<p>I am a paragraph directly adjacent to the div</p>
<p>I am NOT a paragraph directly adjacent to the div</p>
In this example, only the first paragraph directly after the element div will be italic and colored red.
The css rules will not be applied to the following paragraphs.

6. Selector [attr]

Selettore [attr] select an element with a specific attribute or an attribute with a specific value.
NB: NOT compatible with Internet Explorer 6.
Example of css rules to select an element with an attribute without a specific value:
p[id]{
font-style: italic;
color: red;
}
Example HTML:
<p id="selected">I am paragraph with an id name</p>
<p>I am a paragraph without an id name</p>
In this example, all the paragraphs with an id will be in italic and colored red whatever is the id name.
The css rules will not be applied to the paragraph without an id.
Example of css rules to select an element with an attribute and a specific value:
p[class="selected"]{
font-style: italic;
color: red;
}
Example HTML:
<p class="selected">I am a paragraph with an attribute ‘class’ and the value ‘selected’</p>
<p class="other">I am a paragraph with an attribute ‘class’ but with another value then ‘selected’</p>
<p>I am a paragraph without an attribute ‘class’</p>
In this example, all the paragraphs with an attribute ‘class’ and the value ‘selected’ will be in italic and colored red.
The css rules will not be applied to the paragraphs without the attribute ‘class’ o with an attribute ‘class’ of different value of ‘selected’.

.class and #id

1. Selector .class

Select an element based on a specific class name (syntax: .className).
The class name can be applied to more elements which share the same css style.
Example of css rule:
p.myClass{
font-style: italic;
color: red;
}
Esempio HTML:
<p class="myClass">
I am a paragraph with the class name ‘myClass’
</p>
In this case, all the paragraph with the class name ‘myClass’ will be in italic and colored red.
The classes can be applied to different types of element.
Example of css rule:
.myClass{
font-style: italic;
color: red;
}
ExampleHTML:
<div class="myClass">I am a div element with the class name ‘ myClass’</div>
<p> <span class="miaClasse">I am a span element with the class name ‘myClass’</span></p>
In this example, both html elements <div> and <span> will be in italic and colored red.
NB: more classes can be applied to an element (buggy with Internet Explorer 6)
Example of css rules:
.myClass1{
font-style: italic;
}

.myClass2{
color: red;
}
Example HTML:
<p class="myClass1 myClass2">I am an element p with 2 class names</p>

2. Selector #id

The selector #id select an element with a specific and unique id name which can not be applied to other elements.
Example css rules:
#myId{
font-style: italic;
color: green;
}
Example HTML:
<p id="myId">I am a paragraph with an id name ‘myId’</p>
In this example, only the paragraph with the id name ‘myId’ will be italic and colored green.

Pseudo-class

1. :first-child and :last-child

Le pseudo-classi :first-child e :last-child select the first or last child of an element.
NB: NOT compatible with Internet Explorer 6.
:last-child NOT compatible with Internet Explorer 7 and Safari 3.0
Example to select the first child element:
#parent p:first-child{
font-style: italic;
color: red;
}
Example HTML:
<div id="parent">
<p>I am a paragraph, first child of the div element</p>
<p>I am a paragraph, second child of the div element</p>
<p>I am a paragraph, third child of the div element</p>
</div>
In this example, only the first paragraph inside the element div will be italic and colored red. The css rules will not be applied to the following paragraphs.
Example of css rules to select the last child element
#parent p:last-child{
font-style: italic;
color: red;
}
Example HTML:
<div id="parent">
<p>I am a paragraph, first child of the div element</p>
<p>I am a paragraph, second child of the div element</p>
<p>I am a paragraph, third and last child of the div element</p>
</div>
In this example, only the last paragraph inside the element div will be italic and colored red. The css rules will not be applied to the preceding paragraphs.
I pseudo-classi :link e :visited define the css style of the links before and after being visited
Example of css rules for :link e :visited: applied to a link (element a) with a class name ‘mylink’:
a.myLink:link{
color: red;
}
a.myLink:visited{
color: green;
}
Example HTML:
<a class="myLink" href="#nogo">I am a link with a class name ‘myLink”, red before and green after being visited</a>

3. :hover and :active

The pseudo-classes :hover and :active define the css style of an element rolling over and once clicked with the mouse
NB: :active compatible with Internet Explorer only for links, html element a
:hover compatible with Internet Explorer 6 only for links, html element a
Example css rules for :hover and :active applied to a link (element a):
a:hover{
color: red;
}
a:active{
color: green;
}
Example HTML:
<a href="#nogo">I am a link, red on the hover state, green when clicked</a>
Example css rules for :hover and :active applied to a paragraph (element p):
p:hover{
background-color: #F5F5F5;
}
p:active{
background-color: black;
color: white;
}
Esempio HTML:
<p>I am a paragraph with a grey background on the over state; with a black background and white text when clicked.</p>

4. :focus

The pseudo-class :focus define the css style of a selected element in a form.
NB: NOT compatible with Internet Explorer 7 e inferior version.
Example css rule:
input:focus{
background-color: black;
color: white;
}
Example HTML:
<form action="#">
<label for="nome">Nome</label>
<input id="nome" />
<label for="email">Email</label>
<input id="email" />
</form>
In this case, the selected text field will have a black background and white text.

Pseudo element

1. :first-line

The pseudo-element :first-line define the css style of the first line of an element.
Example css rule:
#myParagraph:first-line{
font-style: italic;
color: red;
}
Example HTML:
<p id="myParagraph">The first line of this paragraph will be in italic and colored red</p>

2. :first-letter

The pseudo-element :first-letter define the css style of the first letter of an element
Example css rule:
#myParagraph:first-letter{
font-style: italic;
color: red;
font-size: 30px;
}
Example HTML:
<p id="myParagraph">The first letter of this paragraph will be in italic and colored red</p>

3. :before and :after

The pseudo-elements :after and :before define the css style of a content generated before or after an element
NB: NOT compatible with Internet Explorer 7 e inferior version.
Example css rules:
#myParagraph:before{
content: “I am the content generated before the paragraph”;
font-style: italic;
color: red;
font-size: 30px;
}
#myParagraph:after{
content: “I am the content generated after the paragraph”;
font-style: italic;
color: green;
font-size: 30px;
}
Example HTML:
<p id="myParagraph">I am a paragraph</p>