我在屏幕中间放置了3个divs,每个divs都有一个fontawesome的图标,但有些图标像骰子和代码有点偏移,除了微笑.(我假设这是因为微笑是圆形的就像div,但我不确定)我想知道我如何才能使所有的图标集中在他们自己的div.整个代码的Codepen:Smooth Buttons with Fontawesome Icons

下面是HTML和CSS代码:

body {
  background-color: #333;
  font-size: 1.5em;
  padding: 0;
}

.buttons {
  display: flex;
  gap: 25px;
  justify-content: center;
  align-items: center;
  text-align: center;
  line-height: 50px;
  vertical-align: bottom;
  float: center;
}

.button {
  padding 5px;
  color: black;
  height: 50px;
  width: 50px;
  border: 15px solid #2b2b2b;
  background-color: #2b2b2b;
  border-radius: 100%;
  transition: all ease-in-out 0.5s;
}
<div class="buttons">
  <div class="button"><i class="fa fa-dice fa-2xl"></i></div>
  <div class="button"><i class="fa fa-code fa-2xl"></i></div>
  <div class="button"><i class="fa fa-smile fa-2xl"></i></div>
</div>

我已经试过改变边缘,显示类型和文本对齐,但没有任何效果.

推荐答案

您可以为固定宽度的图标添加类fa-fw.第二,你的字体太大了,所以它偏离了中心.我把尺寸设置为20px,现在看起来很居中.

body {
  background-color: #333;
  font-size: 1.5em;
  padding: 0;
}

.buttons {
  display: flex;
  gap: 25px;
  justify-content: center;
  align-items: center;
  text-align: center;
  line-height: 50px;
  vertical-align: bottom;
  float: center;
}

.button {
  padding 5px;
  font-size: 20px;
  color: black;
  height: 50px;
  width: 50px;
  border: 15px solid #2b2b2b;
  background-color: #2b2b2b;
  border-radius: 100%;
  transition: all ease-in-out 0.5s;
}

.button:hover {
  transform: scale(1.1) rotate(360deg);
  box-shadow: 0 0 15px #111;
  cursor: pointer
}

.button:active {
  animation: clicked ease 0.25s
}

@keyframes clicked {
  from {
    background-color: #2b2b2b;
    border: 15px solid #2b2b2b;
    scale: 1;
  }
  to {
    background-color: #333;
    border: 15px solid #333;
    scale: 1.05;
  }
}
<div class="buttons">
  <div class="button"><i class="fa fa-fw fa-dice fa-2xl"></i></div>
  <div class="button"><i class="fa fa-fw fa-code fa-2xl"></i></div>
  <div class="button"><i class="fa fa-fw fa-smile fa-2xl"></i></div>
</div>

<script src="https://kit.fontawesome.com/4fc295af45.js" crossorigin="anonymous"></script>

Html相关问答推荐

html中背景色的全单元格R中的Rmarkdown表

Flexbox嵌套div溢出

需要帮助实现悬停动画效果

带有多种 colored颜色 的HTML按钮

如何在伪元素背景中定位多个CSS径向梯度

在NzMessageService中传递动态TemplateRef- Angular 15

如果浏览器通过http接收html,为什么客户端内置表单验证不起作用?

Chatbox底部显示新消息,并向上推送旧消息

div居中碰撞问题

如果您将带有 html 标签的字符串数据(name : test) 放在 `

用于表行组标题的正确 HTML 标记是什么?

屏幕缩小时背景图像裁剪高度

调整窗口大小时文本重叠导航栏

两个span,一个在div居中,好像没有另一个,另一个在右边

获取 div 中每个元素的 href 并使用它

使用 rgba() 的 css 中的边框不透明度不起作用

在 React (NEXT) 中,当我try 进行动态补充时,我无法使用实例this来引用输入

为什么 `html` 上的 overflow: hidden 将滚动框移动到正文?

正确使用视频作为背景

使用 htmloutput 在shiny 的应用程序中呈现文本