在表单内设置单选按钮的样式

时间:2015-02-13 07:57:47

标签: css html5 forms radio-button

我正在尝试为我有一个单选按钮的表单设置样式。我想更改单选按钮的默认视图,并为单选按钮和检查图像添加背景图像。此外,我想将我的表格放在屏幕的中央,并用一条线突出显示。我的代码在jsfiddle:

           <style>
                form{
                    font-size: 200%;
                    font-family: "Courier New", Monospace;
                    display: inline-block;
                    align: middle;
                    text-align: center;
                    font-weight: bold; 
                     background-size: 20px; 
                }     

                input[type="radio"] {
                      width: 26px;
                      height: 26px;
                      background: url(check.png) no-repeat;

                }

                </style>

http://jsfiddle.net/chrathan/q1mnq2os/2/ 1

我该如何执行这些操作?

2 个答案:

答案 0 :(得分:1)

居中表格:

删除

display:inline-block

并添加:

margin:0 auto

形成。

Updated jsfiddle is here.

This is a nice link for styling radio button.

答案 1 :(得分:1)

试试这个

*{box-sizing: border-box}
form{
    font-size: 200%;
    font-family: "Courier New", Monospace;
    text-align: center;
    font-weight: bold; 
    width: 320px;
    margin: 0 auto;
    background-size: 20px; 
}     

input[type="radio"] {
    width: 26px;
    height: 26px;
    visibility: hidden;
    display: none
}
label{
    position: relative;
    margin-right: 40px
}
label:after{
    content: '';
    position: absolute;
    right: -40px;
    top: 0;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border: 2px solid blue;
    border-radius: 50%;
}
input[type="radio"]:checked + label:after{
    background: red; /*add your background image here*/
}
<form class = "form"  action="action2.php"  method="post">
    
    <a href=' .$user. ' style=\"text-decoration:none;\"> "' .$user. '" </a><br><br>
    <p>
        <input   type="radio" name="classif" id="C1" value="true" checked="checked" hidden />
        <label for="C1">FASHION</label>
    </p>
    
    <p>
        <input type="radio" name="classif" id="C2" value="false" hidden />
        <label for="C2"> NON FASHION </label>
    
        <input type="hidden" name="imageName" value="' . $line . '">
    </p>
    
    <input   type="submit"   value="submit"  />
    </form>;