与 <input type="radio>> 一起使用的良好

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

本文介绍了与 <input type="radio>> 一起使用的良好 HTML 和 CSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

在 HTML 中使用 <input type="radio"> 的最佳方式是什么?

What's the best way to use <input type="radio"> in HTML?

我正在寻找语义良好的 HTML,其格式可通过 CSS 配置.

I'm looking for HTML that's semantically good, whose formatting is configurable via CSS.

我希望能够对其进行样式/渲染,使其看起来像:

I want to be able to style/render it to look something like:

    Car: (o) Yes
         (X) No
         (o) Maybe

  Train: (o) Yes
         (o) No
         (X) Maybe

Address: [An input text box     ]

考虑到 CSS,我想我希望左侧的标签(例如汽车"和公共汽车")位于某种 text-align: right 块中?

Thinking of the CSS, I think that I'd like the labels on the left (e.g. "Car" and "Bus") to be in some kind of text-align: right block?

我不知道右边的单选按钮:在某种 <span> 中,也许是 "display: inline-block"?还是 "white-space: pre"?

I don't know about the radio buttons on the right: in some kind of <span> perhaps, with "display: inline-block"? Or "white-space: pre"?

什么样的块级标签(例如 <p><div>)和/或其他标签(例如 <br/>) 你会推荐吗?

What kind of block-level tags (e.g. <p> or <div>) and/or other tags (e.g. <span> or <br/>) would you recommend?

下面的怎么样.

HTML 使用 <legend>,就像 HTML 应该和 alistapart 文章:

HTML uses <legend>, like HTML is supposed to and as recommended in the alistapart article:

<fieldset>
<legend>Car</legend>
<label><input type="radio" name="car" value="yes"/> Yes</label>
<label><input type="radio" name="car" value="no"/> No</label>
<label><input type="radio" name="car" value="maybe"/> Maybe</label>
</fieldset>

为了让 Firefox 更容易访问/定位 <legend> 的内容,请将其放在 <span> 中:

To make it easer for Firefox to access/position the contents of the <legend>, place it within a <span>:

<fieldset>
<legend><span>Car</span></legend>
<label><input type="radio" name="car" value="yes"/> Yes</label>
<label><input type="radio" name="car" value="no"/> No</label>
<label><input type="radio" name="car" value="maybe"/> Maybe</label>
</fieldset>

然后,使用 Legends of样式已修改以将 span 的内容定位到字段集的左侧.

Then, use the browser-specific CSS described in Legends of Style Revised to position the contents of the span to left of the fieldset.

CSS 真的必须如此复杂和特定于浏览器吗?理论上应该可以工作的最简单的 CSS 是什么,而不是在那些不完美的浏览器上实际工作所需的更复杂的 CSS?如果 <legend> 很难定位,那么有什么好的(语义)替代方案?

Does the CSS really have to be so complicated and browser-specific? What's the simplest CSS which ought theoretically to work, instead of the more-complicated CSS required to actually work with those imperfect browsers? If <legend> is hard to position then what's a good (semantic) alternative?

推荐答案

我将使用

.

<label> 在不同浏览器中定位的困难在Legends of Style Revised" 文章;因此,与其使用 <label> 并尝试定位它,我可能会在 <字段集>.

The difficulty with positioning a <label> in different browsers is described in the "Legends of Style Revised" article; so instead of using a <label> and trying to position it, I might use a <span class="label"> outside the <fieldset>.

这篇关于与 &lt;input type=&quot;radio&gt;&gt; 一起使用的良好 HTML 和 CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

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

layui要如何改变时间日历布局大小?
问题描述 我想改变layui时间日历布局大小,这个要怎么操作呢? 解决办法 可以用css样式对时间日历进行重新布局,具体代码如下: !DOCTYPE htmlhtmlheadmeta charset="UTF-8"title/titlelink rel="stylesheet" href="../../layui/css/layui.css" /style#test-...
2024-10-24 前端开发问题
271

jQuery怎么动态向页面添加代码?
append() 方法在被选元素的结尾(仍然在内部)插入指定内容。 语法: $(selector).append( content ) var creatPrintList = function(data){ var innerHtml = ""; for(var i =0;i data.length;i++){ innerHtml +="li class='contentLi'"; innerHtml +="a href...
2024-10-18 前端开发问题
125

“数组中的每个孩子都应该有一个唯一的 key prop"仅在第一次呈现页面时
quot;Each child in an array should have a unique key propquot; only on first time render of page(“数组中的每个孩子都应该有一个唯一的 key prop仅在第一次呈现页面时)...
2024-04-20 前端开发问题
5

CoffeeScript 总是以匿名函数返回
CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)...
2024-04-20 前端开发问题
13