gpt4 book ai didi

css - 图像顶部的中心 ionic 图标

转载 作者:行者123 更新时间:2023-12-02 17:31:47 25 4
gpt4 key购买 nike

看完Center a Font Awesome icon over the image on hover它是相应的答案,我仍然无法用 ionic 图标复制这个答案。

我使用的代码如下:

<div class="video-thumbnail">
<img src="image here" />
<i class="icon ion-play"></i>
</div>

我使用的 CSS 是:

.video-thumbnail {
position: relative;
margin: 0 auto;
display: inline-block;
}

.video-thumbnail img {
position: absolute;
}

.video-thumbnail i {
position: absolute;
top: 50%;
transform: translateY(-50%);
}

我已经把它放在彼此之上,但似乎找不到中间点。水平和垂直居中。我不是在寻找任何悬停状态,只是在图像上寻找明显的图标。

谢谢!

最佳答案

对于水平和垂直居中,

  1. 您需要删除图像的 position: absolute,因为它需要它脱离了流程。
  2. 使用 calc() 计算顶部和左侧的值,您需要从 50% 中减去图标的尺寸值。

angular.module('app', ['ionic']);
.video-thumbnail {
position: relative;
display: inline-block;
}
.video-thumbnail img {
width: 100px;
height: 100px;
}
.video-thumbnail i {
position: absolute;
top: calc(50% - 10px);
left: calc(50% - 5px);
}
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<link href="http://code.ionicframework.com/1.0.0/css/ionic.min.css" rel="stylesheet">
<script src="http://code.ionicframework.com/1.0.0/js/ionic.bundle.js"></script>
</head>

<body ng-app="app">
<ion-pane>
<ion-header-bar class="bar-stable">
<h1 class="title">Awesome App</h1>
</ion-header-bar>
<ion-content class="padding">
<div class="video-thumbnail">
<img src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcT2KjQI_sGhxCm5CTyQPuCACLuLEyvup4eDNVowMzdHiiPLShdL3ggiA7QC" />
<i class="icon ion-play"></i>
</div>
</ion-content>

</ion-pane>
</body>

关于css - 图像顶部的中心 ionic 图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32257288/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com