简体   繁体   English

在检查如何更改单选按钮的颜色?

[英]On checked how to change the color of radio button?

How I can change the color of a radio button after selecting it?选择后如何更改单选按钮的颜色? I'm using this code but it's not working for me.我正在使用此代码,但它对我不起作用。

    <div class="container3">
        <label class="columnName" style="margin-bottom:7px">Analytics</label><span style="color: red !important; display: inline; float: none;">    *</span><br></br>
        <label class="btn-primary">
            <input type="radio" name="first" id="radio1" value="SQL" style="margin-left: 10px"></input><span style="margin-left:20px">SQL </span>  
        </label><br></br>
        <label class="btn-primary">
            <input type="radio" name="first" id="radio2" value="Python" style="margin-left: 10px"></input><span style="margin-left:20px">Python </span>
        </label>
    </div>

And my CSS code is:我的 CSS 代码是:

           .container3 input[type="radio"]:checked 
                   {
                    background-color: #ff0000;
                 }

But this is not working for me.但这对我不起作用。 Can someone please help me to figure out this without implementing custom images or use of custom Javascript library?有人可以在不实现自定义图像或使用自定义 Javascript 库的情况下帮我解决这个问题吗? Thank you谢谢

Do you want something like this?你想要这样的东西吗?

 /* The container */.container { display: block; position: relative; padding-left: 35px; margin-bottom: 12px; cursor: pointer; font-size: 22px; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } /* Hide the browser's default radio button */.container input { position: absolute; opacity: 0; cursor: pointer; } /* Create a custom radio button */.checkmark { position: absolute; top: 0; left: 0; height: 25px; width: 25px; background-color: #eee; border-radius: 50%; } /* On mouse-over, add a grey background color */.container:hover input ~.checkmark { background-color: #ccc; } /* When the radio button is checked, add a blue background */ /* Create the indicator (the dot/circle - hidden when not checked) */.checkmark:after { content: ""; position: absolute; display: none; }.container input:checked ~.checkmark { background-color: #ff9999; } /* Show the indicator (dot/circle) when checked */.container input:checked ~.checkmark:after { display: block; background: #ff9999; } /* Style the indicator (dot/circle) */.container.checkmark:after { top: 9px; left: 9px; width: 8px; height: 8px; border-radius: 50%; background: white; }
 <h1>Custom Radio Buttons</h1> <label class="container">Php <input type="radio" checked="checked" name="radio"> <span class="checkmark"></span> </label> <label class="container">Java <input type="radio" name="radio"> <span class="checkmark"></span> </label> <label class="container">Python <input type="radio" name="radio"> <span class="checkmark"></span> </label> <label class="container">Sql <input type="radio" name="radio"> <span class="checkmark"></span> </label>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM