javascript - 单选按钮后面的垂直线
问题描述
我有一组 7 个单选按钮,我需要中间的一个 (id=q1val6) 在其后面有一条短垂直线(以指示李克特量表的零点)。
<form name="form1" action="#" onsubmit="jsPsych.finishTrial()" method="post">
<div class="likertline0">
<input class="radio" style="display:inline" type="radio" id="q1val3" name="q1" value="-3"/>
<input class="radio" style="display:inline" type="radio" id="q1val4" name="q1" value="-2"/>
<input class="radio" style="display:inline" type="radio" id="q1val5" name="q1" value="-1"/>
<input class="radio" style="display:inline" type="radio" checked id="q1val6" name="q1" value="0"/>
<input class="radio" style="display:inline" type="radio" id="q1val7" name="q1" value="1"/>
<input class="radio" style="display:inline" type="radio" id="q1val8" name="q1" value="2"/>
<input class="radio" style="display:inline" type="radio" id="q1val9" name="q1" value="3"/>
</form>
CSS:
.likertline0:before {
content: '';
position: relative;
top: 16px;
display: block;
z-index: -1;
left: 4%;
background-color: gray;
height: 4px;
align-items: center;
width: 93%;
}
.radio {
display: none;
width: 20px;
margin: 0 10px 0 10px;
/* this is a green */
}
.radio input[type='radio'] {
display: none;
}
.radio label {
color: #666;
font-weight: normal;
}
.radiolabel:before {
content: " ";
display: inline-block;
position: relative;
top: 5px;
margin: 0 5px 0 0;
width: 20px;
height: 20px;
border-radius: 11px;
border: 2px solid #004c97;
background-color: transparent;
}
.radio input[type=radio]:checked+label:after {
border-radius: 11px;
width: 12px;
height: 12px;
position: absolute;
top: 9px;
left: 10px;
content: " ";
display: block;
background: #004c97;
}
我正在尝试在背景中使用彩色 div,但它似乎不起作用,可能是因为我有 ::before 运算符,它用于按钮后面的行。我更喜欢一个简单的解决方案,而不是隐藏按钮本身并用图像替换它们,但如果这是唯一的方法,请告诉我。
编辑:我刚刚意识到 CSS 部分不正确,我把不相关的东西放在那里,CSS 应该是这样的:
.likertline0:before {
content: '';
position: relative;
top: 16px;
display: block;
z-index: -1;
left: 4%;
background-color: gray;
height: 4px;
align-items: center;
width: 93%;
}
.radio {
display: none;
width: 20px;
margin: 0 10px 0 10px;
/* this is a green */
}
解决方案
我会这样做:
<html>
<head>
<style>
.centre {
background-image: linear-gradient(to right,
#ffffff,
#ffffff 45%,
#aaaaaa 45%,
#aaaaaa 55%,
#ffffff 55%);
}
.radio {
display: none;
width: 20px;
margin: 0 10px 0 10px;
}
</style>
</head>
<body>
<form name="form1" action="#" onsubmit="jsPsych.finishTrial()" method="post">
<div class="likertline0">
<input class="radio" style="display:inline" type="radio" id="q1val3" name="q1" value="-3"/>
<input class="radio" style="display:inline" type="radio" id="q1val4" name="q1" value="-2"/>
<input class="radio" style="display:inline" type="radio" id="q1val5" name="q1" value="-1"/>
<span class="centre"><input class="radio" style="display:inline" type="radio" checked id="q1val6" name="q1" value="0"/></span>
<input class="radio" style="display:inline" type="radio" id="q1val7" name="q1" value="1"/>
<input class="radio" style="display:inline" type="radio" id="q1val8" name="q1" value="2"/>
<input class="radio" style="display:inline" type="radio" id="q1val9" name="q1" value="3"/>
</form>
</body>
</html>
您可以随心所欲地调整线条的宽度和颜色,甚至渐变。
推荐阅读
- cookies - 限制网站上所有 cookie 的最大使用期限或过期时间
- javascript - 如何取消选择 oracle apex 中的导航子菜单?
- asp.net - 有没有办法在使用 jExcel 或 jSpreadsheet 创建的报告中检查和显示数据库中的实时更新数据?
- node.js - Firebase 上的网站没有得到我的服务器 nodejs express 的 cookie(oauth2 不和谐护照)
- laravel - 错误的响应代码 URL 返回了错误的 HTTP 响应代码
- javascript - 将捕获按钮添加到捕获窗口的底部中心
- c++ - 重载箭头运算符为 ref 合格
- excel - 数据帮助和提示
- c# - 为什么使用 64 位哈希而不是字符串时字典的内存消耗会增加?
- reactjs - React中如何将子元素传递给父元素