Приветствую Вас Гость

Категории каталога
Продвижение сайтов [4]
Seo штучки и все что поможет повысить сайт в выдаче поисковика
Настройка сайтов и сео-штучки [7]
Партнерские [0]
Советы вебмастерам [36]
Дорогие коллеги, новички и профи, загляните, улыбнитесь, почитайте, дабы не наступать на грабли дважды. Дорогие клиенты - представьте себя в нашей шкуре :)
Поиск
Статистика

Статьи о сайтостроительстве


Главная » Статьи » Советы вебмастерам

Стилизация чекбоксов

This JavaScript and CSS will allow you to use custom images to stylecheckboxes,radio buttons and select lists.

Checkboxes, Radio Buttons, Select Lists, Custom HTML Form Elements

Have you ever wanted to use your own images for checkboxes, radio buttons or select lists? This script will let you do that. Easily. The unobtrusive script gracefully degrades, so if JavaScript is disabled, normal form input objects appear instead of your customized elements. This works flawlessly in Firefox, Safari, Internet Explorer 7, Opera and others. In Internet Explorer, the select lists are unstyled, but the checkboxes and radio buttons still look and function beautifully. It's this easy:

     
  1. <input type="checkbox" class="styled" />

The example

 
   

Sexy

   

Boring

   

Sleek

   

Nice

 
 
   

Radical

   

Good

   

Fair

   

Poor

 
 
   

This         

   

What         

 

View a more comprehensive example

How does it work?

In a nutshell, the JavaScript looks for every form element with class="styled" on it; hides the real form element; sticks a span tag with a CSS class on it next to the element; and, finally, mouse events are added to the span that handles the visual stages form inputs go through when they are clicked.

Download the full script

Download the CSS file

Custom CheckboxesCustom Radio Buttons

To get the checkboxes, radio buttons and select boxes to work properly, you'll need to change three variables in the script: checkboxHeight, radioHeight and selectWidth on lines 21-23. If you use the images I created, you won't have to change the variables, but if you make your own, chances are you'll have to. The checkboxes and radio buttons to the right are linked to transparent PNG images for you to use freely if you'd like. The first two variables are the height of a single stage of the checkbox and radio button, and the third is the width of the select box. You may need to spend a little time tinkering with the checkbox and radio button images so they don't twitch during different stages.

     
  1. var checkboxHeight = "25";
  2.  
  3. var radioHeight = "25";
  4.  
  5. var selectWidth = "190";

The CSS

If you make your own images, you may need to change a few things in the cascading style sheet. In .checkbox and .radio, the height property should be one fourth of the height of the full size images. You also might have to change the width property in.select selector. You probably won't have to edit any other portions of the CSS, but regardless, this part is still straight forward.

     
  1. .checkbox, .radio {
  2.  
  3.  width: 19px;
  4.  
  5.  height: 25px;
  6.  
  7.  padding: 0 5px 0 0;
  8.  
  9.  background: url(checkbox.gif) no-repeat;
  10.  
  11.  display: block;
  12.  
  13.  clear: left;
  14.  
  15.  float: left;
  16.  
  17. }
  18.  
  19. .radio {
  20.  
  21.  background: url(radio.gif) no-repeat;
  22.  
  23. }
  24.  
  25. .select {
  26.  
  27.  position: absolute;
  28.  
  29.  width: 158px;
  30.  
  31.  height: 21px;
  32.  
  33.  padding: 0 24px 0 8px;
  34.  
  35.  color: #fff;
  36.  
  37.  font: 12px/21px arial,sans-serif;
  38.  
  39.  background: url(select.gif) no-repeat;
  40.  
  41.  overflow: hidden;
  42.  
  43. }

The XHTML

The script won't customize checkboxes, radio buttons or select lists unless you declare the styled class. Simply add class="styled" to any checkbox, radio button or option list and the JavaScript and CSS will take over from there.

Checkbox

     
  1. <input type="checkbox" name="a" class="styled" />

Radio button

     
  1. <input type="radio" name="radio" class="styled" /> Yes
  2.  
  3. <input type="radio" name="radio" class="styled" /> No

Select list

     
  1. <select name="d" class="styled">
  2.  
  3.  <option value="1">Option 1</option>
  4.  
  5.  <option value="2">Option 2</option>
  6.  
  7.  <option value="3">Option 3</option>
  8.  
  9. </select>

Usage

You are free to share, alter and use this script commercially. Just leave the title, my name and website in tact in the JavaScript script. This script is licensed under aCreative Commons license.

Категория: Советы вебмастерам | Добавил: cmerlin (17.10.2011)
Просмотров: 2098
Хентай
фанфики