Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 10 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
只是想建议一种(恕我直言)更聪明的方法来制作标志精灵。
这个想法是根据国家 iso2 代码将标志保存在网格中。
第一个字母 ->垂直位置
第二个字母 ->水平位置
示例(对于 16x11px 标志 + 4x4px 间距):
这样我可以在客户端使用非常简单的函数计算标志位置,而不需要 200 多个额外的样式定义。
示例 jQuery 插件:
演示用法:
http://jsfiddle.net/rorkules/TxAhb/
这里是我的标志精灵:
Just wanted to suggest a (imho) smarter way of doing the flags sprite.
The idea is to save the flags in a grid according to the country iso2 code.
1st letter -> vertical position
2nd letter -> horizontal position
Examples (for 16x11px flags + 4x4px spacing):
This way I can calculate the flag location with a very easy function on the client side without the need of 200+ extra style definitions.
Sample jQuery plugin:
Demo Usage:
http://jsfiddle.net/roberkules/TxAhb/
And here my flag sprite:
这很容易。你需要的东西:
请记住,Google 是您的朋友。将成分充分混合,小心地加入一些 javascript,只需 7 行代码即可完成:
这是正在运行的代码< /a>
It's pretty easy. Things you need:
Remember, Google is your friend. Blend the ingredients well, carefully whisk some javascript in, and it's done - in 7 lines of code:
Here's this code in action
正如评论者所提到的,CSS 精灵是这里的正确解决方案。幸运的是,有许多免费的 CSS 标志精灵。 这个看起来相当不错。
我们必须调整下拉代码以适应预制的 CSS 精灵。我已经为你做了这件事。 这是一个现场演示。
languageswitcher.js
languageswitcher.css
我所做的 CSS 更改是 Q&D hack;您可能需要花一些时间来完善它们。我从 languageswitcher.css 中删除了所有特定于标志的内容,因为我们使用 flag16.css。
此外,如果 CSS 精灵中不存在国家/地区代码,则显示的标志将默认为
非洲联盟的旗帜,因为它是精灵中的第一张图像。在演示中,我的示例列表中的几个国家/地区没有精灵图像。小心这一点。
As mentioned by commenters, a CSS sprite is the proper solution here. Fortunately, there are many CSS sprites of flags freely available. This one looks pretty good.
We will have to tweak the dropdown code to accomodate that pre-made CSS sprite. I've gone ahead and done that for you. Here's a live demo.
languageswitcher.js
languageswitcher.css
The CSS changes I made were Q&D hacks; you'll probably want to spend some time polishing them. I removed all of the flag-specific stuff from languageswitcher.css since we're using flag16.css.
Also, if the country code doesn't exist in the CSS sprite, the flag shown will default to the
African Union's flag since it is the first image in the sprite. In the demo, several of the countries in my example list don't have a sprite image. Watch out for that.
这是一个包含国家/地区列表及其国旗链接的文件(尽管有些链接可能无法正常工作,但大多数都可以)
Excel 文件
Here's a file with the list of countries and links to their flags (some of the links might not be working though but most of them are)
Excel File
您还可以使用 http://www.famfamfam.com/lab/icons/flags/ 中的标志 并简单地使用 CSS 来定位适当的标志。
----编辑----
如果我需要显示我的国家的国旗,那么我会从 CSS 进行映射,例如
.np {
背景:url(./flags_preview_large.png) -172px -397px no-repeat;
宽度:14px;
高度:20px;
<代码>}
You can also use flags from http://www.famfamfam.com/lab/icons/flags/ and simply use CSS for positioning the appropriate flag.
----EDITED----
If i need to show flag of my country then i would do mapping from CSS like
<span class='np'></span>
.np {
background: url(./flags_preview_large.png) -172px -397px no-repeat;
width: 14px;
height: 20px;
}