1 回答

TA貢獻1789條經驗 獲得超8個贊
您可以有一個變量來控制您的 css 鏈接到樣式表。因此,您為移動設備設置了一個樣式表,為桌面設置了另一個樣式表,當該按鈕發送到服務器發布/請求時,然后將樣式表頁面的 css 鏈接設置為該 CSS 頁面。
例如:
在你的 php 頁面上...
if(isset($_POST['desktop_version'])){
$styleSheet = "desktop.css";
$buttonDisplay = "Switch to mobile version";
$buttonName = "main";
}elseif(isset($_POST['main'])){
$styleSheet = "main.css";
$buttonDisplay = "Switch to desktop version";
$buttonName = "desktop_version";
}else{
// default version when neither instances have been submit yet
$styleSheet = "main.css";
$buttonDisplay = "Switch to desktop version";
$buttonName = "desktop_version";
}
//... in your html head
<link rel="stylesheet" type="text/css" href="<?=$styleSheet?>">
//... in your html body your buttons value is set to the opposite of the set sheet it is using
//... when the style sheet is set to main, the button displays the attributes
//... for the desktop version and when set to desktop it sets the attributes
//... for the main version.
<form method="post">
<button type="submit" name="<?=$buttonName?>" value="<?=$buttonDisplay?>">
</form>
- 1 回答
- 0 關注
- 183 瀏覽
添加回答
舉報