如何在Ionic 2中添加带图像名称的图像

时间:2018-04-05 06:29:35

标签: css angular ionic-framework sass ionic2

我想在用户Image的中心显示用户名称的用户图像, 所以我如何通过响应来实现这一目标。 enter image description here

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:0)

您可以尝试使用Ionic提供的现有CSS类文本中心https://ionicframework.com/docs/theming/css-utilities/

答案 1 :(得分:0)

以下是图像上定位文字的示例: HTML:

<div class="container">
  <img src="img_fjords_wide.jpg" alt="Norway" style="width:100%;">
  <div class="bottom-left">Bottom Left</div>
  <div class="top-left">Top Left</div>
  <div class="top-right">Top Right</div>
  <div class="bottom-right">Bottom Right</div>
  <div class="centered">Centered</div>
</div>

AND CSS:

/* Container holding the image and the text */
.container {
    position: relative;
    text-align: center;
    color: white;
}

/* Bottom left text */
.bottom-left {
    position: absolute;
    bottom: 8px;
    left: 16px;
}

/* Top left text */
.top-left {
    position: absolute;
    top: 8px;
    left: 16px;
}

/* Top right text */
.top-right {
    position: absolute;
    top: 8px;
    right: 16px;
}

/* Bottom right text */
.bottom-right {
    position: absolute;
    bottom: 8px;
    right: 16px;
}

/* Centered text */
.centered {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}