html - 无法制作具有边框半径的圆并将其与下一个元素垂直对齐

标签 html css flexbox

结果如下

enter image description here

我想要实现的是

  1. 一个灰色圆圈围绕着“<”,字母位于中心

  2. 它和“无标题”垂直居中对齐

然而,尽管将宽度和高度设置为相同的大小,“圆形”最终仍然是椭圆形。

使用flex的align-items: center;也无法实现对齐。

如何修复CSS?这是示例代码的链接

html

<div class='flex-container'>   
  <div class='arrow-container'>
      <a class='btn-icon' href='#'>
        <span class='square-btn icon icon-back'></span>
      </a>
  </div>
  <div class=title>
        <a href='#'>Untitled
        </a>
  </div>
</div>

CSS

.flex-container {
  display: flex;
  align-items: center;
}

.icon {
  font-size: 50px;
}

.icon-back::before {
  content: '<';
}

.title {
  margin-left: 5px;
  font-size: 50px;
}

.square-btn {
  height: 50px;
  width: 50px;  
}

.btn-icon {
  padding: 5px;
  border-radius: 50%;
  background-color: gray;
  text-decoration: none;
}

最佳答案

这似乎有效。 HTML 没有更改。

.flex-container {
    display: flex;
    align-items: center;
}

.icon {
    font-size: 50px;
}

.icon-back::before {
    content: '<';
}

.title {
    margin-left: 5px;
    font-size: 50px;
}

.square-btn {
    height: 50px;
    width: 50px;
    border-radius: 50%;                    /* new */
    background-color: gray;                /* new */
    display: flex;                         /* new */
    align-items: center;                   /* new; align arrow vertically */
    justify-content: center;               /* new; align arrow horizontally */
}

.btn-icon {
    /* padding: 5px;                        <-- remove */
    /* border-radius: 50%;                  <-- remove */
    /* background-color: gray;              <-- remove */
    text-decoration: none;
}
<div class='flex-container'>
    <div class='arrow-container'>
        <a class='btn-icon' href='#'>
            <span class='square-btn icon icon-back'></span>
        </a>
    </div>
    <div class=title>
        <a href='#'>Untitled
        </a>
    </div>
</div>

jsFiddle

关于html - 无法制作具有边框半径的圆并将其与下一个元素垂直对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36925441/

相关文章:

html - 我想使用 CSS 将滚动限制添加到固定页脚

html - 在元素之间划分线,但第一项向左对齐

css - Flexbox 在 Firefox 的按钮中不起作用

html - 响应式导航栏,带有下拉表和 div 之间的 Logo

html - 允许 HTML 内容缩放,这样内容就不会聚集在一起

css - 动态生成 Html 图形

php - 将 CSS 样式应用于 PHP 输出

html - 在这种情况下如何解决网格布局问题?

php - 如何使用 localhost 托管我的 HTML 和 CSS 网站

html - HTML 内联中的 CSS 动画