html - 按钮和文字不在一条线上

标签 html css layout

有谁知道为什么右边的按钮与标题和左边的按钮不一致?我用 position:fixed 试了一下,但是它在标题下面(可见但不可点击)。我现在不知道我在这里做错了什么。

    <header class="title">

  <button id="buttonLeft" class="btn-square pull-left" onclick="toggleMenu()">

    <i class="fa fa-chevron-left"></i>

  </button>

  <div id="headerElements">

    <h1> TITEL </h1>

  </div>

  <button id="buttonRight" class="btn-square pull-right" onclick="">

    <i class="fa fa-chevron-right"></i>

  </button>

</header>

  header.title {

  display: inline-block;
  position: absolute;
  top: 0px;
  left: 0px;
  width: 100%;
  height: 72px;
  background-color: #37baf4;
  color: white;
  display: inline;
  text-align: center;
  z-index: 90;
}

header h1 {

  left: 0;
  top: 0px;
  right: 0;
  width: 100%;
  z-index: 90;
}

#buttonLeft {
  float: left;
  margin: 18px;
  z-index: 101;
}

#buttonRight {

  float: right;
  margin: 18px;
  z-index: 101;
}

.pull-left {}

.pull-right {}

.btn-square {

  background-color: rgba(255, 255, 255, 1.0);
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.9);
  width: 40px;
  height: 40px;
  border: 1px solid;
  border-color: white;
}

谢谢 JSFiddle Code

最佳答案

header.title {

  display: inline-block;
  position: absolute;
  top: 0px;
  left: 0px;
  width: 100%;
  height: 72px;
  background-color: #37baf4;
  color: white;
  display: inline;
  text-align: center;
  z-index: 90;
}
header.title  div{
  float: left;
}

header h1 {

  left: 0;
  top: 0px;
  right: 0;
  z-index: 90;
}

#buttonLeft {
  float: left;
  margin: 18px;
  z-index: 101;
}

#buttonRight {

  float: right;
  margin: 18px;
  z-index: 101;
}

.pull-left {}

.pull-right {}

.btn-square {

  background-color: rgba(255, 255, 255, 1.0);
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.9);
  width: 40px;
  height: 40px;
  border: 1px solid;
  border-color: white;
}
<header class="title">
  <div>
    <button id="buttonLeft" class="btn-square pull-left" onclick="toggleMenu()">
      <i class="fa fa-chevron-left"></i>
    </button>
  </div>
  <div id="headerElements">
    <h1> TITEL </h1>
  </div>
  <div>
    <button id="buttonRight" class="btn-square pull-right" onclick="">
      <i class="fa fa-chevron-right"></i>
    </button>
  </div>	
</header>

.titlle 中每个 div 的宽度取决于您的选择。

关于html - 按钮和文字不在一条线上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36703560/

相关文章:

jquery - 为什么我的导航栏 'bars' 不能在移动 View 中正确显示?

javascript - 获取 Javascript div 在出现时滑出

php - 表格行数据的动态缩略图

React 应用程序刷新后 CSS 样式消失

jquery - 如何将多个元素放在 div 的第二行

java - 如何在不同位置使用 LinearLayout 两次?中心和底部

css - 子div的高度溢出父容器

jquery - 将滚动条位置移动 x 个像素

html - 仅在缺少位置时隐藏表列

javascript - 有没有一种方法可以在不编写任何 JavaScript 的情况下构建在手机屏幕和桌面屏幕上使用不同字体的网页?