ASP.NET 仅声明一次 CSS 样式表
如果我的网站有一个 CSS 样式表,并且只想声明一次,也就是说,不要在每个 aspx 页面上使用以下代码。
<link href="stylesheets/general.css" rel="stylesheet" type="text/css" />
我是否被迫使用 .master 页面?或者还有其他方法可以做到这一点..
if i have a single CSS stylesheet for a website and only want to declare it once, that is, not use the following code on every aspx page..
<link href="stylesheets/general.css" rel="stylesheet" type="text/css" />
Am i forced to use a .master page? or is there another way to do this..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
除了上面提到的之外,还可以使用包含 CSS 的 ASP.Net 主题。母版页将自动包含 css 文件。
http://odetocode.com/articles/423.aspx
in addition to what was mentioned above, use an ASP.Net theme with the CSS in it. The master page will have the css file included automatically.
http://odetocode.com/articles/423.aspx
母版页是您最好的选择。我猜想,一旦你把它放在那里,不久你就会发现很多其他很棒的东西也可以放在那里。
还有其他解决方案,但它们并不那么容易(例如子类页面和注入脚本)。
Master pages are you best bet here. I would guess that once you get that in there, before long you'll find lots of other great things to put in there, too.
There are other solutions, but they're not as easy (e.g. subclass page and inject scripts).
您可以使用所有页面继承的基页并将其加载到其中。除此之外,可能还有一种方法可以通过连接到管道来执行某些操作。 (最后一种方法的示例在这里 https://web.archive.org/web/20211029043851/https://www.4guysfromrolla.com/articles/120308-1.aspx)
You can use a base page that all your pages inherit from and load it in that. Other than that there's probably a way of doing something by hooking into the pipeline. (Example of this last approach here https://web.archive.org/web/20211029043851/https://www.4guysfromrolla.com/articles/120308-1.aspx)