html - 将两个 div 水平居中,彼此相邻?

标签 html css

我有两个 ,我需要将它们水平居中,但它们需要彼此相邻。基本上,动态添加的 html 是一个按钮。这是我的两个代码,CSS 是内联的,无论我尝试什么,我似乎都无法正常工作。如果我使用 display: inline-block,我无法让它们并排放置 :(。

<div class="infor-experience col-lg-2 more_info">
  <div class="bottom-add-bid-buttons">
    {% if request.user|isEmployer %}
      <div class="add-to-list" style="float:left; width:300px;">{% include "layout/addtolistmodal.html" %}</div>
      <div class="connect-now bottom" style="width:300px; margin-left:320px;">{% include "layout/bidmodal.html" %}</div>
    {% endif %}
  </div>
</div>

使用这段代码,两个按钮彼此相邻,但它们不是水平居中的。

感谢您的帮助!

最佳答案

例如,我删除了 float:left; 并将宽度减小了 150px。并将 text-align:center 给父级,将 display:inline-block 给子级

.bottom-add-bid-buttons {
  text-align: center
}
.add-to-list,
.connect-now {
  width: 150px;
  display: inline-block;
  text-align: left;
  border: 1px solid #ddd;
}
<div class="infor-experience col-lg-2 more_info">
  <div class="bottom-add-bid-buttons">
    <div class="add-to-list">div 1</div>
    <div class="connect-now bottom">div 2</div>
  </div>
</div>

关于html - 将两个 div 水平居中,彼此相邻?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40858430/

相关文章:

css - 绑定(bind)不适用于属性 "class"

php - 将 css 类应用于回显 php 变量的每个实例

css - ty-product-list__item-name CS-Cart 中的 H2 标签

javascript - 如何设置表单 Action 以打开特定大小的新窗口?

javascript - 单击时使元素成为其父列表的第一个子元素

html - 将 GET 与 tokenID 一起使用以确保安全是个好主意吗?

javascript - onclick 事件不会在第一次点击条件语句时触发

html - 使 HTML 按钮在电子邮件中可见但在浏览器中不可见

html - 滚动时悬停文本不会相对于元素移动

javascript - 使用 jquery、dom 突变在模态窗口中加载图像