Date: 2024.03.27
效果
HTML
img{ border: none; height: 250px; width: 250px; border-radius: 2% }
.pubCon{ width: 1000px; margin: auto } /* exp1: if you donot need, ignnore */
.conBox{ display: flex; justify-content: space-around } /* exp2: if you have more images */
.imgBox{ height: 250px; width: 250px } /* exp3: fit flex */
.imgBox img{ position: absolute } /* exp4: about position */
.imgBox .img1{ background: linear-gradient(-45deg, #a8cecf, #cee4da) } /* exp5: gave images a color, if you have src value, ignore */
.imgBox .img2{ background: linear-gradient(45deg, #c6ffdd, #f7797d) } /* exp5: gave images other color, if you have src value, ignore */
.imgBox img:first-child{ animation: am 20s ease-in-out infinite; z-index: 1 } /* exp6: about 'z-index' */
@keyframes am {
0%, 40% { opacity: 1 }
50%, 90% { opacity: 0 }
}
flex
和 justify-content
时,你需要子元素有宽度,以控制它的位置。参考 MDN-flexible 和 参考 MDN-justify-contentposition
: 让表层与里层进行切换展示,需要图片重叠,你需要将图像 img
设置为绝对位置参考 MDN-position。src
可以不用设置背景,这里只是由于替代 img
内容。opacity
属性控制了第一个 img
元素透明,将改变其层叠上下文参考 MDN-opacity,需要将其优先设置在上层,使得其 opacity
恢复后能再显示在上层,覆盖掉第二章图。
img{ border: none; height: 250px; width: 250px; border-radius: 2% }
.pubCon{ width: 1000px; margin: auto } /* exp1: if you donot need, ignnore */
.conBox{ display: flex; justify-content: space-around } /* exp2: if you have more images */
.outBox{ width: 250px; height: 250px; border-radius: 2%; overflow: hidden } /* exp3: control the width height */
.imgBox{ width: 500px; display: flex } /* exp4: make imgs inline */
/* .imgBox{ float:left; display: flex } /* exp4: other way */
.imgBox .img1{ background: linear-gradient(-45deg, #a8cecf, #cee4da) } /* exp5: gave images a color, if you have src value, ignore */
.imgBox .img2{ background: linear-gradient(45deg, #c6ffdd, #f7797d) } /* exp5: gave images other color, if you have src value, ignore */
.imgBox{ animation: am 10s ease-in-out infinite }
@keyframes am {
0%, 40% { margin-left: 0 }
50%, 90% { margin-left: -250px }
}
float
对整个盒子中内容的影响,你可以参考参考 MDN-float(当然,为什么不删除 float
呢?只有 flex
可不能让你的图像显示正常,参考参考 MDN-flexible)。src
可以不用设置背景,这里只是由于替代 img
内容。参与评论
手机查看
返回顶部