gpt4 book ai didi

html - 如何在html和css中点击切换图像

转载 作者:太空狗 更新时间:2023-10-29 15:55:20 25 4
gpt4 key购买 nike

我在单个页面中有 9 张图片,布局看起来像 9 张图片的网格。我有一个图像,当您单击图像时,我想将其用作每个图像的边框。它是一个带有边框的透明图像,就像确认图像的选择。

我怎样才能做到这一点?当我点击图片时,边框图片应该出现,当我点击图片时,边框图片应该消失。

有什么方法可以只使用 HTML 和 CSS 来实现吗

    .image1 {
left: 786 px;
top: 629 px;
position: absolute;
width: 441 px;
height: 243 px;
float: left;
}

.image2 {
left: 1284 px;
top: 629 px;
position: absolute;
width: 441 px;
height: 243 px;
float: left;
}

.image3 {
left: 289 px;
top: 920 px;
position: absolute;
width: 441 px;
height: 243 px;
float: left;
}
<html>

<body>
<div class="image1">
<img src="images/image1.png" />
</div>
<div class="image2">
<img src="images/image2.png" />

</div>

<div class="image3">
<img src="images/image3.png" />
</div>
</body>

</html>

最佳答案

尝试 css 伪代码。

使用复选框多选

input.switch-border {
display: none;
}
input.switch-border + label > img {
border: 2px solid transparent;
cursor: pointer;
}
input.switch-border:checked + label > img {
border-color: grey;
}
<input type='checkbox' class='switch-border' id='r1' />
<label for='r1'>
<img src='http://pix.iemoji.com/sbemojix2/0669.png' class='switch-border' />
</label>
<input type='checkbox' class='switch-border' id='r2' />
<label for='r2'>
<img src='http://pix.iemoji.com/sbemojix2/0669.png' class='switch-border' />
</label>

单选单选

input.switch-border {
display: none;
}
input.switch-border + label > img {
border: 2px solid transparent;
cursor: pointer;
}
input.switch-border:checked + label > img {
border-color: grey;
}
<input type='radio' class='switch-border' id='r1' name='switch' />
<label for='r1'>
<img src='http://pix.iemoji.com/sbemojix2/0669.png' class='switch-border' />
</label>
<input type='radio' class='switch-border' id='r2' name='switch' />
<label for='r2'>
<img src='http://pix.iemoji.com/sbemojix2/0669.png' class='switch-border' />
</label>

编辑

圆 Angular 、大小、位置和文字

input.switch-border {
display: none;
}
input.switch-border + label {
border: 2px solid transparent;
border-radius: 10px;
/* rounded corners */
-moz-border-radius: 10px;
/* FF */
-webkit-border-radius: 10px;
/* chrome */
cursor: pointer;
padding: 5px 7px;
}
input.switch-border + label > img {
width: 100px;
/* size */
height: 100px;
/* size */
}
input.switch-border:checked + label {
border-color: grey;
}
label[for=r2] {
float: right;
}
label[for=r1] {
float: left;
}
<input type='radio' class='switch-border' id='r1' name='switch' />
<label for='r1'>
<span>Image Desc</span>
<img src='http://pix.iemoji.com/sbemojix2/0669.png' class='switch-border' />
</label>
<input type='radio' class='switch-border' id='r2' name='switch' />
<label for='r2'>
<span>Image Desc</span>
<img src='http://pix.iemoji.com/sbemojix2/0669.png' class='switch-border' />
</label>

附言css 属性 border-radius 不适用于 IE < 9

关于html - 如何在html和css中点击切换图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30023239/

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