创建具有多个 div 的按钮时出现问题
这是我正在尝试构建的菜单。现在我很困惑,不知道如何制作。
一个 div(蓝色箭头)需要负边距才能到达框外,另一个 div 需要蓝色按钮背景,按钮内部还有另外两个 div 或 span 用于文本颜色。但悬停时它们需要看起来相同(白色)。
我曾多次尝试构建它,但都失败了。我在加载时遇到一些错误。也许它需要任何 jquery 代码,但我对它很陌生,我不知道该怎么做。
我在本地工作,无法提供任何链接来显示它,但有一张我想要制作的图像。
我希望你理解我,因为我的英语不好。
This is the menu I'm trying to build. Now I'm confused and can't figure out how to make it.
One div (blue arrow) needs negative margin to get outside the box, another div for blue button background and inside the button two another divs or spans for the text colors. But on hover they need to look same (white color).
I've tried many times to build it but i failed. I get some bugs while loading. Maybe it need any jquery code but I'm very new on it, and I have no idea what to do.
I'm working local and I can't give any link to show it, but there is an image of what I want to make.
I hope you understand me because my English is not good.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
参见: http://jsbin.com/ihugut
这适用于所有现代浏览器,和 IE8+(在 IE7 中性能下降相当)。
(编辑:事实证明,这必须在 IE7 中完美运行,因此请参阅我对该解决方案的回答的结尾)
您可能遇到的一个问题是,因为我的目标是为了使 HTML 尽可能简单,CSS 很复杂,因此可能很难进行更改。
HTML:
CSS:
这是在 IE7 中完全运行的版本: http://jsbin.com/ihugut/3
HTML 必须被破坏:
See: http://jsbin.com/ihugut
This works in all modern browsers, and IE8+ (it degrades reasonably in IE7).
(edit: it turned out that this must work perfectly in IE7, so see the end of my answer for that solution)
The one problem you might have is that because I aimed to keep the HTML as simple as possible, the CSS is complicated, so it could be difficult to make changes.
HTML:
CSS:
Here's a version that works fully in IE7: http://jsbin.com/ihugut/3
The HTML had to be defiled:
看来您很清楚自己想做什么。如果我理解正确的话,你的问题是悬停时一切都会变白。
应该有一个 div 包含所有其他 div,您可以在悬停时更改其子项,而无需像这样使用 Javascript。
例如,如果您有以下 HTML:
您可以使用以下 CSS 将两个子项的颜色在悬停时更改为白色:
http: //jsfiddle.net/ptUkg/
您可以使用相同的技术来显示和隐藏左侧的蓝色箭头。
对于仅颜色,这也适用,但不适用于箭头:
只是为了有替代方案,我不会推荐这个
It seems like you've got a good clue of what you want to do. If I understand correctly your problem is everything turning white on hover.
There should be one div that contains all the others, you can change its children on hover without using Javascript like so.
If you for example have this HTML:
You would use the following CSS to change the color of both children to white on hover:
http://jsfiddle.net/ptUkg/
You can use the same technique to show and hide the blue arrow on the left.
For just the color this would work too, but not for the arrow:
just for the sake of alternatives, I wouldn't recommend this