【问题标题】:Bootstrap Nav Pills content widthBootstrap Nav Pills 内容宽度
【发布时间】:2021-07-23 10:31:59
【问题描述】:

我正在使用带有两个标签的 Bootstrap 药丸。我希望标签内容的容器具有不同的宽度。我不知道该怎么做。 tab-content 设置两个宽度。我需要 tab1 容器为 600px 宽,tab2 为 800px。

<div class="container"> 
<ul  class="nav nav-pills justify-content-center">
            <li class="active">
        <a  href="#tab1" data-toggle="tab">First Tab</a>
            </li>
            <li><a href="#tab2" data-toggle="tab">Second Tab</a>
            </li>
            
        </ul>

            <div class="tab-content clearfix">
              <div class="tab-pane active" id="tab1" >
          <h3>Same as example 1 but we have now styled the tab's corner</h3>
                </div>
                <div class="tab-pane" id="tab2">
          <h3>We use the class nav-pills instead of nav-tabs which automatically creates a background color for the tab</h3>
                </div>
        
            </div>
  </div>

CSS:

.nav-pills > li {
    float:none;
    display:inline-block;
    zoom:1;
}

.nav-pills {
    text-align:center;
}

.nav-pills > li > a {
  border-radius: 6px 6px 0 0 ;
  
  background-color: #FFF;
  color: black;
  font-size: 13px;
  font-family: 'Lato', sans-serif;
  font-weight: 700;
  padding: 7px 50px;
    text-decoration: none;
    margin-right: 20px;
}
.nav-pills > li.active > a {
  background-color: #F5A000;
}


.tab-content {
    margin-top: 4px;
  padding : 5px 15px;
  box-shadow: 0 2rem 2rem #00000080;
  height:90px;
  position: relative;
  border-radius:0px 0px 8px 8px;
  border-top: 3px solid #F5A000;
  background-color: rgba(255, 255, 255, 0.5);
  
}

有什么建议吗?

【问题讨论】:

  • 我正在使用引导程序 5

标签: css twitter-bootstrap bootstrap-5 nav-pills


【解决方案1】:

“我需要 tab1 容器为 600px 宽,tab2 为 800px。”

两个标签共享一个tab-content 容器。但由于每个标签都有自己的tab-pane,您可以更改它的宽度。

.tab-pane {
    padding: 5px 15px;
    box-shadow: 0 2rem 2rem #00000080;
    position: relative;
    border-radius: 0px 0px 8px 8px;
    border-top: 3px solid #F5A000;
    background-color: rgba(255, 255, 255, 0.5);
}

#tab1 {
    width: 600px;    
}

#tab2 {
    width: 800px;    
}

https://codeply.com/p/DrJOw7Pf78

编辑:居中是一个单独的问题.. 只需在选项卡内容上使用 flexbox:

&lt;div class="tab-content clearfix d-flex justify-content-center"&gt;..&lt;/div&gt;

【讨论】:

  • 感谢您的帮助。选项卡窗格和导航药丸未居中
  • 这不是问题吧?
  • 那只是另一个问题 :)
猜你喜欢
  • 2015-09-17
  • 2023-04-07
  • 2016-08-14
  • 1970-01-01
  • 2015-12-14
  • 2012-05-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多