Html 如何在卡片视图中显示水平自定义单选按钮
我正在一个电子商务系统的前端工作,它有一个卡片视图。我必须用不同的颜色显示水平自定义样式的单选按钮 我把单选按钮放在卡片上,也可以自定义,但问题是当应用自定义样式时,它不能水平工作 HTMLHtml 如何在卡片视图中显示水平自定义单选按钮,html,css,bootstrap-4,Html,Css,Bootstrap 4,我正在一个电子商务系统的前端工作,它有一个卡片视图。我必须用不同的颜色显示水平自定义样式的单选按钮 我把单选按钮放在卡片上,也可以自定义,但问题是当应用自定义样式时,它不能水平工作 HTML 单选按钮是单色的垂直按钮,但需要水平和多色您不能同时使用单选和复选框的输入类型 如果您只是简单地使用收音机,那么您的示例将按预期工作: /*自定义标签(容器)*/ .包含{ 显示:块; 位置:相对位置; 左侧填充:35px; 边缘底部:12px; 光标:指针; 字体大小:22px; -webkit用户选择
单选按钮是单色的垂直按钮,但需要水平和多色您不能同时使用单选和复选框的
输入
类型
如果您只是简单地使用收音机
,那么您的示例将按预期工作:
/*自定义标签(容器)*/
.包含{
显示:块;
位置:相对位置;
左侧填充:35px;
边缘底部:12px;
光标:指针;
字体大小:22px;
-webkit用户选择:无;
-moz用户选择:无;
-ms用户选择:无;
用户选择:无;
}
/*隐藏浏览器的默认单选按钮*/
.包含输入{
/*位置:绝对位置*/
不透明度:0;
光标:指针;
身高:0;
宽度:0;
}
/*创建自定义单选按钮*/
.对号{
位置:绝对位置;
排名:0;
左:0;
高度:25px;
宽度:25px;
背景色:#eee;
边界半径:50%;
}
/*在鼠标悬停时,添加灰色背景色*/
.contain:悬停输入~。复选标记{
背景色:#ccc;
}
/*选中单选按钮后,添加蓝色背景*/
.包含输入:选中~。选中标记{
背景色:#2196F3;
}
/*创建指示器(点/圆-未选中时隐藏)*/
.勾选:之后{
内容:“;
位置:绝对位置;
显示:无;
}
/*选中时显示指示器(点/圆)*/
.包含输入:选中~。选中标记:之后{
显示:块;
}
/*设置指示器的样式(点/圆)*/
.包含。选中标记:在{
顶部:9px;
左:9px;
宽度:8px;
高度:8px;
边界半径:50%;
背景:白色;
}
颜色
将此代码替换为您的代码
。包含{
显示:块;
位置:相对位置;
左侧填充:35px;
边缘底部:12px;
光标:指针;
字体大小:22px;
-webkit用户选择:无;
-moz用户选择:无;
-ms用户选择:无;
用户选择:无;
}
/*隐藏浏览器的默认单选按钮*/
.包含输入{
/*位置:绝对位置*/
不透明度:0;
光标:指针;
身高:0;
宽度:0;
}
/*创建自定义单选按钮*/
.对号{
位置:绝对位置;
排名:0;
左:0;
高度:25px;
宽度:25px;
背景色:#eee;
边界半径:50%;
}
/*在鼠标悬停时,添加灰色背景色*/
.contain:悬停输入~。复选标记{
背景色:#ccc;
}
/*选中单选按钮后,添加蓝色背景*/
.包含输入:选中~。选中标记{
背景色:#2196F3;
}
/*创建指示器(点/圆-未选中时隐藏)*/
.勾选:之后{
内容:“;
位置:绝对位置;
显示:无;
}
/*选中时显示指示器(点/圆)*/
.包含输入:选中~。选中标记:之后{
显示:块;
}
/*设置指示器的样式(点/圆)*/
.包含。选中标记:在{
顶部:9px;
左:9px;
宽度:8px;
高度:8px;
边界半径:50%;
背景:白色;
}
.所有的收音机{
显示:内联flex;
}
颜色
您可以使用此代码
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style type="text/css">
.contain {
display: inline-block;
position: relative;
padding-left: 35px;
margin-bottom: 12px;
cursor: pointer;
font-size: 22px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.contain input {
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}
.checkmark {
position: absolute;
top: 0;
left: 0;
height: 25px;
width: 25px;
background-color: blue;
border-radius: 50%;
}
.checkmark.one {
position: absolute;
top: 0;
left: 0;
height: 25px;
width: 25px;
background-color: green;
border-radius: 50%;
}
.checkmark.two {
position: absolute;
top: 0;
left: 0;
height: 25px;
width: 25px;
background-color: red;
border-radius: 50%;
}
.contain:hover input ~ .checkmark {
background-color: blue;
}
.contain:hover input ~ .checkmark.one {
background-color: green;
}
.contain:hover input ~ .checkmark.two {
background-color: red;
}
.contain input:checked ~ .checkmark {
background-color: blue;
}
.contain input:checked ~ .checkmark.one {
background-color: green;
}
.contain input:checked ~ .checkmark.two {
background-color: red;
}
.checkmark:after {
content: "";
position: absolute;
display: none;
}
.contain input:checked ~ .checkmark:after {
display: block;
}
.contain .checkmark:after {
top: 9px;
left: 9px;
width: 8px;
height: 8px;
border-radius: 50%;
background: white;
}
</style>
</head>
<body>
<div class="card-body">
<span style="color: #707070; font-size: 18px;"><h5><b>Color</b></h5></span>
<form>
<label class="radio-inline contain">
<input type="radio" name="optradio" >
<span class="checkmark"></span>
</label>
<label class="radio-inline contain">
<input type="radio" name="optradio">
<span class="checkmark one"></span>
</label>
<label class="radio-inline contain">
<input type="radio" name="optradio">
<span class="checkmark two"></span>
</label>
</form>
</div>
</body>
</html>
页面标题
.包含{
显示:内联块;
位置:相对位置;
左侧填充:35px;
边缘底部:12px;
光标:指针;
字体大小:22px;
-webkit用户选择:无;
-moz用户选择:无;
-ms用户选择:无;
用户选择:无;
}
.包含输入{
不透明度:0;
光标:指针;
身高:0;
宽度:0;
}
.对号{
位置:绝对位置;
排名:0;
左:0;
高度:25px;
宽度:25px;
背景颜色:蓝色;
边界半径:50%;
}
1.勾选{
位置:绝对位置;
排名:0;
左:0;
高度:25px;
宽度:25px;
背景颜色:绿色;
边界半径:50%;
}
.对勾,二{
位置:绝对位置;
排名:0;
左:0;
高度:25px;
宽度:25px;
背景色:红色;
边界半径:50%;
}
.contain:悬停输入~。复选标记{
背景颜色:蓝色;
}
.contain:悬停输入~.checkmark.one{
背景颜色:绿色;
}
.contain:悬停输入~.选中标记.two{
背景色:红色;
}
.包含输入:选中~。选中标记{
背景颜色:蓝色;
}
.contain输入:选中~.checkmark.one{
背景颜色:绿色;
}
.contain输入:选中~.checkmark.2{
背景色:红色;
}
.勾选:之后{
内容:“;
位置:绝对位置;
显示:无;
}
.包含输入:选中~。选中标记:之后{
显示:块;
}
.包含。选中标记:在{
顶部:9px;
左:9px;
宽度:8px;
/* Customize the label (the container) */
.contain {
display: block;
position: relative;
padding-left: 35px;
margin-bottom: 12px;
cursor: pointer;
font-size: 22px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
/* Hide the browser's default radio button */
.contain input {
/*position: absolute;*/
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}
/* Create a custom radio button */
.checkmark {
position: absolute;
top: 0;
left: 0;
height: 25px;
width: 25px;
background-color: #eee;
border-radius: 50%;
}
/* On mouse-over, add a grey background color */
.contain:hover input ~ .checkmark {
background-color: #ccc;
}
/* When the radio button is checked, add a blue background */
.contain input:checked ~ .checkmark {
background-color: #2196F3;
}
/* Create the indicator (the dot/circle - hidden when not checked) */
.checkmark:after {
content: "";
position: absolute;
display: none;
}
/* Show the indicator (dot/circle) when checked */
.contain input:checked ~ .checkmark:after {
display: block;
}
/* Style the indicator (dot/circle) */
.contain .checkmark:after {
top: 9px;
left: 9px;
width: 8px;
height: 8px;
border-radius: 50%;
background: white;
}
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style type="text/css">
.contain {
display: inline-block;
position: relative;
padding-left: 35px;
margin-bottom: 12px;
cursor: pointer;
font-size: 22px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.contain input {
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}
.checkmark {
position: absolute;
top: 0;
left: 0;
height: 25px;
width: 25px;
background-color: blue;
border-radius: 50%;
}
.checkmark.one {
position: absolute;
top: 0;
left: 0;
height: 25px;
width: 25px;
background-color: green;
border-radius: 50%;
}
.checkmark.two {
position: absolute;
top: 0;
left: 0;
height: 25px;
width: 25px;
background-color: red;
border-radius: 50%;
}
.contain:hover input ~ .checkmark {
background-color: blue;
}
.contain:hover input ~ .checkmark.one {
background-color: green;
}
.contain:hover input ~ .checkmark.two {
background-color: red;
}
.contain input:checked ~ .checkmark {
background-color: blue;
}
.contain input:checked ~ .checkmark.one {
background-color: green;
}
.contain input:checked ~ .checkmark.two {
background-color: red;
}
.checkmark:after {
content: "";
position: absolute;
display: none;
}
.contain input:checked ~ .checkmark:after {
display: block;
}
.contain .checkmark:after {
top: 9px;
left: 9px;
width: 8px;
height: 8px;
border-radius: 50%;
background: white;
}
</style>
</head>
<body>
<div class="card-body">
<span style="color: #707070; font-size: 18px;"><h5><b>Color</b></h5></span>
<form>
<label class="radio-inline contain">
<input type="radio" name="optradio" >
<span class="checkmark"></span>
</label>
<label class="radio-inline contain">
<input type="radio" name="optradio">
<span class="checkmark one"></span>
</label>
<label class="radio-inline contain">
<input type="radio" name="optradio">
<span class="checkmark two"></span>
</label>
</form>
</div>
</body>
</html>