应用于 YUI 菜单栏的正确 CSS 是什么?

发布于 2024-07-16 17:34:58 字数 2305 浏览 4 评论 0原文

我试图找出使用 CSS sprites 作为 YUI 菜单控件。

我有一个带有以下 CSS 的 CSS 精灵:

.navImg0{width:61px;height:23px;background-repeat:no-repeat;background-position:top left;background-image:url('/dynamicimage/navigation');background-position:-0px -0px;}
.navImg0:hover{width:61px;height:23px;background-repeat:no-repeat;background-position:top left;background-image:url('/dynamicimage/navigation');background-position:-0px -23px;}
.navImg1{width:75px;height:23px;background-repeat:no-repeat;background-position:top left;background-image:url('/dynamicimage/navigation');background-position:-65px -0px;}
.navImg1:hover{width:75px;height:23px;background-repeat:no-repeat;background-position:top left;background-image:url('/dynamicimage/navigation');background-position:-65px -23px;}
.navImg2{width:96px;height:23px;background-repeat:no-repeat;background-position:top left;background-image:url('/dynamicimage/navigation');background-position:-144px -0px;}
.navImg2:hover{width:96px;height:23px;background-repeat:no-repeat;background-position:top left;background-image:url('/dynamicimage/navigation');background-position:-144px -23px;}
.navImg3{width:65px;height:23px;background-repeat:no-repeat;background-position:top left;background-image:url('/dynamicimage/navigation');background-position:-244px -0px;}
.navImg3:hover{width:65px;height:23px;background-repeat:no-repeat;background-position:top left;background-image:url('/dynamicimage/navigation');background-position:-244px -23px;}
.navImg4{width:98px;height:23px;background-repeat:no-repeat;background-position:top left;background-image:url('/dynamicimage/navigation');background-position:-313px -0px;}
.navImg4:hover{width:98px;height:23px;background-repeat:no-repeat;background-position:top left;background-image:url('/dynamicimage/navigation');background-position:-313px -23px;}

如何将其应用到 YUI 菜单?

到目前为止,我已经将 navImg0、navImg1 等样式应用于按钮。

它们出现在正确的位置,但有一些问题:

  • 项目之间有线条,
  • 当我滚动按钮时,我需要理想的方式来删除它们,正确的滚动可以工作,但是如果我从菜单滚动到主菜单上屏幕的一部分按钮消失,
  • 每个顶级项目的
  • 下的 标签不起作用(里面不再有文本)。

他们有很多关于应用 CSS 的文档,但我找不到任何关于如何使用 CSS Sprites 作为图像的示例。

I am trying to figure out the best way to use CSS sprites as header images for a YUI menu control.

I have a CSS sprite with the following CSS :

.navImg0{width:61px;height:23px;background-repeat:no-repeat;background-position:top left;background-image:url('/dynamicimage/navigation');background-position:-0px -0px;}
.navImg0:hover{width:61px;height:23px;background-repeat:no-repeat;background-position:top left;background-image:url('/dynamicimage/navigation');background-position:-0px -23px;}
.navImg1{width:75px;height:23px;background-repeat:no-repeat;background-position:top left;background-image:url('/dynamicimage/navigation');background-position:-65px -0px;}
.navImg1:hover{width:75px;height:23px;background-repeat:no-repeat;background-position:top left;background-image:url('/dynamicimage/navigation');background-position:-65px -23px;}
.navImg2{width:96px;height:23px;background-repeat:no-repeat;background-position:top left;background-image:url('/dynamicimage/navigation');background-position:-144px -0px;}
.navImg2:hover{width:96px;height:23px;background-repeat:no-repeat;background-position:top left;background-image:url('/dynamicimage/navigation');background-position:-144px -23px;}
.navImg3{width:65px;height:23px;background-repeat:no-repeat;background-position:top left;background-image:url('/dynamicimage/navigation');background-position:-244px -0px;}
.navImg3:hover{width:65px;height:23px;background-repeat:no-repeat;background-position:top left;background-image:url('/dynamicimage/navigation');background-position:-244px -23px;}
.navImg4{width:98px;height:23px;background-repeat:no-repeat;background-position:top left;background-image:url('/dynamicimage/navigation');background-position:-313px -0px;}
.navImg4:hover{width:98px;height:23px;background-repeat:no-repeat;background-position:top left;background-image:url('/dynamicimage/navigation');background-position:-313px -23px;}

How can I apply this to a YUI menu?

So far I've applied the navImg0, navImg1 etc. styles to the buttons.

They come up in the right position but with a few problems:

  • there are lines between the items and i need to ideal way to remove them
  • when i rollover the button the correct rollover works, but then if i roll off the menu and onto the main part of the screen the button disappears
  • the <a> tags under the <li> for each of the top level items doesnt work (theres no text inside anymore).

They have a lot of documentation about applying CSS but I couldn't find any examples of how to use CSS Sprites as images.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

活泼老夫 2024-07-23 17:34:58

您能提供一个您所遇到的问题的实例吗? 仅根据 CSS 片段很难进行调试。

与你的问题无关,但你可以让你的CSS更小& 通过组合每次重复的规则,更容易维护。 就像是

.navImg0, 
.navImg0:hover, 
.navImg1, 
.navImg1:hover, 
.navImg2, 
.navImg2:hover, 
.navImg3, 
.navImg3:hover, 
.navImg4, 
.navImg4:hover { background: url('/dynamicimage/navigation') no-repeat top left; }


.navImg0{width:61px;height:23px;background-position:-0px -0px;}
.navImg0:hover{width:61px;height:23px;background-position:-0px -23px;}
.navImg1{width:75px;height:23px;background-position:-65px -0px;}
.navImg1:hover{width:75px;height:23px;background-position:-65px -23px;}
.navImg2{width:96px;height:23px;background-position:-144px -0px;}
.navImg2:hover{width:96px;height:23px;background-position:-144px -23px;}
.navImg3{width:65px;height:23px;background-position:-244px -0px;}
.navImg3:hover{width:65px;height:23px;background-position:-244px -23px;}
.navImg4{width:98px;height:23px;background-position:-313px -0px;}
.navImg4:hover{width:98px;height:23px;background-position:-313px -23px;}

Can you provide a live example of the problems you're seeing? Tough to debug just based off of your CSS snippet.

Not related to your problem, but you could make your CSS smaller & easier to maintain by combining the rules that are repeated every time. Something like

.navImg0, 
.navImg0:hover, 
.navImg1, 
.navImg1:hover, 
.navImg2, 
.navImg2:hover, 
.navImg3, 
.navImg3:hover, 
.navImg4, 
.navImg4:hover { background: url('/dynamicimage/navigation') no-repeat top left; }


.navImg0{width:61px;height:23px;background-position:-0px -0px;}
.navImg0:hover{width:61px;height:23px;background-position:-0px -23px;}
.navImg1{width:75px;height:23px;background-position:-65px -0px;}
.navImg1:hover{width:75px;height:23px;background-position:-65px -23px;}
.navImg2{width:96px;height:23px;background-position:-144px -0px;}
.navImg2:hover{width:96px;height:23px;background-position:-144px -23px;}
.navImg3{width:65px;height:23px;background-position:-244px -0px;}
.navImg3:hover{width:65px;height:23px;background-position:-244px -23px;}
.navImg4{width:98px;height:23px;background-position:-313px -0px;}
.navImg4:hover{width:98px;height:23px;background-position:-313px -23px;}
铁轨上的流浪者 2024-07-23 17:34:58

1:听起来像是边距/填充问题。 检查 ali 标签上的边距和填充。

2:我从来没有听说过回滚时会发生这种情况。 您使用的图像是动态的吗? 在 CSS 中,看起来您正在使用一些服务器端代码动态创建它。 这可能是问题所在,也可能是某种缓存问题。 没有把握。

3:您的精灵表中显示的内容是否已有文本? 通常这就是它在精灵表中的工作方式,因此您通常会隐藏文本。 如果您仍然需要此文本,请检查某些将 a 标记设置为 display: none 的 css。 它也可能在 YUI javascript 中,我对 YUI 不是很熟悉。 ;)

1: Sounds like a margin/padding issue. Check the margin and padding on the a and li tags.

2: I've never heard of this happening when it rolls back. Is the image you're using dynamic? In the css, it looks like you're creating it on the fly with some server side code. This could be the problem, or possibly a cache issue of some sort. Not sure.

3: Does your spritesheet have the text already on what's shown? Usually that's how it's works in a spritesheet, and you generally hide the text because of this. If you still want this text, check for some css that sets the a tags to display: none. It may also be in the YUI javascript, I'm not terribly familiar with YUI. ;)

说好的呢 2024-07-23 17:34:58

我有几个使用精灵的 YUI 菜单,但这有点棘手。

如果您从标记构建,则很简单 - 只需在锚标记中添加 css 类名称即可。 如果您从 JavaScript 构建菜单,则必须在渲染菜单后添加该类。

YAHOO.util.Dom.addClass(theAnchorElemnt, 'the-sprite-css-class');

尽管 YUI 提供了类名配置属性,但它不是您想要的。 您需要在锚点处应用精灵。

希望有帮助。

I have several YUI menus that use sprites, but it's a bit tricky.

If you're building from markup, it's easy - just add your css class names in the anchor tag. If you're building your menus from javascript, you have to add the class after you render the menu.

YAHOO.util.Dom.addClass(theAnchorElemnt, 'the-sprite-css-class');

Even though YUI provides a classname configuration property it's not the one you want. You need to apply the sprites at the anchor.

Hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文