html - 2个按钮彼此相邻的宽度边距与CSS

标签 html css

我怎么把这些<a>位于 div 的中心,在 100% 宽度的 div 中彼此相邻,它们之间有 40px 的空间?

a.explore {
  padding: 15px 20px;
  text-decoration: none;
  text-align: center;
  border: 1px solid #4f96b6;
  font-size: 20px;
}
#container {
  width: 100%;
}
<div id="container">
  <a class="explore" href="#" target="_blank">I'm Ready To Go</a>
  <a class="explore" href="#" target="_blank">Take Me Somewhere</a>
</div>

最佳答案

您可以通过在 #container 上使用 display:flexjustify-content:center 来做到这一点

a.explore {
  padding: 15px 20px;
  text-decoration: none;
  text-align: center;
  border: 1px solid #4f96b6;
  font-size: 20px;
}
a.explore:first-child {
  margin-right:40px;
}
#container {
  width: 100%;
  display:flex;

  justify-content: center;
}
<div id="container">
  <a class="explore" href="#" target="_blank">I'm Ready To Go</a>
  <a class="explore" href="#" target="_blank">Take Me Somewhere</a>
</div>

关于html - 2个按钮彼此相邻的宽度边距与CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38439832/

相关文章:

javascript - JS - 为什么 Angular 使用 `ng-click="f( )"` 属性来处理点击事件,而不是 `$(el).on(' click', f)`?

html - 我应该如何使用 styled-component 解决这些样式问题

jquery - 显示 :none show on load 的元素

css - 使用 CSS3 在页面加载时动画化元素的不透明度

javascript - 如何在 Ant Design Modal Component Body 旁边启用滚动条?

javascript - 如何在同一按钮位置循环切换多个按钮

javascript - 尝试输出多维数组时,AngularJS 中的 ng-repeat 不起作用

html - 使用 css 在文章中放置图像时遇到问题

html - 页面上其他元素之后的元素?

html - 停止折叠位置为 :fixed 的 div