我想让nav-tabs ul将其内容呈现为2列而不是水平(这是bootstrap nav-tabs的默认样式)。
我尝试了css属性column-count: 2
,但它没有工作
以下是我的代码
<ul class="nav nav-tabs ml-0 mr-0 bg-primary two-columns" role="tablist" style="column-count: 2;">
<li class="nav-item"><a class="nav-link active" data-toggle="tab" href="#cont1" role="tab">Title 1</a></li>
<li class="nav-item"><a class="nav-link " data-toggle="tab" href="#cont2" role="tab">Title 2</a></li>
<li class="nav-item"><a class="nav-link " data-toggle="tab" href="#cont3" role="tab">Title 3</a></li>
<li class="nav-item"><a class="nav-link " data-toggle="tab" href="#cont4" role="tab">Title 4</a></li>
<li class="nav-item"><a class="nav-link " data-toggle="tab" href="#cont5" role="tab">Title 5</a></li>
<li class="nav-item"><a class="nav-link " data-toggle="tab" href="#cont6" role="tab">Title 6</a></li>
<li class="nav-item"><a class="nav-link " data-toggle="tab" href="#cont7" role="tab">Title 7</a></li>
<li class="nav-item"><a class="nav-link " data-toggle="tab" href="#cont8" role="tab">Title 8</a></li>
</ul>
<!-- Tab panes -->
<div class="tab-content ml-2 mr-2">
<div class="tab-pane jumbotron active" id="cont1" role="tabpanel">Conctent 1</div>
<div class="tab-pane jumbotron active" id="cont2" role="tabpanel">Conctent 2</div>
<div class="tab-pane jumbotron active" id="cont3" role="tabpanel">Conctent 3</div>
<div class="tab-pane jumbotron active" id="cont4" role="tabpanel">Conctent 4</div>
<div class="tab-pane jumbotron active" id="cont5" role="tabpanel">Conctent 5</div>
<div class="tab-pane jumbotron active" id="cont6" role="tabpanel">Conctent 6</div>
<div class="tab-pane jumbotron active" id="cont7" role="tabpanel">Conctent 7</div>
<div class="tab-pane jumbotron active" id="cont8" role="tabpanel">Conctent 8</div>
</div>
和我的自定义css类two-columns
ul.two-columns {
-moz-column-count: 2 !important;
-moz-column-gap: 2.5em !important;
-webkit-column-count: 2 !important;
-webkit-column-gap: 2.5em !important;
column-count: 2 !important;
column-gap: 2.5em !important;
}
我认为Bootstrap中包含的JavaScript会阻止我的自定义样式。 以下是我的代码
有没有人知道如何实现这个目标?
答案 0 :(得分:0)
试试这个答案
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<style>
.tabs-left{
border-bottom: none;
padding-top: 2px;
}
.tabs-left {
border-right: 1px solid #ddd;
}
.tabs-left>li {
float: none;
margin-bottom: 2px;
}
.tabs-left>li {
margin-right: -1px;
}
.tabs-left>li.active>a,
.tabs-left>li.active>a:hover,
.tabs-left>li.active>a:focus {
border-bottom-color: #ddd;
border-right-color: transparent;
}
.tabs-left>li>a {
border-radius: 4px 0 0 4px;
margin-right: 0;
display:block;
}
</style>
<div class="row" style="min-height:300px;">
<div class="col-sm-6">
<div class="col-xs-3">
<!-- required for floating -->
<!-- Nav tabs -->
<ul class="nav nav-tabs tabs-left">
<li class="nav-item active"><a class="nav-link" data-toggle="tab" href="#cont1" role="tab">Title 1</a></li>
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#cont2" role="tab">Title 2</a></li>
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#cont3" role="tab">Title 3</a></li>
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#cont4" role="tab">Title 4</a></li>
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#cont5" role="tab">Title 5</a></li>
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#cont6" role="tab">Title 6</a></li>
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#cont7" role="tab">Title 7</a></li>
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#cont8" role="tab">Title 8</a></li>
</ul>
</div>
<div class="col-xs-9">
<!-- Tab panes -->
<div class="tab-content ml-2 mr-2">
<div class="tab-pane jumbotron active" id="cont1" role="tabpanel">Conctent 1</div>
<div class="tab-pane jumbotron" id="cont2" role="tabpanel">Conctent 2</div>
<div class="tab-pane jumbotron" id="cont3" role="tabpanel">Conctent 3</div>
<div class="tab-pane jumbotron" id="cont4" role="tabpanel">Conctent 4</div>
<div class="tab-pane jumbotron" id="cont5" role="tabpanel">Conctent 5</div>
<div class="tab-pane jumbotron" id="cont6" role="tabpanel">Conctent 6</div>
<div class="tab-pane jumbotron" id="cont7" role="tabpanel">Conctent 7</div>
<div class="tab-pane jumbotron" id="cont8" role="tabpanel">Conctent 8</div>
</div>
</div>
<div class="clearfix"></div>
</div>
答案 1 :(得分:0)
您可以尝试此代码
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-3">
<ul class="nav nav-pills nav-stacked">
<li class="active"><a data-toggle="pill" href="#home">Home</a></li>
<li><a data-toggle="pill" href="#menu1">Menu 1</a></li>
<li><a data-toggle="pill" href="#menu2">Menu 2</a></li>
<li><a data-toggle="pill" href="#menu3">Menu 3</a></li>
</ul>
</div>
<div class="col-md-9">
<div class="tab-content">
<div id="home" class="tab-pane fade in active">
<h3>HOME</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
<div id="menu1" class="tab-pane fade">
<h3>Menu 1</h3>
<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
<div id="menu2" class="tab-pane fade">
<h3>Menu 2</h3>
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam.</p>
</div>
<div id="menu3" class="tab-pane fade">
<h3>Menu 3</h3>
<p>Eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.</p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>