为什么我的按钮不能对齐?

时间:2017-06-30 17:52:45

标签: html css twitter-bootstrap-3

我制作了一个程序,由于某些原因我的按钮没有正确对齐。我尝试制作一个codepen,但每当我制作它时,它看起来与我在我的网页上看起来不一样。我希望它只是一些我的眼睛错过了样式的东西,我使用bootstrap,只是希望所有东西在一条线上很好地对齐。

这是我的HTML:



<div class="panel-heading">
      <h3 class="panel-title pull-left">Person Summary</h3>

      <div style="float: left;">
        <button class="btn btn-default btn-margin">Save</button>
        <button class="btn btn-default btn-margin">Edit</button>
      </div>

      <div style="float: right;">
        <div class="onoffswitch">
          <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked>
          <label class="onoffswitch-label" for="myonoffswitch">
            <span class="onoffswitch-inner"></span>
            <span class="onoffswitch-switch"></span>
          </label>
        </div>
      </div>
      <div class="clearfix"></div>
  </div>
&#13;
&#13;
&#13;

这里有css,其中大部分都是onoffswitch:

&#13;
&#13;
.panel-heading {
  background-color: #165284;
}

.panel-heading h3 {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: normal;
  width: 75%;
  padding-top: 8px;
  font-weight:bold;
  color: white;
}

.onoffswitch {
  position: relative;
  width: 90px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

.onoffswitch-checkbox {
  display: none;
}

.onoffswitch-label {
  display: block;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid #000000;
  border-radius: 20px;
}

.onoffswitch-inner {
  display: block;
  width: 200%;
  margin-left: -100%;
  transition: margin 0.3s ease-in 0s;
}

.onoffswitch-inner:before, .onoffswitch-inner:after {
  display: block;
  float: left;
  width: 50%;
  height: 30px;
  padding: 0;
  line-height: 30px;
  font-size: 14px;
  color: white;
  font-family: Trebuchet, Arial, sans-serif;
  font-weight: bold;
  box-sizing: border-box;
}

.onoffswitch-inner:before {
  content: "Days";
  padding-left: 10px;
  background-color: #84161B;
  color: #FFFFFF;
}

.onoffswitch-inner:after {
  content: "Hours";
  padding-right: 10px;
  background-color: #84161B;
  color: #FFFFFF;
  text-align: right;
}

.onoffswitch-switch {
  display: block;
  width: 18px;
  margin: 6px;
  background: #FFFFFF;
  position: absolute;
  top: 0;
  bottom: 0;
  right: 56px;
  border: 2px solid #000000;
  border-radius: 20px;
  transition: all 0.3s ease-in 0s;
}

.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
  margin-left: 0;
}

.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
  right: 0px;
}
&#13;
&#13;
&#13;

这是一张目前的照片 enter image description here

2 个答案:

答案 0 :(得分:1)

HTML

.panel-heading {
  background-color: #165284;
}

.panel-heading h3 {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: normal;
  padding-top: 8px;
  font-weight:bold;
  color: white;
}

.onoffswitch {
  position: relative;
  width: 90px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

.onoffswitch-checkbox {
  display: none;
}

.onoffswitch-label {
  display: block;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid #000000;
  border-radius: 20px;
}

.onoffswitch-inner {
  display: block;
  width: 200%;
  margin-left: -100%;
  transition: margin 0.3s ease-in 0s;
}

.onoffswitch-inner:before, .onoffswitch-inner:after {
  display: block;
  float: left;
  width: 50%;
  height: 30px;
  padding: 0;
  line-height: 30px;
  font-size: 14px;
  color: white;
  font-family: Trebuchet, Arial, sans-serif;
  font-weight: bold;
  box-sizing: border-box;
}

.onoffswitch-inner:before {
  content: "Days";
  padding-left: 10px;
  background-color: #84161B;
  color: #FFFFFF;
}

.onoffswitch-inner:after {
  content: "Hours";
  padding-right: 10px;
  background-color: #84161B;
  color: #FFFFFF;
  text-align: right;
}

.onoffswitch-switch {
  display: block;
  width: 18px;
  margin: 6px;
  background: #FFFFFF;
  position: absolute;
  top: 0;
  bottom: 0;
  right: 56px;
  border: 2px solid #000000;
  border-radius: 20px;
  transition: all 0.3s ease-in 0s;
}

.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
  margin-left: 0;
}

.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
  right: 0px;
}

CSS

class SharedPointerSingleton
{
   SharedPointerSingleton() = default;

public:
   static SharedPointerSingleton& getSingleton(
   {
      static SharedPointerSingleton instance;
      return instance;
   }
};

将按钮包装在div中并添加类右拉。并将clearfix添加到面板标题

并删除h3元素的宽度

希望这会有所帮助..

答案 1 :(得分:0)

在乞讨时改变你的CSS

.panel-heading {
  background-color: #165284;
}

到此

.panel-heading  {
  background-color: #165284;
  display: block;
}