首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不能在一行中垂直对齐内容

不能在一行中垂直对齐内容
EN

Stack Overflow用户
提问于 2018-03-15 04:39:24
回答 2查看 69关注 0票数 0

我要疯了,因为无法将一些元素对齐到引导行的中心。唯一起作用的似乎是将某些元素定位为相对于行的绝对位置,但我想避免这一点,因为在响应性方面,这将是一个调整对象之间水平差距的问题。您能否建议一种更有效的方法来垂直对齐下面的行元素中的所有内容?我的代码如下: PS。我正在使用引导3.0和SCSS

HTML

代码语言:javascript
复制
<div class="standard-container">
  <div class="row title-menu-row">
      <div class="col-md-4 title-menu-col">
        <h1>Your predictions</h1>
      </div>
      <div class="col-md-7 title-menu-col">
        <span class="badge badge-error pmd-ripple-effect">12</span>
        <span>Not predicted yet</span>
        <div class="onoffswitch">
            <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch">
            <label class="onoffswitch-label" for="myonoffswitch"></label>
        </div>
      </div>
      <div class="col-md-1 title-menu-col icons">
        <a href="#">
          <span class="fa-layers fa-fw" style="">
            <i class="fal fa-female" data-fa-transform="shrink-3 up-1 left-6"></i>
            <i class="fal fa-male" data-fa-transform="shrink-3 down-1"></i>
          </span>
        </a>
        <a href="#">
          <i class="fal fa-table"></i>
        </a>
      </div>
  </div>

SCSS

代码语言:javascript
复制
// ---------------  Toggle switch ---------------
.onoffswitch {
    position: relative; width: 48px;
    -webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch-checkbox {
    display: none;
}
.onoffswitch-label {
    display: block; overflow: hidden; cursor: pointer;
    height: 24px; padding: 0; line-height: 24px;
    border: 2px solid #F1F1F5; border-radius: 24px;
    background-color: #F1F1F5;
    transition: background-color 0.3s ease-in;
}
.onoffswitch-label:before {
    content: "";
    display: block; width: 24px; margin: 0px;
    background: #FFFFFF;
    position: absolute; top: 0; bottom: 0;
    right: 22px;
    border: 2px solid #F1F1F5; border-radius: 24px;
    transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox:checked + .onoffswitch-label {
    background-color: #2DC76D;
}
.onoffswitch-checkbox:checked + .onoffswitch-label, .onoffswitch-checkbox:checked + .onoffswitch-label:before {
   border-color: #2DC76D;
}
.onoffswitch-checkbox:checked + .onoffswitch-label:before {
    right: 0px;
}

//---------------all else -----------------


.standard-container {
    padding: 0;
    margin: 170px 0 0 155px;

    .title-menu-row, .title-menu-col {
        margin: 0;
        padding: 0;
    border: 1px solid red;
    }
    h1 {
        color: rgba(117, 64, 238, 1);
        margin: 0;
    }
}

.title-menu-row {

    margin-bottom: 100px !important;
    vertical-align: top;
    .title-menu-col {
    }
    .onoffswitch {
        display: inline-block;
        .onoffswitch-label {
            margin: 0;
        }
    }
    .icons {

    }

    .icon > a, .icons > a {
        color: rgba(117, 64, 238, 1);
        font-size: 20px;
    }
    .icon:first-child > a {
        margin-right: 200px;
    }
}

下面是一个说明这个问题的CodePen。https://codepen.io/alopez25/live/PRNayZ

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-03-15 04:52:03

试着-

代码语言:javascript
复制
display: flex;
align-items:center;

在这里,小小提琴-

https://jsfiddle.net/5v35gvr7/1/

代码语言:javascript
复制
<div class="wrap">
    <div class="inner-wrap">Hello</div>
    <div class="inner-wrap">Hello</div>
</div>


.wrap{
  height: 30px;
  background: green;
  display: flex;
  align-items: center;
}
.inner-wrap{
  margin: 0px 10px;
  background: blue;
  display: inline-block;
}
票数 0
EN

Stack Overflow用户

发布于 2018-03-15 04:58:12

从您的代码创建了一个示例小提琴

添加了一个小的css更改

代码语言:javascript
复制
.container{
 display: flex;
 align-items: center;
 width: 500px;
 height: 100px;
 border: 1px solid #888;
 justify-content: center; //remove horizontal align by removing this
}

代码语言:javascript
复制
.onoffswitch {
    position: relative; width: 48px;
    -webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch-checkbox {
    display: none;
}
.onoffswitch-label {
    display: block; overflow: hidden; cursor: pointer;
    height: 24px; padding: 0; line-height: 24px;
    border: 2px solid #F1F1F5; border-radius: 24px;
    background-color: #F1F1F5;
    transition: background-color 0.3s ease-in;
}
.onoffswitch-label:before {
    content: "";
    display: block; width: 24px; margin: 0px;
    background: #FFFFFF;
    position: absolute; top: 0; bottom: 0;
    right: 22px;
    border: 2px solid #F1F1F5; border-radius: 24px;
    transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox:checked + .onoffswitch-label {
    background-color: #2DC76D;
}
.onoffswitch-checkbox:checked + .onoffswitch-label, .onoffswitch-checkbox:checked + .onoffswitch-label:before {
   border-color: #2DC76D;
}
.onoffswitch-checkbox:checked + .onoffswitch-label:before {
    right: 0px;
}

.container{
  display: flex;
  align-items: center;
  width: 500px;
  height: 100px;
  border: 1px solid #888;
  justify-content: center;
}
.container>*{
  margin: 0px 3px;
}
代码语言:javascript
复制
<div class="container">
  <span class="badge badge-error pmd-ripple-effect">12</span>
  <span>Not predicted yet</span>
  <div class="onoffswitch">
    <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch">
    <label class="onoffswitch-label" for="myonoffswitch"></label>
  </div>
</div>

编辑Fiddle 这里

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49291716

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档