html - 在 CSS 形状的顶部居中图像?
问题描述
我正在尝试将图像居中放置在使用 CSS 制作的 Hexagon 上。
我目前拥有的代码是:
.img-social {
width: 25px;
height: 25px;
}
.hexagon {
position: relative;
width: 35px;
height: 20.21px;
background-color: #525555;
margin: 10.10px 0;
}
.hexagon:before,
.hexagon:after {
content: "";
position: absolute;
width: 0;
border-left: 17.5px solid transparent;
border-right: 17.5px solid transparent;
}
.hexagon:before {
bottom: 100%;
border-bottom: 10.10px solid #525555;
}
.hexagon:after {
top: 100%;
width: 0;
border-top: 10.10px solid #525555;
}
<li class="img-social-container">
<div class="hexagon"></div>
<a><img class="img-social" src="icons/logo-github.png" alt="github"></a>
</li>
我还希望图像位于六边形之上,这是我遇到的另一个问题。
解决方案
就动一下?我有点确定这不是最好的解决方案,但仍然如此。
.img-social {
width: 25px;
height: 25px;
position: relative;
bottom: 32.5px;
left: 5px;
margin: 0;
}
推荐阅读
- python - 使用 selenium:如何在使用 python 关闭驱动程序后保持登录状态
- json - 连接嵌套字段
- plsql - 从分号分隔的字符串中获取不同的电子邮件
- java - 将拥有自己数据库的我的模块集成到另一个应用程序中
- java - 从命令行设置弹簧属性文件位置
- c++ - 为什么这不会为链接器生成重复的符号?
- fortran - 是否有可以检查变量值的 Fortran IDE?
- agda - Agda 中集合和函数类别的简单编码
- java - 如何以编程方式设置内容类型?获取 org.jvnet.mimepull.MIMEParsingException:缺少开始边界
- javascript - 如何检测用户何时点击网页标签?