gpt4 book ai didi

html - 为什么选中复选框时相邻的复选框会移动?

转载 作者:太空宇宙 更新时间:2023-11-03 22:12:03 26 4
gpt4 key购买 nike

我正在使用 background-image:url 导入一个复选框,然后当单击该复选框时,相邻的复选框向右移动,如何防止这种移动?我希望复选框固定到位。提供的图像链接只是一个示例。我试图在框中弹出一个复选标记。这是片段:https://jsfiddle.net/0py4enwb/

<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="Interaktywny poradnik szybkiego startu dla Brackets.">
<link rel="stylesheet" href="test.css">

</head>

<body>


<div class="checkbox" style="background-color:white">
<form>
<label class="checkboxlabel" >
<input class="checkboxparameter" type="checkbox" id="capacity"><span class="inputcheckbox"><span class="inputcheckboxcheckmark"></span></span></input>
</label>
<label class="checkboxlabel">
<input class="checkboxparameter" type="checkbox" id="production"><span class="inputcheckbox"><span class="inputcheckboxcheckmark"></span></span></input>
</label>
</form>
</div>


</body>

<script>
</script>

</html>

*{
box-sizing: border-box;
}

body{
margin:0;
width:100vw;
height:100vh;
}

.checkbox{
width:100%;
height:100%;
}

.inputcheckbox::before{
background-image:url("/checkbox_notchecked_2.svg");
background-size: 100% 100%;
display: inline-block;
background-repeat: no-repeat;
height:75px;
width:75px;
content:"";
}




.inputcheckbox::before{
background-image:url("https://img.icons8.com/office/16/000000/add-image.png");
display: inline-block;
background-size: 100% 100%;
background-repeat: no-repeat;
height: 75px;
width:75px;
content:"";
}

.checkboxlabel:nth-child(1) input[type=checkbox]:checked + .inputcheckbox > .inputcheckboxcheckmark{
background-image:url("https://img.icons8.com/material-outlined/24/000000/add-image.png");
background-size: 100% 100%;
display: inline-block;
background-repeat: no-repeat;
height:75px;
width:75px;
content:"";
position:relative;
left:-75px;
animation-name:animationcheckbox;
animation-duration:0.5s;
}

.checkboxlabel:nth-child(2) input[type=checkbox]:checked + .inputcheckbox > .inputcheckboxcheckmark{
background-image:url("https://img.icons8.com/material-outlined/24/000000/add-image.png");
background-size: 100% 100%;
display: inline-block;
background-repeat: no-repeat;
height:75px;
width:75px;
content:"";
position:relative;
left:-75px;
animation-name:animationcheckbox;
animation-duration:0.5s;
}

@keyframes animationcheckbox{
from{
transform:scale(0)
}
to{
transform:scale(1)
}
}

.checkboxparameter{
display:none;
}


.checkboxlabel{
cursor:pointer;
}

```

最佳答案

添加此代码.. 因为在检查图像后不在适当的位置。现在添加绝对位置。它工作正常

CSS

*{
box-sizing: border-box;
}

body{
margin:0;
width:100vw;
height:100vh;
}

.checkbox{
width:100%;
height:100%;
}

.inputcheckbox::before{
background-image:url("/checkbox_notchecked_2.svg");
background-size: 100% 100%;
display: inline-block;
background-repeat: no-repeat;
height:75px;
width:75px;
content:"";
}




.inputcheckbox::before{
background-image:url("https://img.icons8.com/office/16/000000/add-image.png");
display: inline-block;
background-size: 100% 100%;
background-repeat: no-repeat;
height: 75px;
width:75px;
content:"";
}

.checkboxlabel:nth-child(1) input[type=checkbox]:checked + .inputcheckbox > .inputcheckboxcheckmark{
background-image:url("https://img.icons8.com/material-outlined/24/000000/add-image.png");
background-size: 100% 100%;
display: inline-block;
background-repeat: no-repeat;
height:75px;
width:75px;
content:"";
position:absolute;
left:0px;
animation-name:animationcheckbox;
animation-duration:0.5s;
}

.checkboxlabel:nth-child(2) input[type=checkbox]:checked + .inputcheckbox > .inputcheckboxcheckmark{
background-image:url("https://img.icons8.com/material-outlined/24/000000/add-image.png");
background-size: 100% 100%;
display: inline-block;
background-repeat: no-repeat;
height:75px;
width:75px;
content:"";
position:absolute;
left:0px;
animation-name:animationcheckbox;
animation-duration:0.5s;
}
.inputcheckbox{
position:relative;
}
@keyframes animationcheckbox{
from{
transform:scale(0)
}
to{
transform:scale(1)
}
}

.checkboxparameter{
display:none;
}


.checkboxlabel{
cursor:pointer;
}

```

关于html - 为什么选中复选框时相邻的复选框会移动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58876698/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com