没有标签的样式单选按钮

2023-10-21前端开发问题
1

本文介绍了没有标签的样式单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我现在面临这个问题:我想为系统生成的没有标签的单选按钮复选框设置样式.

我正在使用 IBM SPSS Data Collection 进行在线调查,这意味着它会根据我可以设置样式的某些模板(主要是 CSS 样式)生成所有页面问题.

我发现很多教程如何使用纯 CSS 设置单选按钮和复选框的样式,问题是,所有这些都使用标签:<label for="id"></label>.关键是,生成的代码没有 <label>.

正如我所说,对象没有标签,例如单个单选按钮由此代码定义(我还想附上屏幕截图,但我没有足够的声誉点):

我尝试更改 html 代码以添加标签并且它有效,但这并不是我所需要的.此解决方案出现的问题是,我不能让系统轮换集成主题(问题),因为无法生成页面但必须明确编写.

当我使用这个解决方案(这不是一个合适的解决方案)时,我可以简单地使用 CSS 添加背景图像来重新设置带有标签的单选按钮和复选框:

input[type=radio]:not(old) + label{显示:内联块;左边距:-28px;padding-left : 40px;背景:url('radio_off.png')不重复0 0;背景尺寸:30px 30px;行高:35px;}输入[type=radio]:not(old):checked + label{背景 : url('/radio_on.png') no-repeat 0 0;背景尺寸:29px 29px;}

所以我的问题是:

  • 有没有办法在没有标签的情况下重新设置单选按钮和复选框的样式?

  • 有没有办法使用 javacsript 或其他方法为生成页面上的每个单选按钮或复选框添加假空白标签?

  • 有没有其他方法可以解决这个问题而无需编辑生成的页面代码,例如我可以使用它是如何生成的页面吗?

如果我没有提供任何必要的信息,请索取,如果可以的话,我会提供.

非常感谢您的帮助!

问候,

彼得

解决方案


没有办法使用纯 CSS 来设置单选按钮的样式,但是您可以使用 CSS 和 JavaScript 混合来实现,在单选按钮上放置一个假图像并不显示单选按钮一开始,要做到这一点,是否有标签并不重要.如果您不想制作自己的脚本,有几个插件可以做到这一点:

  • I am now facing this problem: I want to style radio buttons and checkboxes that are generated by system and do not have a label.

    I am working with IBM SPSS Data Collection for making online surveys, so that means it generates all questions to page according to some template I can style (mostly styling with CSS).

    I found out many tutorials how to style radio buttons and checkboxes using pure CSS, problem is, all of them are using label: <label for="id"></label>. Point is, that generaged code does not have <label>.

    As I said, objects are without label, and single radio button for example is defined by this code (I wanted also attach screenshot how it looks like, but i do not have enough reputation points):

    <td id="Cell.2.1" style="text-Align: Center;vertical-align: Middle;background-color: #e6efe6;width: 7%;border-color: Black;border-style: Solid;border-width: 0px;">
      <div></div>
      <input type="radio" name="_QQ3_Qa_QSingleResponseQuestion_C" id="_Q0_Q0_Q0_C1" class="mrSingle" style="font-family: Trebuchet MS;font-size: 9pt;" value="b"></input>
    </td>
    

    I tried to change html code to add label and it worked, but it is not exactly what I need. Problem that occurs with this solution is, I can't let system rotate integrated subjects (questions), because page cannot be generated but have to be explicitly written.

    When I used this solution (which is not suitable one), I could simply restyle radio buttons and checkboxes with lable using CSS adding background images like this:

    input[type=radio]:not(old) + label{
      display      : inline-block;
      margin-left  : -28px;
      padding-left : 40px;
      background   : url('radio_off.png') no-repeat 0 0;
      background-size:30px 30px;
      line-height  : 35px;
    }
    
    input[type=radio]:not(old):checked + label{
      background   : url('/radio_on.png') no-repeat 0 0;
      background-size:29px 29px;
    }
    

    So my questions are:

    • is there a way to restyle radio buttons and checkboxes without lable?

    or

    • is there a way to add fake blank lable to every radio button or checkbox on generated page using javacsript or something other?

    or

    • is there any other way I could solve this without need edit generated page code e.g. I can use page how it ist generated?

    If I did not included any of the necessary informations, pleas ask for them, i will provide them if I am able to.

    Thanks a lot for any help!

    Regards,

    Peter

    解决方案


    There is no way to style radio buttons with pure CSS, but you can do it with CSS and JavaScript mix, positioning a fake image over the radio and displaying to none the radio button At the beginning, to do this, to doesnt matter if you have a label or not. If you dont want to make your own script, there are several plugin to do this:

    • http://www.hongkiat.com/blog/css3-checkbox-radio/
    • http://www.csscheckbox.com/radio-buttons.php
    • Even Ive my own plugin: http://albertofortes.com/projects/piscoPrettyForms/

    In my plugin you don't need the label to style the radio button, there is a label but isn't use to style so you can remove it and still works.

    See this code edited with Inspector tools:

    这篇关于没有标签的样式单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

    The End

相关推荐

Fatal error: Call to a member function fetch_assoc() on a no
业务场景:使用update语句去更新数据库字段。 原因:update接收值不正确。原来代码: $query = "UPDATE student SET date = now() WHERE id = $id";$result = $mysqli-query($query2) or die($mysqli-error); // 问题出现了在这句 $data = $result-fetch_ass...
2024-12-13 前端开发问题
136

layui实现laydate日历控件控制之前日期不可选择
具体实现代码如下: laydate.render({ elem: '#start_time', min:0, //,type: 'date' //默认,可不填}); 只要加一个min参数,就可以控制了。0表示之前的日期不可...
2024-11-29 前端开发问题
133

ajax请求获取json数据并处理的实例代码
ajax请求获取json数据并处理的实例代码 $.ajax({ type: 'GET', url: 'https://localhost:44369/UserInfo/EditUserJson',//请求数据 data: json,//传递数据 //dataType:'json/text',//预计服务器返回的类型 timeout: 3000,//请求超时的时间 //回调函数传参 suc...
2024-11-22 前端开发问题
215

js删除数组中指定元素的5种方法
在JavaScript中,我们有多种方法可以删除数组中的指定元素。以下给出了5种常见的方法并提供了相应的代码示例: 1.使用splice()方法: let array = [0, 1, 2, 3, 4, 5];let index = array.indexOf(2);if (index -1) { array.splice(index, 1);}// array = [0,...
2024-11-22 前端开发问题
182

layui 实现实时刷新一个外部的div
主页面上显示了一个合计,在删除和增加的时候需要更改这个总套数的值: //html代码div class="layui-inline layui-show-xs-block" style="margin-left: 10px" id="sumDiv"spanSOP合计:/spanspan${totalNum}/spanspan套/span/div 于是在我们删除这个条数据后,...
2024-11-14 前端开发问题
156

layui 单选框、复选框、下拉菜单不显示问题如何解决?
1. 如果是ajax嵌套了 页面, 请确保 只有最外层的页面引入了layui.css 和 layui.js ,内层页面 切记不要再次引入 2. 具体代码如下 layui.use(['form', 'upload'], function(){ var form = layui.form; form.render(); // 加入这一句});...
2024-11-09 前端开发问题
313