CSS Sprites:表单输入(文本字段)设计问题

发布于 2024-09-16 07:57:15 字数 813 浏览 3 评论 0原文

我希望文本字段中出现国旗。

当所有图标单独保存时,它工作得很好。例如:

#search input[type="text"] {
    background: #FFFFFF url(GB.png) no-repeat right center;
}

<div id="search">
    To: <input name="to" type="text" />
</div>

但是,超过 60 个标志会产生大量可能的 HTTP 请求,因此我将它们放入一个垂直 CSS 精灵图像 (< 25 KB) 中。

问题是,我无法使用 CSS sprites 获得相同的结果(一次只显示一个标志):

#search input[type="text"] {
    background: #FFFFFF url(countries.png) no-repeat right center;
}
.c-GB { background-position: 0 -368px;  } 

<div id="search">
    To: <input name="to" type="text" class="c-GB" />
</div>

屏幕截图(正确和错误)

如果不可能,您会建议其他什么解决方案?每次用户进入不同的位置时,该标志都应该改变。

I want a flag of country to appear in the text field.

It works fine, when all icons are kept separately. For example:

#search input[type="text"] {
    background: #FFFFFF url(GB.png) no-repeat right center;
}

<div id="search">
    To: <input name="to" type="text" />
</div>

However, having more than 60 flags makes a lot of possible HTTP requests, so I put them into one vertical CSS sprite image (< 25 KB).

The problem is, that I can't get the same result (only one flag shown at once) with CSS sprites:

#search input[type="text"] {
    background: #FFFFFF url(countries.png) no-repeat right center;
}
.c-GB { background-position: 0 -368px;  } 

<div id="search">
    To: <input name="to" type="text" class="c-GB" />
</div>

Screenshoots (correct and wrong)

If it's impossible, what other solutions would you suggest? The flag should change each time the user enters a different location.

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

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

发布评论

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

评论(2

憧憬巴黎街头的黎明 2024-09-23 07:57:15

问题是标志太紧密地堆积在一起..将它们垂直地展开一点,以便在上面和下面显示一些透明的内容 - 即,使每个“标志”与文本输入框一样高

the problem is the flags are too tightly packed together .. spread them out a little vertically so that some transparent shows above and below - ie, make each 'flag' as tall as the text input box

箜明 2024-09-23 07:57:15

在制作旗帜精灵时,您可以增加旗帜顶部和底部的“空白空间”。

You could increase the 'blank space' at the top and bottom of your flags when making your flag sprite.

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