Django形式的单选按钮的背景

时间:2016-03-02 15:40:54

标签: css django forms radio-button

我找到了解决问题的一些代码,但是所有这些代码都使用了彼此靠近的输入标签和标签标签。 Django在标签内部放置了输入,这就是为什么代码在我的情况下是无效的。 我试过的变体之一here 任何建议或想法。 谢谢大家!

input[type=radio] {
display:none;
}

input[type=radio] + label
{
background: #999;
height: 16px;
width: 16px;
display:inline-block;
padding: 0 0 0 0px;
}
input[type=radio]:checked + label
{
background: #0080FF;
height: 16px;
width: 16px;
display:inline-block;
padding: 0 0 0 0px;
}

2 个答案:

答案 0 :(得分:0)

解决了问题自定义表单模板并在上面的css上应用了解决方案。

{% for field in form %}
    {% for item in field %}
        <input id="id_name_{{ forloop.counter0 }}" name="name" type="radio" value="{{ item.choice_value }}">
        <label for="id_name_{{ forloop.counter0 }}">{{ item.choice_label }}</label>
    {% endfor %}
{% endfor %}

答案 1 :(得分:0)

我还没有检查我的解决方案是否正确。 但你可以这样写:

JTextArea

欲了解更多信息,  你可以阅读官方doc