html - 在悬停时显示垂直按钮集而不移动/按下背景内容

标签 html css hover hidden fixed

嗨:这些年来我在很多网站上都看到过这个(顶部的水平按钮栏,将鼠标悬停在其中一个主要按钮上时会显示相关子功能的访问按钮)但我不太确定该怎么做.我在这里找到的代码实际上让我在没有任何 javascript 的情况下到达那里,但是每当显示一个子按钮集时,它都会将所有后续页面内容向下推送。我不想要这个。我宁愿在页面内容之上(即覆盖)打开按钮集,而不在其“后面”移动任何内容。

这是一个 fiddle ,展示了我到目前为止所得到的......

    <html>
        <head>
        <style>
        body{position:fixed;}
        button{ width: 100%; }
        button.hidden { display:none;}
        button.main {display:block;}
        div.buttongroup {display:block; float: left; width: 20%;}
        div.buttongroup:hover .hidden {display:block;}
    </style>
    </head>
    <body>
        <div class="buttongroup" id="one">
        <button class="main">MAIN 1</button>
        <button class="hidden">2</button>
        <button class="hidden">3</button>
        <button class="hidden">4</button>
        <button class="hidden">5</button>
        </div>
        <div class="buttongroup" id="two">
        <button class="main">MAIN 2</button>
        <button class="hidden">2</button>
        <button class="hidden">3</button>
        <button class="hidden">4</button>
        <button class="hidden">5</button>
        </div>
        <div class="buttongroup" id="three">
        <button class="main">MAIN 3</button>
        <button class="hidden">2</button>
        <button class="hidden">3</button>
        <button class="hidden">4</button>
        <button class="hidden">5</button>
        </div>
        <div style="clear:both;"></div>
        <p>Howdy. I am a paragraph or any other page contents (images, background, etc.) that should just REMAIN fixed exactly where they are in the background when the site visitor momentarily hovers over the main button above and the hidden buttonset cascades open.</p>
    </body>
    </html>

http://jsfiddle.net/Lzd6zraq/

最佳答案

您需要将按钮设置为position: absolute。 这是一个例子:http://jsfiddle.net/Lzd6zraq/1/ 您还可以将它们设置为 position: fixed,这样它们将始终保持在它们的位置,即使您滚动也是如此。

.buttons {position: absolute; width: 100%;}

<div class="buttons">
  *buttons*
</div>

关于html - 在悬停时显示垂直按钮集而不移动/按下背景内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27407827/

相关文章:

javascript - 如何仅在浏览器中禁用 cookie 时显示消息?

javascript - PHP/Javascript - 显示tinyMCE生成的HTML页面的更多功能

css - :hover above img doesnt work properly with display block under IE & Opera

javascript - 使用悬停将图像加载到另一个图像上 (Javascript)

html - 我无法使用 html 和 css 在 Sencha Architect 中设置图标大小的样式

html - map 区域悬停行为异常

javascript - Angular 服务可以从一个 Controller 设置数据,但不能从另一个 Controller 设置数据

html - 除非 html 元素发生更改,否则 nth-of-type 不起作用

Javascript - 简单地获取元素的高度

html - css - 对齐图像在一条直线上