CSS 使单选按钮显示为小彩色框
我正在实现一个具有购物车功能的网站,并希望用户能够为他们购买的产品选择颜色。
假设我从这样的事情开始:
<form action="">
<input type="radio" name="color" value="red" />
<input type="radio" name="color" value="green" />
<input type="radio" name="color" value="black" />
</form>
需要什么 CSS 来显示每个选项的彩色框,这些框水平显示并在所选选项周围有边框?
沿着:
[红盒] [绿盒] [黑盒]
Im implementing a site with shopping cart features and want the user to be able to select the color for the product they are purchasing.
Let's say I started with something like this:
<form action="">
<input type="radio" name="color" value="red" />
<input type="radio" name="color" value="green" />
<input type="radio" name="color" value="black" />
</form>
What CSS is needed to show coloured boxes for each of the options, with the boxes displayed horizontally and have a border around the selected option?
Along the lines of:
[redbox] [greenbox] [blackbox]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以查看 jQuery UI 的按钮 http://jqueryui.com/demos/button/#radio
它允许您为复选框/单选按钮等创建漂亮的样式。
我不确定您是否想为此使用整个框架,但据我所知,单选按钮不是非常“有风格”。您需要在它旁边创建另一个元素,并以编程方式更改单选按钮的选定值。
希望这有帮助,
马科
You can check out jQuery UI's Button http://jqueryui.com/demos/button/#radio
It allows you to create nice styles for checkboxes/radio buttons and so on..
I'm not sure if you'd want to use a whole framework for that though, but as far as I know, radio buttons aren't very 'stylable'. You'd need to create another element next to it, and change the selected value of the radio button programatically.
Hope this helps,
Marko
因为每个浏览器都会以不同的方式呈现按钮,所以我将使用一系列按钮来改变隐藏输入字段的状态。 (我没有测试这一点,但这是总体思路):
Because each browser is going to render the button differently, I would use a series buttons that are altering the state of a hidden input field. (I didn't test this, but it's the general idea):
我认为您不会使用无线电盒。您可以有一个隐藏的输入字段来存储颜色,以及 3 个用于颜色框的 div。 onclick 事件将处理设置类,以便所选项目具有边框并设置隐藏值。
使用 jQuery 它看起来像这样:
即使我有一些语法错误,也许这会让你走上正确的道路?...让我知道我是否可以提供更多帮助。
I would think that you wouldn't use radio boxes. You can have a hidden input field that stores the color, and 3 div's for the color boxes. onclick events would handle setting the classes so the selected item has the border and the hidden value is set.
Using jQuery it would look something like this:
Even if I have some syntax wrong, maybe this will set you on the right path?.. let me know if I can be of more help.