【问题标题】:Width 100% isn't using full screen宽度 100% 未使用全屏
【发布时间】:2016-09-17 03:02:34
【问题描述】:

我已经构建了一个修改后的选项卡图表。当您单击左侧的选项卡时,它们会切换右侧的内容。唯一的问题是右侧的主要内容 div,即使宽度为 100%,也只能穿过屏幕的三分之一左右。任何想法为什么?

* {
  padding: 0;
  margin: 0;
}
#container {
  display: block;
  height: 100%;
  width: 100%;
}
#topBar1 {
  height: 55px;
  width: 100%;
  background-color: #FAFAFA;
  border-bottom: 1px solid #d9d9d9;
  display: block;
  position: relative;
  z-index: 2;
}
#topBar2 {
  height: 22px;
  width: 100%;
  background-color: #FAFAFA;
  display: block;
  border-radius: 11%;
  box-shadow: 0 6px 10px -2.5px #ccc;
  position: relative;
  z-index: 2;
  transition: all;
}
main {
  display: block;
  background-color: #EEEEEE;
  height: 1000px;
  width: 100%;
  position: relative;
  z-index: 1;
  top: -5px;
}
nav {
  height: 100%;
  width: 261px;
}
nav::after {
  height: 100%;
  width: 1px;
  content: "";
  display: block;
  background: #d9d9d9;
  position: relative;
  left: 260px;
  top: -1000px;
}
input[type=radio] {
  display: none;
}
.tabs {
  list-style: none;
  position: relative;
  //border: 1px solid #ccc;
  width: 260px;
  height: 100%;
  top: 15px;
}
.tabs li {
  font-family: Roboto, sans-serif;
  font-size: 13px;
  padding: 10px 20px 20px 60px;
  color: #222222;
  //border: 1px solid #ccc;
  background-color: none;
  transition: all .2s ease-in-out;
}
.tabs li:hover {
  background-color: #d9d9d9;
}
.tabs li:active {
  background-color: #d9d9d9;
}
.tabs label {
  display: block;
  position: relative;
  cursor: pointer;
  top: 6px;
}
.tab-content {
  position: absolute;
  display: none;
  z-index: 2;
  height: 100%;
  width: 100%;
  left: 261px;
  top: 0;
  border: 1px solid #ccc;
}
[id^=tab]:checked~[class^=tab-content] {
  display: block;
}
.contentItem {
  //border: 1px solid #ccc;
  height: 38px;
  width: 200px;
  margin-left: 10px;
  margin-top: 10px;
  margin-bottom: 20px;
  margin-left: 10px;
  background-color: #FAFAFA;
  box-shadow: .5px 2px 6px #ccc;
  float: left;
}
.documentIcon {
  height: 30px;
  width: 30px;
  border: 1px solid #ccc;
  margin: 3px;
  margin-left: 5px;
  margin-right: 10px;
  float: left;
}
.contentText {
  font-family: Roboto, sans-serif;
  font-size: 12px;
  color: #222222;
  line-height: 3;
}
<div id="container">
  <div id="topBar1"></div>
  <!--topBar-->
  <div id="topBar2"></div>
  <!--topBar2-->

  <main>
    <nav>
      <ul class="tabs">
        <li>
          <input type="radio" name="tabs" id="tab-1" checked />
          <label for="tab-1">Staff Directory</label>

          <div class="tab-content" id="tab-content-1">
            <div class="contentItem" id="ci1">
              <img src="" alt="" class="documentIcon" />
              <p class="contentText">Telephone Extension List</p>
            </div>



          </div>
          <!--tab-content-->
        </li>

        <li>
          <input type="radio" name="tabs" id="tab-2" />
          <label for="tab-2">How-To Guides</label>
          <div class="tab-content" id="tab-content-2">
            <p>Put Tab 2 Content here</p>
          </div>
        </li>

        <li>
          <input type="radio" name="tabs" id="tab-3" />
          <label for="tab-3">OECTA Calendar</label>
          <div class="tab-content" id="tab-content3">
            <p>Put tab content 3 here</p>
          </div>
        </li>

        <li>
          <input type="radio" name="tabs" id="tab-4" />
          <label for="tab-4">Finance</label>
          <div class="tab-content" id="tab-content-4">
            <p>Put tab content for 4 here</p>
          </div>
        </li>

        <li>
          <input type="radio" name="tabs" id="tab-5" />
          <label for="tab-5">Directories and Contact Lists</label>
          <div class="tab-content" id="tab-content-5">
            <p>Put Tab 5 content here</p>
          </div>
        </li>

        <li>
          <input type="radio" name="tabs" id="tab-6" />
          <label for="tab-6">Upcoming Meetings</label>
          <div class="tab-content" id="tab-content-6">
            <p>Put tab 6 content here</p>
          </div>
        </li>


        <li>
          <input type="radio" name="tabs" id="tab-7" />
          <label for="tab-7">Manuals and Handbooks</label>
          <div class="tab-content" id="tab-content-7">
            <p>Tab Content 7</p>
          </div>
        </li>

        <li>
          <input type="radio" name="tabs" id="tab-8" />
          <label for="tab-8">Information and Forms</label>
          <div class="tab-content" id="tab-content-8">
            <p>Tab Content 8</p>
          </div>
        </li>

        <li>
          <input type="radio" name="tabs" id="tab-9" />
          <label for="tab-9">Visitor Information</label>
          <div class="tab-content" id="tab-content-9">
            <p>Tab Content 9</p>
          </div>
        </li>
      </ul>
    </nav>

  </main>

</div>

【问题讨论】:

  • TL;博士;阅读How to Ask。创建 MCVE。
  • .tab-content 的宽度是其包含块宽度的百分比。所以,“100%”的意思是“.tabs的宽度的100%”,也就是260px。

标签: html css width


【解决方案1】:

您正在寻找这样的东西吗? https://jsfiddle.net/csgn6051/9/

.tabs
{
    width: calc(100% - 270px);
}

【讨论】:

  • 非常感谢!是不是因为元素是“绝对的”,系统无法100%计算出已经从html流中取出的元素?
  • 这是因为您将选项卡设置为距左侧约 265 像素,具有 100% 的宽度将设置 100% 的父级并会创建一个滚动条,您想要 100% - 左侧的 265 像素.此外,我将父 div 设置为 100%,就像霰弹枪修复一样。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-09-07
  • 2021-07-23
  • 1970-01-01
  • 1970-01-01
  • 2017-11-11
  • 2011-09-30
  • 2012-08-14
相关资源
最近更新 更多