zoukankan      html  css  js  c++  java
  • 自定义单选框radio样式

    <!doctype html>
    <html>
    <head>
        <meta charset="utf-8">
        <title>自定义单选框radio样式</title>
    </head>
    <style>
        body { margin: 0; }
        input { padding: 0; margin: 0; border: 0; }
        .female, .male { position: relative; /* 设置为相对定位,以便让子元素能绝对定位 */ height: 40px; line-height: 40px; margin-left: 40px; }
        .sex label { display: block; height: 40px; width: 40px; line-height: 40px; font-size: 20px; cursor: pointer; }
        .sex input { z-index: 3; position: absolute; top: 0; bottom: 0; left: 40px; margin: auto; /* 这里及以上的定位,可以让该元素竖直居中。(top: 0; bottom: 0;) */ opacity: 0; display: block; width: 30px; height: 30px; cursor: pointer; }
        .sex span { position: absolute; top: 0; bottom: 0; left: 40px; margin: auto; display: block; width: 25px; height: 25px; border: 1px solid #000; border-radius: 50%; cursor: pointer; }
        .sex span.active { background-color: #000;padding:-5px; }
    </style>
    <body>
    <form action="">
        <div class="sex">
            <div class="female">
                <label for="female"></label>
                <input type="radio" name="sex" id="female">
                <span class="female-custom"></span> </div>
            <div class="male">
                <label for="male"></label>
                <input type="radio" name="sex" id="male">
                <span class="male-custom"></span> </div>
        </div>
    </form>
    <script typet="text/javascript" src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
    <script>
        $("#male").click( function () {
            $(this).siblings("span").addClass("active");
            $(this).parents("div").siblings("div").children("span").removeClass("active");
        });
        $("#female").click( function () {
            $(this).siblings("span").addClass("active");
            $(this).parents("div").siblings("div").children("span").removeClass("active");
        });
    </script>
    </body>
    </html>
  • 相关阅读:
    Android编译系统
    Android指针管理:RefBase,SP,WP
    Android图片异步加载
    Android动画学习笔记Android Animation
    触发checkbox的click事件时遇到的问题
    C++ Primer笔记
    Android自定义对话框(Dialog)位置,大小
    android startService流程梳理笔记
    自定义SimpleAdapter
    Android Touch事件
  • 原文地址:https://www.cnblogs.com/gopark/p/9401105.html
Copyright © 2011-2022 走看看