默认 CSS 文件名
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4831660/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Default CSS filename
提问by Alan
for html, we have index.html, the file thats automatically loaded by the webserver if no filenames are specified. Is there an equivalent for css, either from the webserver point of view, or just by convention? surely it's not "index.css" right?
对于 html,我们有 index.html,如果未指定文件名,则由网络服务器自动加载的文件。从网络服务器的角度来看,或者只是按照惯例,css 是否有等价物?肯定不是“index.css”吧?
Thanks.
谢谢。
Update: I guess I phrased my question a little poorly. I already knew that css files would not be loaded automatically. I was just wondering if there was a strong convention for default css files. Although there exists no strong convention, there are common names, as listed by the people who answered, some of which are:
更新:我想我的问题措辞有点糟糕。我已经知道 css 文件不会自动加载。我只是想知道默认 css 文件是否有很强的约定。虽然不存在严格的约定,但有一些常见名称,如回答者列出的那样,其中一些是:
- default.css
- main.css
- web.css
- style.css
- site.css
- 默认.css
- 主文件
- 网页.css
- 样式文件
- 网站.css
Or you can name the css file with the same filename as the html file that uses it.
或者,您可以使用与使用它的 html 文件相同的文件名命名 css 文件。
采纳答案by bdukes
No.
不。
There are common names for the main stylesheet for a site, e.g. site.css or main.css, but no strong (or useful) convention.
站点的主样式表有一些通用名称,例如 site.css 或 main.css,但没有强(或有用)的约定。
回答by LuckyLuke
No there is no such thing. It probably is some "guidelines" to follow when designing templates for e.g. Joomla where you have "template.css" and so on. When I do not have such guidelines I normally name the default css "style.css", but this is a matter of taste.
不,没有这样的事情。在为您拥有“template.css”等的 Joomla 设计模板时,可能需要遵循一些“指南”。当我没有这样的指导方针时,我通常将默认的 css 命名为“style.css”,但这是一个品味问题。
回答by Cookalino
The name style.css
starts to look odd as soon as you have more than one stylesheet. My 2 cents would be:
style.css
一旦您拥有多个样式表,该名称就开始看起来很奇怪。我的 2 美分将是:
main.css
ormyappname.css
(e.g.intranet.css
) for the app- Something like
global.css
for a stylesheet shared between apps - For css for individual pages, create subdirectories named after the pages so that you can easily see which css are shared and which are only used on certain pages
main.css
或myappname.css
(例如intranet.css
)对于应用程序- 类似于
global.css
在应用程序之间共享的样式表 - 对于单个页面的css,创建以页面命名的子目录,以便您可以轻松查看哪些css是共享的,哪些只在某些页面上使用
If you can, I'd recommend keeping it short and all lowercase without underscores / hyphens as it is less prone to typos.
如果可以,我建议保持简短且全部小写,不要使用下划线/连字符,因为它不太容易出现拼写错误。
回答by Daniel Sokolowski
Since stylesheets can be loaded based on media
attribute my file naming convention just follows the available options:
由于可以根据media
属性加载样式表,因此我的文件命名约定仅遵循可用选项:
theme-media-all.css
- used for all media type devicestheme-media-print.css
- used for printerstheme-media-screen.css
- used for computers screens, tablets, phones, etc.theme-media-speech.css
- used for screenreaders
theme-media-all.css
- 用于所有媒体类型设备theme-media-print.css
- 用于打印机theme-media-screen.css
- 用于电脑屏幕、平板电脑、手机等。theme-media-speech.css
- 用于屏幕阅读器
You could omit the media-
prefix but I like to be explicit both for myself years down the line or new developers coming to the project - plus you get filename grouping when sorted alphabetically.
您可以省略media-
前缀,但我喜欢对自己多年后或新加入该项目的新开发人员进行明确 - 此外,按字母顺序排序时,您会得到文件名分组。
回答by Daniel Sokolowski
Can't think of a better default than stylesheet.cssto match the value of the rel
attribute.
想不出比stylesheet.css更好的默认值来匹配rel
属性的值。
<link rel="stylesheet" type="text/css" href="stylesheet.css">
回答by RunnerRick
There is no standard, because it's your HTML that decides which CSS file to reference rather than web server configuration.
没有标准,因为决定引用哪个 CSS 文件的是您的 HTML,而不是 Web 服务器配置。
With that said, it is a good idea to have a convention, so that your files are better organized.
话虽如此,最好有一个约定,以便更好地组织您的文件。
For example, if you tie a CSS file with each file you might re-use the HTML file's name, but with the CSS extension. (e.g. index.html has index.css or index.html.css.)
例如,如果您将一个 CSS 文件与每个文件绑定在一起,您可能会重复使用 HTML 文件的名称,但使用 CSS 扩展名。(例如 index.html 有 index.css 或 index.html.css。)
You could apply the same concept to directories or URL paths if your code is organized that way. (e.g. /MyApp/MyFeature/MyFeature.css).
如果您的代码以这种方式组织,您可以将相同的概念应用于目录或 URL 路径。(例如/MyApp/MyFeature/MyFeature.css)。
It's really up to you to decide, but it is important to be consistent, so others can understand your code more easily.
这真的由您决定,但保持一致很重要,这样其他人就可以更容易地理解您的代码。
Hope this helps.
希望这可以帮助。