使用内联css - 在某些情况下没有或没有? [英] using inline css - a no-no or okay in certain situations?

查看:270
本文介绍了使用内联css - 在某些情况下没有或没有?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

CSS中的内联样式和样式






我正在寻找一些意见。我所有使用CSS样式作为类在一个单独的.css文件。但每一次,在一段时间,我遇到一个场景,我只需要一些特定的元素的填充或改变CSS类的宽度只在一个特定的情况。是否可以在这些方案中添加内联样式?



我的理论是,如果它不是可重用的或不包含超过2个样式,为什么为它创建一个类。


$ b

最好避免内联样式,因为



1)样式表提供了更多的可维护性。



2)更好地分离html数据和布局。



3)样式的可重用性。 p>

4)可能提供更好的缓存。



总的来说,css样式表是最好的做法。

解决方案

这一个的两个答案:



1 )将您的设计(css)和数据(html)分开保存是一种良好做法。通过添加在线样式,它使得更难以修改网站的外观,这使得以后的程序员更难以修改您的网站,并且总的来说不是最好的方式。



如果一切都在一个CSS文件中,那么你可以改变你的网站的整个设计,而不必弄乱网站的数据(HTML)。这是理想的。



2)是的,很多人仍然使用内联样式, 。


Possible Duplicate:
Inline styles vs styles in CSS

i guess i'm looking for some opinions on this. I am all for using css styles as classes in a separate .css file. But every once in a while, i run into a scenario where i need just some padding for a particular element or change the css class' width only in one particular situation. Is it okay to add inline styles in those scenarios? do people do this or always create classes for everything.

My theory would be if its not something reusable or does not contain more than 2 styles, why create a class for it. Am I wrong in thinking that?

Summary of Answers (since there are many)

It is better to avoid inline styles because

1) style sheets provides more maintainability.

2) better separation of html data and layout.

3) re-usability of styles.

4) probably provides better caching.

Overall, css style sheet is the best practice.

解决方案

Two answers to this one:

1) It's considered good practice to keep your design (css) and your data (html) separate. By adding in-line styles, it makes it more difficult to revise the look of a site, it makes it more difficult for future programmers to modify your site, and is overall NOT the best way to go.

If everything is in a CSS file(s), then you can change the entire design of your site without having to mess with the data (HTML) of the site. This is ideal.

2) Yes, a lot of people still use inline styles very often when tweaking something small, regardless of "best practice".

这篇关于使用内联css - 在某些情况下没有或没有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆