水平居中 Bootstrap 个图标
Centering Bootstrap Icons Horizontally
我无法将 Bootstrap 按钮中的图标居中。如您所见,图标没有水平居中。我无法让它工作(我已经尝试过文本对齐、带有 justify-content 的 flexbox,...),因为显然“字母”本身在右侧占用了一些额外的 space - 在至少在我看来是这样的。有人可以帮助我吗?
body {
display: flex;
justify-content: center;
align-items: center;
}
button {
padding: 4px;
font-size: 24px;
text-align: center;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.6.1/font/bootstrap-icons.css">
</head>
<body>
<button>
<i class="bi-play"></i>
</button>
</body>
*{
padding:0;
margin:0;
}
button {
display: flex;
justify-content: center;
align-items: center;
height: 30px;
width: 60px;
font-size: 30px;
border-radius: 5px;
background-color: red;
}
.bi-play{
color: white;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.6.1/font/bootstrap-icons.css">
</head>
<body>
<button>
<i class="bi-play my4"></i>
</button>
</body>
现在检查它是否解决了您的问题。我认为它现在居中了。
这与文本没有任何关系,因为您要居中的是 i 元素。因此需要显示为flex并设置居中的按钮。
body {
display: flex;
justify-content: center;
align-items: center;
}
button {
display: flex;
justify-content: center;
align-items: center;
padding: 4px;
font-size: 24px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.6.1/font/bootstrap-icons.css">
</head>
<body>
<button>
<i class="bi-play"></i>
</button>
</body>
我无法将 Bootstrap 按钮中的图标居中。如您所见,图标没有水平居中。我无法让它工作(我已经尝试过文本对齐、带有 justify-content 的 flexbox,...),因为显然“字母”本身在右侧占用了一些额外的 space - 在至少在我看来是这样的。有人可以帮助我吗?
body {
display: flex;
justify-content: center;
align-items: center;
}
button {
padding: 4px;
font-size: 24px;
text-align: center;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.6.1/font/bootstrap-icons.css">
</head>
<body>
<button>
<i class="bi-play"></i>
</button>
</body>
*{
padding:0;
margin:0;
}
button {
display: flex;
justify-content: center;
align-items: center;
height: 30px;
width: 60px;
font-size: 30px;
border-radius: 5px;
background-color: red;
}
.bi-play{
color: white;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.6.1/font/bootstrap-icons.css">
</head>
<body>
<button>
<i class="bi-play my4"></i>
</button>
</body>
现在检查它是否解决了您的问题。我认为它现在居中了。
这与文本没有任何关系,因为您要居中的是 i 元素。因此需要显示为flex并设置居中的按钮。
body {
display: flex;
justify-content: center;
align-items: center;
}
button {
display: flex;
justify-content: center;
align-items: center;
padding: 4px;
font-size: 24px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.6.1/font/bootstrap-icons.css">
</head>
<body>
<button>
<i class="bi-play"></i>
</button>
</body>