【问题标题】:Centering a button [closed]使按钮居中[关闭]
【发布时间】:2021-05-12 04:52:14
【问题描述】:

当页面宽度为 767 像素且更小时,我试图将按钮居中,但它不起作用。我虽然是通过 display: center ruby​​ 完成的——但这在某种程度上只适用于我的浏览器,但不适用于我的手机。我尝试了很多东西.. 但居中对象不是我的事 :D 谢谢你的任何提示。

<div class="write-us">
  <a href="contactus.html">NAPIŠTE NÁM</a>
</div>

CSS

@media (max-width: 767px) {
.write-us a {
    width: 28%;
}
.write-us {
    margin: auto;
}
}

【问题讨论】:

  • 您能在问题中创建一个minimal reproducible example 吗?不建议使用场外资源/示例,因为一旦问题得到解决,问题就会失去所有未来价值。
  • 请在此处添加有意义的代码和问题描述。不要只链接到需要修复的站点——否则,一旦问题得到解决或者您链接的站点无法访问,这个问题将对未来的访问者失去任何价值。发布 Minimal, Reproducible example (or MCVE) 来证明您的问题将帮助您获得更好的答案。有关详细信息,请参阅Something on my web site doesn't work. Can I just paste a link to it? 谢谢!
  • 只需将margin: auto 发送给@media (max-width: 767px) { .write-us a { width: 28%; margin: auto; } }
  • Manas Khandelwal - 非常感谢,奇怪的是我以为我尝试了很多次。它总是我尝试的第一个想法。但它有效,谢谢! :)

标签: css button responsive center


【解决方案1】:

将 CSS margin: auto; 添加到特定 @media 处的 .write-us a

@media (max-width: 767px)
.write-us a {
    width: 28%;
    margin: auto;
}

【讨论】:

    猜你喜欢
    • 2020-12-21
    • 1970-01-01
    • 1970-01-01
    • 2017-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 2016-03-07
    相关资源
    最近更新 更多