LoginSignup
0
0

More than 3 years have passed since last update.

CSSでラジオボタンの表示形式変更

Last updated at Posted at 2020-10-18

CSSでラジオボタンの表示形式変更

デフォルトのラジオボタンの表示形式を変更させる際、
style="display: none;"を設定したうえ、デフォルトのラジオボタンの表示形式を無効にして、
表示したい形式のCSSを指定すれば、表示形式が変えられます。
※具体的には下記の例をご参照ください。

<html>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("#female").click(function(){
    alert($("#female").val());
  });
  $("#male").click(function(){
    alert($("#male").val());
  });
});
</script>

<style type="text/css">
<!--
. ui-radio {
padding: 6px 5px;
}

.ui-radio+label{
background:green;
padding: 7px 60px;
}


.ui-radio:checked+label{
background:yellow;
padding: 7px 60px;
}
-->
</style>
<div>
    <h1>Radioボタン</h1>
    <input type="radio" id="female" class="ui-radio" name="sex" style="display: none;" value="女性"/>
    <label for="female"></label>              
    <input type="radio" id="male" class="ui-radio" name="sex" style="display: none;"  value="男性"/>
    <label for="male"></label>
</div>
</html>


0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0