Html 当屏幕尺寸减小时,如何保持播放按钮图标位于图像中心?
以下是问题的屏幕截图: 我使用本教程中的说明学习如何在动画GIF上放置播放按钮: 在大多数情况下,这是可行的,但当屏幕变为移动时,我很难让播放按钮保持居中 我正在使用这个主题(雨果): 我猜我需要在一张桌子或其他东西中包含图像和播放按钮图标?本教程的示例中的图像包含在一个DIV中,但当我尝试这样做时,我丢失了“播放”按钮:Html 当屏幕尺寸减小时,如何保持播放按钮图标位于图像中心?,html,css,Html,Css,以下是问题的屏幕截图: 我使用本教程中的说明学习如何在动画GIF上放置播放按钮: 在大多数情况下,这是可行的,但当屏幕变为移动时,我很难让播放按钮保持居中 我正在使用这个主题(雨果): 我猜我需要在一张桌子或其他东西中包含图像和播放按钮图标?本教程的示例中的图像包含在一个DIV中,但当我尝试这样做时,我丢失了“播放”按钮: <div class="demo-content"> <figure> <img src="/images/image-placeholder
<div class="demo-content">
<figure>
<img src="/images/image-placeholder.jpg" alt="Static Image" data-alt="/images/animated-gif.gif">
</figure>
</div>
如何使我的“播放”按钮保持与教程示例中相同的居中状态?将
图:before
更改为顶部:50%
以使其与顶部保持50%的距离,然后删除左侧的边距
并改用变换:translate(-50%,-50%)
,这将使元素向左移动,并向上移动其自身宽度/高度的50%<代码>左边距:-50px与示例中的translateX(-50%)
相同,但使用transform:translate()
更简单
figure:before {
top: 50%;
left: 50%;
/* margin-left: -50px; */
width: 100px;
height: 100px;
border: 3px solid rgba(255, 255, 255, 0.7);
border-radius: 50px;
background-color: rgba(204, 209, 217, 0.3);
font-family: 'font-awesome';
content: '\f04b';
text-align: center;
line-height: 95px;
font-size: 30px;
color: #182230;
transform: translate(-50%,-50%);
}
一个更一般的问题可能是:“如何以CSS为中心?”
.
.
.
@font-face {
font-family: 'font-awesome';
font-style: normal;
font-weight: 700;
src: url(https://cdnjs.cloudflare.com/ajax/libs/fontawesome/4.7.0/fonts/fontawesome-webfont.ttf) format("truetype")
}
.
.
.
figure {
width: 100%;
margin: 0;
float: left;
padding: 10px;
position: relative;
cursor: pointer;
}
figure:before,
figure:after {
position: absolute;
}
figure:before {
top: 206px;
left: 50%;
margin-left: -50px;
width: 100px;
height: 100px;
border: 3px solid rgba(255, 255, 255, 0.7);
border-radius: 50px;
background-color: rgba(204, 209, 217, 0.3);
font-family: 'font-awesome';
content: '\f04b';
text-align: center;
line-height: 95px;
font-size: 30px;
color: #182230;
}
figure:after {
position: absolute;
display: inline-block;
width: auto;
text-align: center;
top: 20px;
right: 20px;
font-size: 11px;
font-weight: 600;
padding: 5px;
border-radius: 3px;
color: #656D78;
background-color: rgba(170, 178, 189, 0.1);
text-transform: uppercase;
}
figure.play:before {
display: none;
}
figure.play:after {
content: 'playing';
color: #fff;
background-color: #212121;
text-transform: uppercase;
}
figcaption {
padding-top: 15px;
font-size: 14px;
text-align: center;
color: #8d9bad;
}
figcaption a {
color: #59687b;
text-decoration: none;
}
figure:before {
top: 50%;
left: 50%;
/* margin-left: -50px; */
width: 100px;
height: 100px;
border: 3px solid rgba(255, 255, 255, 0.7);
border-radius: 50px;
background-color: rgba(204, 209, 217, 0.3);
font-family: 'font-awesome';
content: '\f04b';
text-align: center;
line-height: 95px;
font-size: 30px;
color: #182230;
transform: translate(-50%,-50%);
}