gpt4 book ai didi

html - 垂直居中 Font Awesome 图标

转载 作者:行者123 更新时间:2023-11-28 02:11:35 25 4
gpt4 key购买 nike

我正在尝试创建一个可重复使用的框,其中包含一个删除和编辑按钮作为框的一部分。但是,无论我尝试什么,我都无法使图标水平居中。

.inputBox .content {
flex: 2;
}

.inputBox .icon {
flex: 1;
max-width: 50px;
}
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<div>
<div class="inputBox d-flex">
<div class="bg-dark text-white rounded-left p-2 content align-middle">
<input name="text" placeholder="This is a test" />
<span>Link text</span>
<br /> test<br />
</div>
<a href="#" class="bg-info text-white p-2 icon">
<i class="fa fa-edit fa-lg"></i>
</a>
<a href="#" class="bg-danger text-white p-2 icon rounded-right">
<span>
<i class="fa fa-trash fa-lg"></i>
</span>
</a>
</div>
</div>

最佳答案

应用 display:flex , align-items:center , justify-content:center.icon 类...

...或使用 d-flex align-items-center justify-content-center.icon 中引导预定义类

堆栈片段

.inputBox .content {
flex: 2;
}

.inputBox .icon {
flex: 1;
max-width: 50px;
display: flex;
align-items: center;
justify-content: center;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<div>
<div class="inputBox d-flex">
<div class="bg-dark text-white rounded-left p-2 content align-middle">
<input name="text" placeholder="This is a test" />
<span>Link text</span>
<br /> test<br />
</div>
<a href="#" class="bg-info text-white p-2 icon">
<i class="fa fa-edit fa-lg"></i>
</a>
<a href="#" class="bg-danger text-white p-2 icon rounded-right">
<span>
<i class="fa fa-trash fa-lg"></i>
</span>
</a>
</div>
</div>

关于html - 垂直居中 Font Awesome 图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48717657/

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