zoukankan      html  css  js  c++  java
  • Checkboxes, Radio Buttons, Select Lists, Custom HTML Form Elements

    This JavaScript and CSS will allow you to use custom images to style checkboxes, 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 Checkboxes Custom 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 frist 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. var radioHeight = "25";
    3. 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.    19px;
    3.   height: 25px;
    4.   padding: 0 5px 0 0;
    5.   background: url(checkbox.gif) no-repeat;
    6.   display: block;
    7.   clear: left;
    8.   float: left;
    9. }
    10. .radio {
    11.   background: url(radio.gif) no-repeat;
    12. }
    13. .select {
    14.   position: absolute;
    15.    158px;
    16.   height: 21px;
    17.   padding: 0 24px 0 8px;
    18.   color: #fff;
    19.   font: 12px/21px arial,sans-serif;
    20.   background: url(select.gif) no-repeat;
    21.   overflow: hidden;
    22. }

    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. <input type="radio" name="radio" class="styled" /> No

    Select list

    1. <select name="d" class="styled">
    2.   <option value="1">Option 1</option>
    3.   <option value="2">Option 2</option>
    4.   <option value="3">Option 3</option>
    5. </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 a Creative Commons license.

    from: http://ryanfait.com/resources/custom-checkboxes-and-radio-buttons/

  • 相关阅读:
    ShellExecuteEX打开iqy文件导致excel hang的原因分析
    3种方法遍历商人访问5个城市问题
    用CRT查找内存泄漏
    同步异步和阻塞5-异步非阻塞
    同步异步和阻塞4-同步非阻塞
    同步异步和阻塞3-同步阻塞
    同步异步和阻塞2-测试小项目
    同步异步和阻塞1
    IDA分析脱壳后丢失导入表的PE
    计算机中补码的数学运算逻辑及证明
  • 原文地址:https://www.cnblogs.com/Langzi127/p/2038922.html
Copyright © 2011-2022 走看看