简体   繁体   English

造型单选按钮没有标签

[英]Styling radio button without label

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). 我正在使用IBM SPSS Data Collection进行在线调查,这意味着它根据我可以设计的一些模板(主要是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> . 我发现了许多教程如何使用纯CSS设置单选按钮和复选框的样式,问题是,所有这些都使用标签: <label for="id"></label> Point is, that generaged code does not have <label> . 重点是,生成的代码没有<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. 我试图更改html代码以添加标签,但它确实有效,但这并不是我需要的。 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: 当我使用这个解决方案(不合适的解决方案)时,我可以简单地使用CSS添加单选按钮和复选框,添加如下背景图像:

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? 有没有办法使用javacsript或其他东西为生成的页面上的每个单选按钮或复选框添加假空白标签?

or 要么

  • is there any other way I could solve this without need edit generated page code eg 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 doesn´t matter if you have a label or not. 没有办法用纯CSS设置单选按钮的样式,但你可以用CSS和JavaScript混合,在收音机上放置一个假图像并显示没有单选按钮开头,这样做,无所谓如果你有标签或没有。 If you don´t want to make your own script, there are several plugin to do this: 如果你不想制作自己的脚本,有几个插件可以做到这一点:

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: 查看使用Inspector工具编辑的代码:

在此输入图像描述

For pure CSS styling of Radio Button without label, try the following: 对于没有标签的单选按钮的纯CSS样式,请尝试以下操作:

input[type=radio]:not(old) {
  display: inline-block;
  -webkit-appearance: none;
  -moz-appearance: none;
  -o-appearance: none;
  appearance: none;
  border-radius: 1em;
  border: 3px solid #555;
}

input[type=radio]:not(old):checked{
  background-image: radial-gradient(circle at center, #555, #555 37.5%, #fff 40%, #fff 100%);
}

The width, height, border thickness and colours can all be styled as required. 宽度,高度,边框厚度和颜色都可以根据需要设计。

It is also possible to use svg images for the checked and unchecked states using something like below: 也可以使用以下内容将svg图像用于已检查和未检查的状态:

input[type=radio]:not(old) {
  display: inline-block;
  -webkit-appearance: none;
  -moz-appearance: none;
  -o-appearance: none;
  appearance: none;
  background-image: url('unchecked.svg') no-repeat;
  background-size: cover;
  background-origin: center;
}

input[type=radio]:not(old):checked{
  background-image: url('checked.svg') no-repeat;
  background-size: cover;
  background-origin: center;
}

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

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