css - 在表单中设置单选按钮的样式

标签 css html forms radio-button

我正在尝试设计一个有单选按钮的表单。我想更改单选按钮的默认 View 并为单选按钮和支票图像添加背景图像。此外,我想将我的表格放在屏幕中央并用一条线突出显示。我的代码在 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

如何执行这些操作?

最佳答案

试试这个

*{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>;

关于css - 在表单中设置单选按钮的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28494913/

相关文章:

php - 用户未登录时 JQuery btn-widgetbar 重定向

html - 在容器调整大小中输入文本大小

javascript - 如何防止在 DOM 准备好之前提交表单?

Javascript - 在提交表单之前删除隐藏字段或设置为空

html - Bootstrap 中的垂直对齐元素

javascript - 下拉菜单隐藏在图像后面

javascript - animatedModal.js 的对话框使链接不可点击(即使它有 z-index :-9999)

html - 使用 ng-show AngularJS 传递元素

c# - 如何在 .aspx 页面中为 CssClass 分配动态值不起作用

javascript - 在 javascript 中切换表单输入状态