首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >内容div之间的制表符,第一个div不会在加载时激活

内容div之间的制表符,第一个div不会在加载时激活
EN

Stack Overflow用户
提问于 2019-12-05 00:02:43
回答 2查看 109关注 0票数 0

我有两个div,我需要使用两个导航选项卡进行导航:第一年和第二年。当我单击第一年时,导航效果很好,出现"first“div,"second”也是如此。我的问题是,当页面第一次加载时,两个div都不是活动的。当页面第一次加载时,如何让" first“div始终显示?我看了很多帖子,但还是不能解决这个问题。

也就是说,当页面第一次加载时,两个选项卡都不会显示,直到我单击它们

在页面加载时,它应该如下所示:

当前代码:

代码语言:javascript
运行
复制
section {
  padding: 150px 0;
}

header {
  padding: 156px 0 100px;
}

.it-icons a {
  display: inline-block;
  height: 3.5rem;
  width: 3.5rem;
  background-color: #4582EC;
  color: #fff !important;
  border-radius: 100%;
  text-align: center;
  font-size: 1.5rem;
  line-height: 3.5rem;
  margin-right: 1rem;
}

.it-icons a:hover {
  transform: scale(1.3) rotate(20deg);
  background-color: skyblue;
}

.tu-icon a:hover {
  transform: rotate(5deg);
}


.os-icons a {
  display: inline-block;
  height: 3.5rem;
  width: 3.5rem;
  background-color: #4582EC;
  color: #fff !important;
  border-radius: 100%;
  text-align: center;
  font-size: 1.5rem;
  line-height: 3.5rem;
  margin-right: 1rem;
}

.os-icons a:hover {
  transform: scale(1.3) rotate(20deg);
  background-color: skyblue;
}




.tabs .nav-tabs > li, .tabs .nav-pills > li {
  float: none;
  display: inline-block;
  margin-bottom: 10px;
  padding: 5px 5px;
}

.tabs .nav-tabs {
  text-align: center;
  border-bottom: 0;
  margin-bottom: 20px;
}

.tabs .nav-tabs li:not(:last-child) {
  margin-right: 10px;
}

.tabs .nav-tabs li a {
  text-transform: capitalize;
  font-size: 20px;
  padding: 10px 25px;
  border: 2px solid #4582EC;
  border-radius: 0;
  transition: all .3s ease;
  font-weight: 600;
  color: #4582EC;
  font-family: "Source Sans Pro", sans-serif;
}

.tabs .nav-tabs li a:hover {
  background: #4582EC;
  color: #fff;
  border: 2px solid #4582EC;
}

.tabs .nav-tabs li.active a {
  color: #fff;
  background: #4582EC;
  border: 2px solid #4582EC;
}

.service-box {
  position: relative;
  width: 100%;
}

.service-box .contents {
  margin-left: 30px;
}



.tab-content {
  position: relative;
  float: left;
  width: 100%;
  z-index: 99;
}

.service-box {
  position: relative;
  width: 100%;
}

.service-box .section-title h3 {
  position: relative;
  font-size: 32px;
  line-height: 42px;
  font-weight: 700;
  padding-bottom: 20px;
  margin-bottom: 45px;
  color: #000;
  text-transform: uppercase;
}

.service-box .section-title h3:before {
  position: absolute;
  left: 0px;
  content: '';
  bottom: 0px;
  background: #333333;
  height: 1px;
  width: 55px;
}
代码语言:javascript
运行
复制
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>

<section id="education" style="background-color:whitesmoke;">
    <div class="container">
      <div class="row d-flex no-gutters">
        <div class="col-lg-12 mx-auto">
          <h2 style="text-align: center;"> Education </h2>

          <div class="row">
            <br>
            <br>

            <div class="col-md-8">

              <!--tabs-->
              <div class="tabs">
                <ul class="nav nav-tabs" role="tablist">
                  <li role="presentation" class="active">
                    <a href="#first" data-toggle="tab"> First Year </a>
                  </li>
                  <li role="presentation">
                    <a href="#second" data-toggle="tab"> Second Year </a>
                  </li>
                </ul>
              </div>
              <!--Start single tab content-->
              <div class="tab-content">

                <div class="service-box tab-pane fade in active row" id="first">
                  <div class="contents">

                    <div class="section-title">
                      <br>
                      <h3> First Year</h3>
                      <br>
                    </div>

                   <div class="col-md-8 animate-box">
                      <div class="progress-wrap">
                        <h3>Photoshop</h3>
                        <div class="progress" style="width: 100%;">
                          <div class="progress-bar  color-1" role="progressbar" aria-valuenow="90"
                            aria-valuemin="0" aria-valuemax="100" style="width:90%">
                            <span>90%</span>
                          </div>
                        </div>
                      </div>
                      <br>

                      <div class="progress-wrap ftco-animate">
                        <h3>jQuery</h3>
                        <div class="progress">
                          <div class="progress-bar color-2" role="progressbar" aria-valuenow="85" aria-valuemin="0"
                            aria-valuemax="100" style="width:85%">
                            <span>85%</span>
                          </div>
                        </div>
                      </div>
                      <br>

                    </div>
                  </div>
                </div>
                <!--End single tab content-->
                <!--Start single tab content-->
                <div class="service-box tab-pane fade in" id="second">
                  <div class="contents">

                    <div class="section-title">
                      <br>
                      <h3> Second Year</h3>
                      <br>
                    </div>

                    <div class="col-md-8 animate-box">
                      <div class="progress-wrap">
                        <h3>Java</h3>
                        <div class="progress" style="width: 100%;">
                          <div class="progress-bar color-1" role="progressbar" aria-valuenow="90"
                            aria-valuemin="0" aria-valuemax="100" style="width:90%">
                            <span>90%</span>
                          </div>
                        </div>
                      </div>
                      <br>

                      <div class="progress-wrap ftco-animate">
                        <h3>C#</h3>
                        <div class="progress">
                          <div class="progress-bar color-2" role="progressbar" aria-valuenow="85" aria-valuemin="0"
                            aria-valuemax="100" style="width:85%">
                            <span>85%</span>
                          </div>
                        </div>
                      </div>
                      <br>

                    </div>
                  </div>
                </div>
                <!--End single tab content-->



              </div>


            </div>

          </div>
        </div>
      </div>
    </div>
  </section>

EN

Stack Overflow用户

发布于 2019-12-05 00:26:03

您可以将show类添加到<div class="service-box tab-pane fade in active row show" id="first">元素中以在默认情况下显示。

直接将类添加到元素比使用代码更好,因为如果在代码运行时元素不存在,它将不会做任何事情。如果你把你的代码放在onLoad函数上,如果你的页面需要时间加载,你会注意到闪烁。

此外,必须更改活动选项卡,因为引导程序将active类放在a元素上,而您的active样式放在li标记上。您必须将活动样式放置在li标签上。我已经在下面的代码、HTML和CSS中做到了这一点。

活动类现在为:

代码语言:javascript
运行
复制
   .tabs .nav-tabs li a.active {
      color: #fff;
      background: #4582EC;
      border: 2px solid #4582EC;
    }

默认情况下,活动类位于以下元素上:

代码语言:javascript
运行
复制
<a href="#first" data-toggle="tab" class="active"> First Year </a>

示例如下:

代码语言:javascript
运行
复制
section {
  padding: 150px 0;
}

header {
  padding: 156px 0 100px;
}

.it-icons a {
  display: inline-block;
  height: 3.5rem;
  width: 3.5rem;
  background-color: #4582EC;
  color: #fff !important;
  border-radius: 100%;
  text-align: center;
  font-size: 1.5rem;
  line-height: 3.5rem;
  margin-right: 1rem;
}

.it-icons a:hover {
  transform: scale(1.3) rotate(20deg);
  background-color: skyblue;
}

.tu-icon a:hover {
  transform: rotate(5deg);
}


.os-icons a {
  display: inline-block;
  height: 3.5rem;
  width: 3.5rem;
  background-color: #4582EC;
  color: #fff !important;
  border-radius: 100%;
  text-align: center;
  font-size: 1.5rem;
  line-height: 3.5rem;
  margin-right: 1rem;
}

.os-icons a:hover {
  transform: scale(1.3) rotate(20deg);
  background-color: skyblue;
}




.tabs .nav-tabs > li, .tabs .nav-pills > li {
  float: none;
  display: inline-block;
  margin-bottom: 10px;
  padding: 5px 5px;
}

.tabs .nav-tabs {
  text-align: center;
  border-bottom: 0;
  margin-bottom: 20px;
}

.tabs .nav-tabs li:not(:last-child) {
  margin-right: 10px;
}

.tabs .nav-tabs li a {
  text-transform: capitalize;
  font-size: 20px;
  padding: 10px 25px;
  border: 2px solid #4582EC;
  border-radius: 0;
  transition: all .3s ease;
  font-weight: 600;
  color: #4582EC;
  font-family: "Source Sans Pro", sans-serif;
}

.tabs .nav-tabs li a:hover {
  background: #4582EC;
  color: #fff;
  border: 2px solid #4582EC;
}

.tabs .nav-tabs li a.active {
  color: #fff;
  background: #4582EC;
  border: 2px solid #4582EC;
}

.service-box {
  position: relative;
  width: 100%;
}

.service-box .contents {
  margin-left: 30px;
}



.tab-content {
  position: relative;
  float: left;
  width: 100%;
  z-index: 99;
}

.service-box {
  position: relative;
  width: 100%;
}

.service-box .section-title h3 {
  position: relative;
  font-size: 32px;
  line-height: 42px;
  font-weight: 700;
  padding-bottom: 20px;
  margin-bottom: 45px;
  color: #000;
  text-transform: uppercase;
}

.service-box .section-title h3:before {
  position: absolute;
  left: 0px;
  content: '';
  bottom: 0px;
  background: #333333;
  height: 1px;
  width: 55px;
}
代码语言:javascript
运行
复制
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>

<section id="education" style="background-color:whitesmoke;">
    <div class="container">
      <div class="row d-flex no-gutters">
        <div class="col-lg-12 mx-auto">
          <h2 style="text-align: center;"> Education </h2>

          <div class="row">
            <br>
            <br>

            <div class="col-md-8">

              <!--tabs-->
              <div class="tabs">
                <ul class="nav nav-tabs" role="tablist">
                  <li role="presentation">
                    <a href="#first" data-toggle="tab" class="active"> First Year </a>
                  </li>
                  <li role="presentation">
                    <a href="#second" data-toggle="tab"> Second Year </a>
                  </li>
                </ul>
              </div>
              <!--Start single tab content-->
              <div class="tab-content">

                <div class="service-box tab-pane fade in active row show" id="first">
                  <div class="contents">

                    <div class="section-title">
                      <br>
                      <h3> First Year</h3>
                      <br>
                    </div>

                   <div class="col-md-8 animate-box">
                      <div class="progress-wrap">
                        <h3>Photoshop</h3>
                        <div class="progress" style="width: 100%;">
                          <div class="progress-bar  color-1" role="progressbar" aria-valuenow="90"
                            aria-valuemin="0" aria-valuemax="100" style="width:90%">
                            <span>90%</span>
                          </div>
                        </div>
                      </div>
                      <br>

                      <div class="progress-wrap ftco-animate">
                        <h3>jQuery</h3>
                        <div class="progress">
                          <div class="progress-bar color-2" role="progressbar" aria-valuenow="85" aria-valuemin="0"
                            aria-valuemax="100" style="width:85%">
                            <span>85%</span>
                          </div>
                        </div>
                      </div>
                      <br>

                    </div>
                  </div>
                </div>
                <!--End single tab content-->
                <!--Start single tab content-->
                <div class="service-box tab-pane fade in" id="second">
                  <div class="contents">

                    <div class="section-title">
                      <br>
                      <h3> Second Year</h3>
                      <br>
                    </div>

                    <div class="col-md-8 animate-box">
                      <div class="progress-wrap">
                        <h3>Java</h3>
                        <div class="progress" style="width: 100%;">
                          <div class="progress-bar color-1" role="progressbar" aria-valuenow="90"
                            aria-valuemin="0" aria-valuemax="100" style="width:90%">
                            <span>90%</span>
                          </div>
                        </div>
                      </div>
                      <br>

                      <div class="progress-wrap ftco-animate">
                        <h3>C#</h3>
                        <div class="progress">
                          <div class="progress-bar color-2" role="progressbar" aria-valuenow="85" aria-valuemin="0"
                            aria-valuemax="100" style="width:85%">
                            <span>85%</span>
                          </div>
                        </div>
                      </div>
                      <br>

                    </div>
                  </div>
                </div>
                <!--End single tab content-->



              </div>


            </div>

          </div>
        </div>
      </div>
    </div>
  </section>

票数 1
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59180106

复制
相关文章

相似问题

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