Html 如何创建带中心图像/文本的圆div
我正在尝试创建一个响应性强的圆圈,适合每种屏幕大小,如下所示:Html 如何创建带中心图像/文本的圆div,html,css,responsive-design,css-shapes,Html,Css,Responsive Design,Css Shapes,我正在尝试创建一个响应性强的圆圈,适合每种屏幕大小,如下所示: <div class="container"> <div class="circle"> <img class="image" src="http://lorempixel.com/800/800/"> </div> </div> .container { width: 100%;
<div class="container">
<div class="circle">
<img class="image" src="http://lorempixel.com/800/800/">
</div>
</div>
.container {
width: 100%;
background: #000;
}
.circle {
border-radius: 50%;
width: 100%;
padding-bottom: 100%;
background: #fff;
position:relative;
overflow:hidden;
z-index:2;
}
.image {
z-index:1;
position:absolute;
top:0;
left:0;
width:auto;
max-width:100%;
height:auto;
max-height:100%;
}
我尝试了来自的一些代码,但任何人都无法按照要求正常工作。尝试以下操作:
<div class="container">
<div class="circle">
<img class="image" src="http://lorempixel.com/800/800/">
</div>
</div>
.container {
width: 100%;
background: #000;
}
.circle {
border-radius: 50%;
width: 100%;
padding-bottom: 100%;
background: #fff;
position:relative;
overflow:hidden;
z-index:2;
}
.image {
z-index:1;
position:absolute;
top:0;
left:0;
width:auto;
max-width:100%;
height:auto;
max-height:100%;
}
.集装箱{
宽度:100%;
背景:#000;
}
.圆圈{
边界半径:50%;
宽度:100%;
垫底:100%;
背景:#fff;
位置:相对位置;
溢出:隐藏;
z指数:2;
}
.形象{
z指数:1;
位置:绝对位置;
排名:0;
左:0;
宽度:自动;
最大宽度:100%;
高度:自动;
最大高度:100%;
}
圆圈应该适合容器
参见小提琴上的:
然后,您可以在此内部为文本/图像创建一个div,并将图像的最大宽度设置为100%和自动宽度。这将确保它不会比圆大。如果您想使图像扩展到边缘,将图像定位为绝对位置也有助于将其保持在圆内 您应该使用SVG或2x res PNG来实现。bandwith的大小大致相同,但您将获得更好的控制和更快的渲染。您当前的代码是什么?你有JSFIDDLE吗?请你努力一点好吗?你尝试过什么,你的主要问题在哪里?