我使用什么 CSS 代码来使我的网站在不同的浏览器中呈现?
我正在上大学,并已经完成了第一年的学业。我想继续将网络应用程序作为一种爱好。我已经使用 MS Visual Studio 2010 创建了一个功能正常的 Web 应用程序,但我知道我需要使其与其他浏览器兼容。
我认识到我需要在其他浏览器中对其进行测试并查看出现的差异,但如何修复它们。我的老师说我需要每个浏览器的 CSS 代码,但我该怎么做呢?
预先感谢您的任何帮助
Im at college and have completed my first year. I want to continue web applications as a hobby. I have create a functioning web application with MS Visual Studio 2010, but I know I need to make it compatible with other browsers.
I recognise that I need to test it in other broswers and see the discrepancies that arise, but how do I fix them. My teacher say I need CSS code for each browser, but how do I do this?
Thanks in advance for any help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
包含 CSS 重置样式表。然后,您应该包含默认样式以获得合理的边距和字体大小,然后在其上添加您自己的 CSS。
Include a CSS reset stylesheet. You should then include a default style to get sensible margins and font sizes, then add your own CSS on top of that.
我使用的方法是为我的网站编写 CSS 并仅在 Google Chrome 中进行测试。您也可以使用 Firefox 4。我使用这些浏览器的原因是,如果我的 CSS 在它们中看起来不错,我很确定它符合标准,并且随着新浏览器的出现,它很有可能看起来不错。
然后,我在 IE 中查看我的网站。现在,值得庆幸的是,您不必再担心 IE6。几乎所有人都忽略了它。所以你必须考虑你的观众。您认为大多数人会使用 IE9 还是 IE8?如果您可以使用 IE9,那么几乎可以肯定您的网站无需任何修改即可看起来很棒,因为它是一个非常符合标准的浏览器。如果您需要 IE8 兼容性,请添加另一个 CSS 样式表并使其仅在浏览器为 IE 时才显示。您的标签将如下所示:
因此,现在您可以在该样式表中放置任何样式修复,而不会损害主样式表中的样式。将其保持在绝对最低限度,以便于维护。
顺便说一句,如果它只是一个供您娱乐的网站,请选择您喜欢的浏览器并确保它可以在其中运行。然后只需在底部添加一条消息,说明哪种浏览器最能显示您的网站。
The approach I use is to write the CSS for my site and test it only in Google Chrome. You can use Firefox 4 too. The reason I use these browsers is that if my CSS looks good in them, I'm pretty sure it's standards compliant and has a great chance of looking good as newer browsers come out.
Then, I take a look at my site in IE. Now, thankfully, you don't really have to worry about IE6 any more. Almost everyone's ignoring it. So you have to think about your audience. Do you think most of them would use IE9 or IE8? If you're ok with IE9, then it's almost certain your site looks great without any modifications because it's a very standards compliant browser. If you need IE8 compatibility, then add another CSS stylesheet and make it so it only shows up if the browser is IE. Your tag would look like this:
So now you can put any style fixes in that stylesheet without hurting the style in your main stylesheet. Keep this to the absolute minimum so that it's easy to maintain.
As an aside, if it's just a site for you to have fun with, pick a browser you like and make sure it works in that. Then just put a message at the bottom saying what browser displays your site best.
如果他确实这么说的话,他就错了。如果您知道自己在做什么,那么 99% 的事情都可以按照您想要的跨浏览器方式工作。对于 IE(问题浏览器,通常是“跨浏览器”的定义,您可以使用 条件注释加载针对特定 IE 版本的不同样式表。
人们常见的错误on:
如果您在一种浏览器中遇到问题 (并且该浏览器不是 IE),但它可以在另一个浏览器中运行,很可能(但总是)您在进行任何调试尝试之前,总是,总是 <。 a href="http://validator.w3.org/" rel="nofollow">首先验证您的 html 许多“CSS 问题”实际上是不同浏览器以不同方式响应的 HTML 问题。
然后,我过去发现这个网站很有帮助:
http://dowebsitesneedtolookexactlythesameineverybrowser.com/
He is wrong if that's literally what he said. If you know what you're doing, you can get 99% of everything to work the way you want cross-browser. For IE (the problem browser and usually definition of "cross-browser", you can use conditional comments to load different stylesheets that target specific IE versions.
Common things people trip up on:
If you're having issues in one browser (and that browser is not IE) but it works in another, chances are (but not always) you are making a mistake somewhere. Before any debugging attempts, always, always validate your html first. A lot of "CSS issues" are actually HTML issues that different browsers respond to in different ways.
And then, there's this site that I've found helpful in the past:
http://dowebsitesneedtolookexactlythesameineverybrowser.com/
您可以使用条件注释来定位 IE。
对于其他浏览器,您可以使用供应商前缀属性来显式定位这些浏览器
-moz-
、-webkit-
等。否则,对于非 IE,只需使用符合标准 (x) html,并且在大多数情况下,他们会对此感到满意。You can target IE with conditional comments.
For other browsers you can use vendor-prefixed properties to explicitly target those browsers
-moz-
,-webkit-
etc. Otherwise for non-IE just use standards compliant (x)html and, for the most part, they'll be fine with it.尝试条件样式表/黑客:http://css-tricks。 com/how-to-create-an-ie-only-stylesheet/
Try conditional stylesheets / hacks: http://css-tricks.com/how-to-create-an-ie-only-stylesheet/