【发布时间】:2022-02-04 19:49:42
【问题描述】:
在我的 div 中将元素居中时遇到问题。
我正在使用 display flex、align-self 和 justify-self 使其居中。
我认为这样可以,但是当我从网络浏览器检查时,我有一个未知元素。
你可以在右边看到,有一个我不知道它来自哪里的条纹元素。
这里是使用网格制作的父元素。
您可以从这里的小提琴中看到问题
https://jsfiddle.net/Martin40/qtjphvga/3/
这是我的 CSS
.customer_card{
background: green;
padding: 10px;
margin-bottom: 20px;
border-radius: 10px;
display: grid;
grid-template-columns: 20% 80%;
gap: 0px 10px;
justify-content: center;
justify-items: stretch;
align-items: center;
}
.customer_card_logo {
display: flex;
position: relative;
justify-self: center;
text-align: center;
background: grey;
border-radius: 50%;
width: 50px;
height: 50px;
color: white;
font-weight: bold;
cursor: pointer;
}
.customer_card_logo > .material-icons-outlined {
align-self: center;
justify-self: center;
font-size: 2rem;
transition: all 0.4s;
}
.customer_card_logo:hover > .material-icons-outlined {
transform: rotate(90deg);
}
.customer_card_name {
display: block;
font-weight: 600;
font-size: 1.5rem;
}
.customer_card_addresse {
font-size: 1.2rem;
}
这是我的 HTML
<head><link href="https://fonts.googleapis.com/css?family=Material+Icons|Material+Icons+Outlined|Material+Icons+Two+Tone|Material+Icons+Round|Material+Icons+Sharp" rel="stylesheet"></head>
<div class="customer_card">
<div class="customer_card_logo"><span class="material-icons-outlined"> autorenew </span></div>
<div class="customer_card_informations">
<span class="customer_card_name">Company Name</span>
<span class="customer_card_addresse">Adresse <br> ZIP CITY NAME</span>
</div>
有谁知道问题出在哪里? 谢谢!
【问题讨论】:
-
问题?什么问题?您在父级中定义了
gap。 -
这不是一个元素,它是浏览器突出显示的间隙/空间
-
不清楚您的问题是什么-如果是徽标圈中的间隙-那是因为您的圈子是50px,而您的图标是32px-如果要使图标居中,只需添加
align-items:center; justify-content:center;到你的标志
标签: css flexbox center display