html - CSS图像卡在角落
问题描述
在这张照片中,我使用 CSS 添加了一个 div箭头,然后将它变成了一个箭头。在 div/箭头的中心,我需要放置一个图像。
网格内的此图标不会将位置更改为中心,而不会干扰使用网格创建的箭头的 css。
.arrow {
position: relative;
text-indent: 30px;
text-align: center;
background-color: #E6EAEF;
display: inline-block;
zoom: 1;
*display: inline;
font-size: 1rem;
text-align: center;
padding: auto 0;
align-items: center;
height: 24px;
margin: 5px;
padding: 5px;
/* tweaked this */
font-size: 1rem;
line-height: 50px;
box-shadow: 0 8px 6px -6px black;
}
.arrow:after {
content: "";
position: absolute;
width: 0;
height: 0;
left: 0;
border-top: 17px solid transparent;
border-left: 12px solid #E6EAEF;
border-bottom: 17px solid transparent;
margin: -5px 10px 0 5px;
}
.arrow:before {
content: "";
position: absolute;
width: 0;
height: 0;
left: 0;
border-top: 17px solid transparent;
border-left: 10px solid white;
border-bottom: 17px solid transparent;
margin: -5px 0 0 0;
}
.arrow-icon {
display: inline-block;
position: relative;
margin-top: 0px;
margin-left: 0px;
padding-left: 0px;
height: 15px !important;
}
<div class="arrow">
<img class="arrow-icon" src="https://www.freeiconspng.com/uploads/magnifying-glass-icon-13.png" alt="">
</div>
`
解决方案
如果图像没有动作目的,例如点击事件,并且仅用于显示目的,您可以将其放置在背景中。
.arrow {
position: relative;
text-indent: 30px;
text-align: center;
/* All background properties are combined in here. */
/* The CALC() is just to nudge it to the right so it looks better on the arrow. */
background: #E6EAEF url(https://www.freeiconspng.com/uploads/magnifying-glass-icon-13.png) calc(50% + 4px) 50% no-repeat;
background-size: 17px; /* Sets the icon size. */
display: inline-block;
zoom: 1;
*display: inline;
font-size: 1rem;
text-align: center;
padding: auto 0;
align-items: center;
height: 24px;
margin: 5px;
padding: 5px;
/* tweaked this */
font-size: 1rem;
line-height: 50px;
box-shadow: 0 8px 6px -6px black;
width: 50px;
}
.arrow::after {
content: "";
position: absolute;
width: 0;
height: 0;
right: -20px;
border-top: 17px solid transparent;
border-left: 12px solid #E6EAEF;
border-bottom: 17px solid transparent;
margin: -5px 10px 0 5px;
}
.arrow::before {
content: "";
position: absolute;
width: 0;
height: 0;
left: 0;
border-top: 17px solid transparent;
border-left: 10px solid white;
border-bottom: 17px solid transparent;
margin: -5px 0 0 0;
}
<div class="arrow">
</div>
推荐阅读
- javascript - 从数据表中获取最大值
- r - 如何重复一个函数n次?
- esxi - 当我关机时,esxi,esxi显示系统已经停止
- java - Java Eclipse 无法使用正则表达式进行拆分(找不到源)
- java - Java - “无法在索引 0 处解析文本‘10 月 11 日’”
- java - 如何不使用我给我的 servlet 提供的新名称来修复 Tomcat?
- node.js - Quasar Firestore 字段相等查询过滤器不起作用
- javascript - Babel 提案装饰器插件不起作用
- swift - 如何在存储为字符串的 coredata 中对工作日进行排序
- pyspark - 将类似字符串的 XML 转换为 PySpark 数据框