html - 在相对定位的 `<a>` 列表上定义宽度(以百分比表示)

标签 html css

我的导航有一堆 <a>链接:

<section class="nav">
    <nav>
        <a href="#" data-hover="BLA">BLA</a>
        <a href="#" data-hover="BLA">BLA</a>
        <a href="#" data-hover="BLA">BLA</a>
        <a href="#" data-hover="BLA">BLA</a>
        <a href="#" data-hover="BLA">BLA</a>
    </nav>
</section>

我的目标是用这些链接覆盖整个显示。所以每个链接需要的高度为20% .

我现在的问题是 <section>有一个position:fixed高度设置为 100% .
如何将高度设置为20%position:relative

这里是额外的 CSS 语句,最后是演示 fiddle 。

.container,
.container > section, /* the part where the section tag above will set to 100% */
.container > section > article{
    position: fixed;
    margin: 0;
    padding: 0;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}
.nav{
    z-index: 1000;
    background: rgba(255, 0, 0, 0.5);
}
.nav nav a{
    display: block;
    height: 20%; /* the 20% which doesn't work because of the position:relative;
    background: blue;
}

http://codepen.io/anon/pen/rhEHl

最佳答案

a 元素上设置 height: 20% 将它们设置为其包含元素的 20% 高度。在这种情况下,包含元素是您的 nav,它没有您指定的任何高度,并且默认为其内容的高度。您需要将 nav 设置为 100% 高度以填充部分:

.nav nav {
    height: 100%;
}

Working CodePen demo .

关于html - 在相对定位的 `<a>` 列表上定义宽度(以百分比表示),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21234307/

相关文章:

html - CSS - 'Open Sans' 字体

css - BootStrap 导航栏侧面按钮未显示

html - 非设计师开发人员使用配色工具的最佳策略是什么?

javascript - 写入服务器: using text file with HTML5 Jquery/Javascript

css - 允许跨度在 Twitter Bootstrap 中溢出行

jquery - 使用 jquery 将动画添加到 bootstrap Tooltip

html - 背景图片不显示

javascript - 如何使用 HTML 设置在浏览器上播放的视频的结束时间值?

javascript - 如何在 JavaScript 中循环浏览图片?

html - View 函数未返回有效响应。该函数返回None或在没有返回语句的情况下结束flask flask Elasticsearch