gpt4 book ai didi

html - 更改圆的背景图像

转载 作者:行者123 更新时间:2023-12-04 13:22:30 25 4
gpt4 key购买 nike

我正在尝试绘制一些以图像为背景的 CSS 生成的圆圈。在我当前的代码中,背景图像在 CSS 代码中设置为固定图像。

.container {
text-align: center;
}

.circle {
position: relative;
height: 180px;
width: 180px;
border-radius: 50%;
display: inline-flex;
vertical-align: top;
justify-content: center;
align-items: center;
overflow: hidden;
text-decoration: none;
border: 0;
margin: 10px;
}

.circle:after {
content: "";
position: absolute;
z-index: -1;
top: 0;
left: 0;
height: 100%;
width: 100%;
background: url("http://deepchains.com/images/team.png") center / cover no-repeat;
opacity: .25;
transition: .25s;
}

.circle:hover:after {
opacity: 1;
color: transparent;
}

.circle:hover {
color: transparent;
}

.ccont {
display: inline-block;
margin: 10px;
}

.ccont:hover {
color: transparent;
}
<div class="container">
<a class="circle" href="http://www.url1.html">
<div class="ccont" style="font-weight: bold; text-decoration:none !important;">This is <br>Text1</div>
</a>
<a class="circle" href="http://www.url2.html">
<div class="ccont" style="font-weight: bold; text-decoration:none !important;">This is <br>Text2</div>
</a>
</div>

这是我在 Chrome 浏览器中看到的示例结果:

enter image description here

我的问题是如何在HTML代码中分别改变每个圆圈的背景图片?我将有许多这样的圆圈,我希望它们对齐并在同一行中,我想在 HTML 代码中设置它们的背景图像并从 CSS 中删除背景图像。我该怎么做?

最佳答案

一个简单的解决方案是将伪元素转换为一个元素并使用背景图像作为内联样式,这样您就可以轻松地更改每个元素的图像并应用与伪元素相同的所有属性:

.container {
text-align: center;
}

.circle {
position: relative;
height: 180px;
width: 180px;
border-radius: 50%;
display: inline-flex;
vertical-align: top;
justify-content: center;
align-items: center;
overflow: hidden;
text-decoration: none;
border: 0;
margin: 10px;
}

.circle .image {
position: absolute;
z-index: -1;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-position:center;
background-size:cover;
background-repeat:no-repeat;
opacity: .25;
transition: .25s;
}

.circle:hover .image {
opacity: 1;
color: transparent;
}

.circle:hover .ccont{
color: transparent;
}

.ccont {
display: inline-block;
margin: 10px;
}
<div class="container">
<a class="circle" href="http://www.url1.html">
<span class="image" style="background-image: url(http://lorempixel.com/400/300/)"></span>
<div class="ccont" style="font-weight: bold; text-decoration:none !important;">This is <br>Text1</div>
</a>
<a class="circle" href="http://www.url2.html">
<span class="image" style="background-image:url(https://lorempixel.com/400/200/)"></span>
<div class="ccont" style="font-weight: bold; text-decoration:none !important;">This is <br>Text2</div>
</a>
</div>

关于html - 更改圆的背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48618005/

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