无法对齐" a"标签

时间:2018-01-05 15:01:30

标签: css css3

我想知道为什么我不能将我的.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

2 个答案:

答案 0 :(得分:2)

text-align: center应用于您的#hero包装器,您的链接就会很好。

答案 1 :(得分:0)

<a></a>确实具有特定的宽度。所以,只需添加.workButton,

#hero {
  .workButton {
    width: 100px;
    text-align: center;
  }
}

那就是......谢谢......

相关问题