将不同的层叠样式表应用于相同的html页面 [英] Applying different Cascade Style Sheets to the same html page
问题描述
谢谢
如果您可以使用像PHP这样的服务器端语言,我会这样做:
< ?php
$ allowed_stylesheets = array(red,white,blue,green,mobile);
$ default_stylesheet =red;
$ stylesheet =
(in_array($ _ GET [stylesheet])?$ _GET [stylesheet]:$ default_stylesheet);
?>
< link rel =stylesheettype =text / csshref =<?php echo $ stylesheet;?>>
然后你可以调用你的页面,并像下面这样切换样式表:
www.example.com/page.php?stylesheet=mobile
$ p $请注意,要在PHP中运行
.html
页面,可能需要某些服务器设置,默认情况下只有
code> .php 页面在PHP中解析。根据你的情况,这可能比它的价值太麻烦。但是,我不知道任何纯HTML样式表可靠切换。
另外,这样,您每次打电话时都必须重复样式表命令这一页。
To apply a CSS to an existing html page I need to add a link that links to the css file, I am asked to include a link in the webpage that I am building that would link to the same html page but with a different css file, I am thinking I need to create a different css file, then create another .html page by copy the exact content from the first page and only change the link of the css file, but it doesn't seem so efficient and I am assuming there should be a standard method to do this.
thanks
解决方案If you can use a server-side language like PHP, I would do it something like this:
<?php $allowed_stylesheets = array("red", "white", "blue", "green", "mobile"); $default_stylesheet = "red"; $stylesheet = (in_array($_GET["stylesheet"]) ? $_GET["stylesheet"] : $default_stylesheet); ?> <link rel="stylesheet" type="text/css" href="<?php echo $stylesheet; ?>">
you would then be able to call your page, and switch the style sheet like so:
www.example.com/page.php?stylesheet=mobile
note that to make a
.html
page run in PHP, there is probably some server setup necessary, by default only.php
pages are parsed in PHP. Depending on your situation, that may be too much hassle than it's worth. However, I don't know any pure HTML way of switching style sheets reliably.Also, this way, you will have to repeat the style sheet command every time you call the page.
这篇关于将不同的层叠样式表应用于相同的html页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!