【问题标题】:Divs on the same row in htmlhtml中同一行上的div
【发布时间】:2016-11-08 07:53:45
【问题描述】:

在不使用 HTML Table 的情况下,是否有任何解决方案可以将 2 个 div 放在一行中的不同列和同一行上,2 个 div 放在同一列上,一个在另一个之上?

这是一张解释得更好的图片:

我正在使用引导程序,我正在尝试达到此目的:

这是我现在得到的:

如果有不同的行,我如何将底部顶部的 DIV 1 和 DIV 2 对齐以居中?

此时我的 html 网格是这样的:

.label {
  font-size: 15px;
}
` #liveChat {
  background-color: #1C3A69;
}
`
<div class="container">
  <div class="col-lg-8 col-lg-offset-2 col-md-8 col-md-offset-2 col-sm-12 col-xs-12 panel" id="mainDiv">
    <header class="row panel-heading"> <span>Tax</span>Extension.com</header>

    <div id="liveChat" class="row ">

      <div class="container">
        <div class="row">
          <div id="taxExtensions" class="label col-md-2 leftItems">
            My Tax Extensions
          </div>
          <div id="UpdateAccount" class="label  col-md-1 leftItems ">
            Update Account Info
          </div>
          <div class="label col-md-2 col-md-offset-7 ">
            <div>
              LIVE CHAT
            </div>
            <div>
              Support is Online
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="panel-body row" id="mainContent" style="min-height:200px; background-color:aquamarine;">

    </div>

    <footer class="panel-footer row">Footer</footer>
  </div>
</div>

【问题讨论】:

  • 你能提供一个工作样本/小提琴吗?
  • 你在做导航栏吗?
  • @TrulyXax,然后改用引导导航栏。

标签: html css twitter-bootstrap


【解决方案1】:

如果导航栏有预定义的高度,可以像这样制作一个简单的

基本上就是一堆div

#div-l{
background-color:red;
}
#div-m{
background-color:blue;
}
#div-r1{
background-color:green;
}
#div-r2{
background-color:grey;
}
.single-stack{
height:50px;
float:left;
width:33%
}
.double-stack{
height:25px;
float:left;
width:33%
}
<div id="div-l" class="single-stack">&nbsp;</div>
<div id="div-m" class="single-stack">&nbsp;</div>
<div id="div-r1" class="double-stack">&nbsp;</div>
<div id="div-r2" class="double-stack">&nbsp;</div>

【讨论】:

    【解决方案2】:

    如果您正在为导航栏工作。那为什么不使用引导导航栏组件呢? 看一下这个。也可以看here

    HTML

    <nav class="navbar navbar-default sample">
      <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <!-- <a class="navbar-brand" href="#">Brand</a> -->
        </div>
    
        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
          <ul class="nav navbar-nav">
            <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
            <li><a href="#">Link</a></li>
          </ul>
          <ul class="nav navbar-nav navbar-right">
                    <div class="row right-items text-center">
                        <div class="col-xs-12">LIVE CHAT</div>
                        <div class="col-xs-12">Support is Online</div>
                    </div>
                </ul>
        </div><!-- /.navbar-collapse -->
      </div><!-- /.container-fluid -->
    </nav>
    

    CSS:

    .sample{
        background: #1c3a69;
    }
    
    nav{
        color: #fff;
    }
    
    .right-items {
         margin-top: 5px;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-14
      • 2021-10-23
      • 1970-01-01
      • 2012-05-14
      • 1970-01-01
      • 1970-01-01
      • 2017-08-24
      • 2015-08-24
      相关资源
      最近更新 更多