ASP.Net,母版页:每页样式表
这些是我的假设,这些正确吗?
- 使用 CSS 进行布局优于 使用表格。
- CSS 应提取到单独的文件中,而不是内联。
- CSS 是从 site.master 中导入(链接)的,因此所有 .css 都会导入(并应用于)所有 .aspx 页面。
鉴于此,我有一个包含一个母版页和两个 .aspx 页面的项目。每个页面都有一个 id 为“records”的表。
问题:我可以为每个单独的 .aspx 页面导入 .css 文件吗?
有没有更好的方法来在单页内范围 html 元素?
Those are my assumptions, are these correct?
- Layout using CSS is preferred over
using tables. - CSS ishould be extracted in a separate file, rather than in-lined.
- CSS are imported (linked) from that is located in the site.master, therefore all .css are imported for (and apply to) all .aspx pages.
Given that, I have a project with one master page, and two .aspx pages. Each of those pages has a table with id "records".
Question: Can I import a .css file for each individual .aspx page?
Is there a better way to scope html elements within single page?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
除了实际呈现表格(例如表格数据,如电子表格或网格)之外,CSS 在所有方面都优于表格。尽管有一些奇怪的情况,表格是跨浏览器实现某些效果的唯一方法。主要是——除非你不能使用CSS,否则总是使用CSS。然后使用表格:)
对于你的第一个问题 - 当然你可以在单独的页面上包含 CSS 文件。您甚至可以使用占位符来做到这一点:
为了将样式范围限定到页面级别,我经常在
标记上放置一个类:
然后在 CSS 中我可以定位应该不同的特定项目页:
CSS is preferred over tables for everything except actually presenting A Table (e.g. tabular data, like a spreadsheet or a grid). Although there are a few weird cases where tables are the only way to accomplish some effects cross-browser. Mainly - always use CSS except when you can't. Then use tables :)
To your first question - of course you can include CSS files on the individual page. You can even do it using placeholders:
To scope styles to the page level, I often put a class on the
<body>
tag:Then in CSS I can target specific items that should be different on that page:
如果是表格数据 - 使用表格,而不是 CSS。 CSS 用于整体页面布局和各个元素的样式 - 您通常希望在许多页面上保持一致。
当人们说“使用 CSS 而不是表格”时,他们的意思是不使用表格来进行整体页面布局(例如页面上的菜单、页眉、页脚和内容所在的位置),而是使用表格来进行布局。实际表格^^
If it's tabular data - use tables, not CSS. CSS is used for overall page layout and the styling of individual elements - something you usually want consistent over many pages.
When people say "use CSS instead of tables" they mean it in a sense of not using tables for the overall page layout (like where the menu, the header, the footer and the content on the page is located) but to use tables for actual tables ^^
设置主题。作为主题一部分的 css 文件将自动导入。
因此,您的每个页面都有一个主题,您可以在内容页面的标记中指定该主题。您定义的每个主题文件夹都将具有适当版本的样式表。如果您不想维护多余的 css 声明,可以将它们分离到另一个文件中并将其链接到主题之外。
set up themes. a css file as part of a theme will get imported automatically.
so, you'd have a theme for each of your pages, which you can specify in the markup of your content page. each of the theme folders you define would have an appropriate version of your stylesheet. if you don't want to maintain redundant css declarations, you can separate those into another file and link it outside the themes.
如果您在母版页中为文档的头部留下内容部分,那么您可以手动链接到不同的 css 文件;但是为什么不为想要以不同方式显示的项目指定不同的类和 id,并将这些类和 id 放在同一个 css 文件中呢?
而不是
在母版页文件上执行以下操作。
因此,您可以这样做:然后将不同的 css 文件放入文档头部的新内容占位符中,
if you leave a content section for the head of your document in your master page, then you can manually link to different css files; but why don't you just specify different classes and ids for the items that you want to appear differently and have those classes and ids in the same css file?
so instead of something like:
on your master page file, you can do this:
and then put the different css files in that new content place holder in the head of your document.
让我们看看您的假设。所有这些通常都是正确的,但值得仔细研究:
1) 使用 CSS 布局优于使用表格。
有点像。更准确的说法是语义布局与非语义布局,CSS是完成语义布局的常规手段。不同之处在于,有时仅使用语义上适当的结构来完成所需的布局是不可能的。我打算为此吃掉它,但是当面对一大堆不属于的额外 div 标签与单个表格之间的选择时,表格可能是更好的选择。
2)CSS应该被提取到一个单独的文件中,而不是内联
排序的。 高级 CSS 应该放在同一个文件中。但您不一定希望整个网站的所有样式都放入同一个文件中,因为这意味着始终具有只能在单个页面上使用的可用样式。而且您也不一定希望每个页面都必须下载主 CSS 文件及其自己的 CSS 文件,因为提高站点性能的方法之一是减少所需的总 http 请求数。因此,您需要考虑某种平衡行为。
3) CSS 是从 site.master 中导入(链接)的,因此所有 .css 都会导入(并应用于)所有 .aspx 页面。
有点像。 CSS 文件通常链接到页面的头元素。放置内容的最简单方法就是在母版页中对其进行硬编码。但如果您确实愿意,可以从内容页面修改页面的 head 元素。
Let's look at your assumptions. All of them are generally correct, but it's worth taking a closer look:
1) Layout using CSS is preferred over using tables.
Sort of. It would be more accurate to say that it's semantic layout vs non-semantic layout, and CSS is the normal means to accomplish the semantic layout. The difference is that sometimes it's just not possible to accomplish the desired layout using only semantically-appropriate structures. I'm gonna eat it for this, but when faced with the choice between a whole bunch of extra div tags that don't belong vs a single table, the table may be the better choice.
2) CSS ishould be extracted in a separate file, rather than in-lined
Sort of. High level CSS should go in the same file. But you don't necessarily want all the styling for the entire site to go into the same file, because that would mean always having styles available that may only be used on a single page. And you also don't necessarily want each page to have to download the main CSS file and it's own css file, since one of the ways to improve performance on a site is to reduce the number of total http requests required. So there's a certain balancing act you need to consider.
3) CSS are imported (linked) from that is located in the site.master, therefore all .css are imported for (and apply to) all .aspx pages.
Sort of. CSS files are typically linked the page's head element. The easiest way to put something in there is just hard code it in the master page. But you can modify the page's head element from a content page if you really want to.