css - 标题不会展开并列出隐藏在 View 中的元素

标签 css

我的测试页有 2 个问题。我试图让页眉占用页面宽度。我将宽度设置为 100%,但它仍然不会扩展到页面宽度。 “链接”项的下拉列表出现在包装元素后面,因此无法单击任何底层链接。谢谢。

代码笔:https://codepen.io/centem/pen/dBdwxw

header {
 margin: 0 auto;
 width: 100%
 height: 40px;
}

header ul {
 height: 40px;
 margin: 0px;
 padding: 0px;
 list-style: none;
}

header ul li {
 float: left;
 width: 200px;
 height: 40px;
 background-color: black;
 opacity: .75;
 line-height: 40px;
 text-align: center;
 font-size: 20px;
 color: white;
}

header ul li a {
 text-decoration: none;
 display: block;
}

header ul li a:hover {
   background-color: green;
}

header ul li ul li {
  display:none;
}

ul li:hover ul li {
  display: block;
}

最佳答案

header 已设置为 100% witdth。但是,您已将固定宽度和 background 设置为 li。您可以简单地使用 flexbox 并将 flex: 1 设置为元素而不用担心它们的宽度。

body {
  margin: 0 auto;
  font: 1.1em;
  background-image: url('CNDsplash.jpg');
  background-repeat: no-repeat;
  background-position: center;
}

h1,
h2,
h3,
h4,
h5 {
  font-weight: 400;
}

header {
  margin: 0 auto;
  width: 100%;
  height: 40px;
}

header ul {
  height: 40px;
  margin: 0px;
  padding: 0px;
  list-style: none;
  display: flex;
}

header ul li {
  height: 40px;
  flex: 1;
  background-color: black;
  opacity: .75;
  line-height: 40px;
  text-align: center;
  font-size: 20px;
  color: white;
}

header ul li a {
  text-decoration: none;
  display: block;
}

header ul li a:hover {
  background-color: green;
}

header ul li ul li {
  display: none;
}

ul li:hover ul li {
  display: block;
}

#title-heading {
  float: left;
}

.hidden {
  display: none;
}

.wrapper {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  border: 2px solid #eee;
  background: #fefefe;
  opacity: 0.9;
  filter: alpha(opacity=90);
  /* for ie8 and earlier */
}

.upload-console {
  /*background: #fefefe;*/
  /*border: 2px solid #eee; */
  padding: 20px;
  /*opacity: 0.9;*/
  /*filter: alpha(opacity=50);*/
  /* for IE8 and earlier */
}

.upload-console-header {
  padding: 0 0 20px 0;
  margin: 0;
  border-bottom: 2px solid #eee;
  font-weight: 600;
  margin-bottom: 20px;
}

.upload-console-drop {
  height: 200px;
  border: 2px dashed #ccc;
  line-height: 200px;
  color: #ccc;
  text-align: center;
  margin-bottom: 20px;
}

.upload-console-drop.drop {
  border-color: #222;
  color: #222;
}

.upload-console-body {
  margin-bottom: 20px;
}

.bar {
  width: 100%;
  background: #eee;
  padding: 3px;
  border-radius: 3px;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, .2);
  box-sizing: border-box;
  margin-bottom: 20px;
}

.bar-fill {
  height: 30px;
  display: block;
  background: cornflowerblue;
  width: 0;
  border-radius: 3px;
  -webkit-transition: width 0.8s ease;
  transition: width 0.8s ease;
}

.bar-fill-text {
  color: #fff;
  line-height: 30px;
  margin-left: 5px;
}

.upload-console-upload {
  border-bottom: 2px solid #ccc;
  margin-bottom: 10px;
  padding-bottom: 10px;
}

.upload-console-upload span {
  float: right;
}
<header>
  <ul>
    <li><a>Home</a></li>
    <li><a>Contact</a></li>
    <li><a>Docs</a></li>
    <li><a>Links</a>
      <ul>
        <li><a>Link 1</a></li>
        <li><a>Link 2</a></li>
        <li><a>Link 3</a></li>
      </ul>
    </li>
  </ul>
</header>
<div class="wrapper">
  <div id="form-heading">
  </div>
  <div class="upload-console">
    <br>
    <h2 class="upload-console-header">FTS</h2>

    <div class="upload-console-body">
      <h3>Select files</h3>
      <form action="upload.php" method="post" enctype="multipart/form-data">
        <input type="file" name="files[]" id="standard-upload-files" multiple>
        <input type="submit" value="Upload files" id="standard-upload">
      </form>

      <h3>Or drag and drop files below</h3>
      <div class="upload-console-drop" id="drop-zone">
        Just drag and drop files here
      </div>

      <div class="bar">
        <div class="bar-fill" id="bar-fill">
          <div class="bar-fill-text" id="bar-fill-text"></div>
        </div>
      </div>

      <div id="uploads-finished" class="hidden">
        <h3>Processed Files</h3>
      </div>

    </div>

  </div>
</div>

关于css - 标题不会展开并列出隐藏在 View 中的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56830560/

相关文章:

css - IE9问题边界半径和线性渐变

jquery - CSS 菜单 - 使子菜单下拉全宽

html - 底部div不居中

html - 无法使用 Bootstrap 缩小导航栏上的响应式 Logo 图像

javascript - 缓慢打开/关闭 div?

css - 如何反转 -*-user-select :none;? 的效果

html - 将文本区域框移动到表单中的文本标题旁边

html - 配置颜色/背景颜色 CSS

javascript - 如何获取 CSS 3D 转换 Canvas 的 Canvas 相对鼠标位置?

html - 使两个 div 响应 - 在大屏幕上并排,在移动设备上彼此下方