首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >图像对齐方式未正确设置为右上角

图像对齐方式未正确设置为右上角
EN

Stack Overflow用户
提问于 2020-09-10 03:28:29
回答 1查看 238关注 0票数 0

我正在尝试在卡片的右上角设置icon,但我无法将所有内容都对齐。

它应该看起来像这样:

但看起来是这样的:

代码语言:javascript
复制
<Card style={{ width: '16rem', border: 'none', margin: '10px', borderRadius: '20px'}}>
                        <div>
                            <Card.Img variant="top" src={Dj} className="img-card img-card-small" />
                            <div className="blue-circle-icon">
                                <img src={LiveIcon}
                                    alt="live-icon"
                                    className="icon-tag"/>
                            </div>
                        </div>
                        <Card.Body style={{borderRadius: '20px'}}>
                            <Card.Text style={{fontFamily: 'SourceSansPro', 
                                    fontSize: '14px', 
                                    fontWeight: 'normal',
                                    fontStretch: 'normal',
                                    fontStyle: 'normal',
                                    lineHeight: '1.6',
                                    letterSpacing: 'normal',
                                    textAlign: 'center',
                                    color: '#616161'}}>
                            Anyone can apply to earn money by hosting a live-streaming or in-person experience                            
                            </Card.Text>
                        </Card.Body>
                    </Card>

css是:

代码语言:javascript
复制
.img-card {
    object-fit: contain;
    border-radius: 20px;

}

.blue-circle-icon {
    background-color: #14cff0;
    width: 40px;
    height: 40px;
    border-radius: 100px;
    margin-left: auto;
    margin-right: 0px;
    margin-top: 0px;
    margin-bottom: auto;
}

.icon-tag {
    height: 20px;
    width: auto;

}

因此,如果有人知道如何确保white icon始终在blue circle中居中,如何使blue circle始终位于图像的右上角……我将很高兴有一些输入。

此外,我试图在图像周围应用一个边界半径,但我做不到,这很奇怪。它只在底部这样做

谢谢

EN

回答 1

Stack Overflow用户

发布于 2020-09-10 03:41:37

  1. 白色图标始终以蓝色圆圈为中心:

position: relative;添加到.blue-circle-icon类,并将以下css添加到.icon-tag

代码语言:javascript
复制
.icon-tag {
  position: absolute;
  top: 50%;
  right: 50%;
  transform: translate(-50%, -50%);
}

  1. 以同样的方式获得始终位于图像右上角的蓝色圆圈:

position: relative;添加到.blue-circle-icon.img-card的父div中,并将以下css添加到.blue-circle-icon

代码语言:javascript
复制
.blue-circle-icon {
  position: absolute;
  top: -20px;    <= adjust these as per your need
  right: -20px;  <= adjust these as per your need
}

但在这里,图标将相对于父div定位,如果可以将.blue-circle-icon放在.img-card内作为子代,则将position: relative;提供给.img-card,以确保图标始终相对于卡片定位。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63818342

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档