css - 无法对齐 "a"标记

标签 css

我想知道为什么我不能将我的 .workButton 移到中心 :D?我试过 text-align 或 margin:0 auto,但似乎没有任何效果......

如果您发现一些错误/或可以采取不同的做法,请告诉我!

任何提示都会非常有帮助!

这是代码的链接(我用scss写的)

* {
  margin: 0;
  padding: 0; //  box-sizing: border-box;
}

body {
  font-family: "Titillium Web", sans-serif;
}

.container {
  max-width: 1140px;
  width: 100vw;
  height: 100vh;
  margin: 0 auto;
  overflow: hidden; //  grid-template-rows: 600px 750px 900px 650px 1420px 900px 820px 100px;
}

#hero {
  max-height: 600px;
  height: 100vh;
  background-color: #87509c;
  h1 {
    text-align: center;
    color: #f7f3ea;
    font-size: 42px;
    line-height: 50px;
    margin-top: 140px;
    margin-bottom: 60px;
  }
  .workButton {
    text-align: center;
    font-size: 18px;
    font-weight: 600;
    color: #ffffff;
    padding: 20px 80px;
    text-transform: uppercase;
    text-decoration: none;
    border: 1px solid #eb7d4b;
    border-radius: 5px;
    background-color: #eb7d4b;
    box-shadow: 0 2px #c86a40;
  }
}

.navbar {
  display: flex;
  margin: 60px 20px 20px 40px;
  ul {
    margin-left: auto;
    list-style-type: none;
    align-self: center;
    li {
      float: left;
      a {
        text-decoration: none;
        color: #ffffff;
        padding: 5px 20px;
        text-transform: uppercase;
        transition-duration: 1.5s;
      }
      a:hover {
        background-color: #643a79;
        border-radius: 3px;
        transition-duration: .4s;
      }
    }
  }
}

https://codepen.io/anon/pen/ZvXZLe

最佳答案

text-align: center 应用到您的 #hero 包装器,您的链接将很好地居中。

关于css - 无法对齐 "a"标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48116124/

相关文章:

javascript - jQuery – 将类添加到具有相同类的第二个元素,然后在中断时重置

jquery - 如何获得高度

jquery - 更改文本框的位置

Col 中的 CSS 垂直对齐对象

css - 高效的 CSS 选择器

jquery - 是什么让下拉菜单覆盖其他元素?

css - SVG 图像 Sprite 作为背景图像缩放在 Chrome 53 上崩溃

html - 是否可以使用 CSS 代码为 SVG 过滤器的不透明度设置动画?

html - 整个导航的渐变,而不是 li

css - 我的网站正文的背景图片在桌面上是响应式的,但在实际手机上不是