如何在 opencart 主题中为手机和平板电脑添加多个样式表
How to add multiple stylesheets for mobile and tablet in opencart theme
我使用的是默认主题的编辑版本。我想为手机和平板电脑准备多个 css 文件。我在 stylesheet.css 代码
之后的头文件中添加了 mobile.css 和 tablet.css
但是样式表未加载。如果我调整浏览器大小,则不会进行任何更改。
我的 header.tpl 看起来像这样:
<!DOCTYPE html>
<!--[if IE]><![endif]-->
<!--[if IE 8 ]><html dir="<?php echo $direction; ?>" lang="<?php echo $lang; ?>" class="ie8"><![endif]-->
<!--[if IE 9 ]><html dir="<?php echo $direction; ?>" lang="<?php echo $lang; ?>" class="ie9"><![endif]-->
<!--[if (gt IE 9)|!(IE)]><!-->
<html dir="<?php echo $direction; ?>" lang="<?php echo $lang; ?>">
<!--<![endif]-->
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo $title; ?></title>
<base href="<?php echo $base; ?>" />
<?php if ($description) { ?>
<meta name="description" content="<?php echo $description; ?>" />
<?php } ?>
<?php if ($keywords) { ?>
<meta name="keywords" content= "<?php echo $keywords; ?>" />
<?php } ?>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<?php if ($icon) { ?>
<link href="<?php echo $icon; ?>" rel="icon" />
<?php } ?>
<?php foreach ($links as $link) { ?>
<link href="<?php echo $link['href']; ?>" rel="<?php echo $link['rel']; ?>" />
<?php } ?>
<script src="catalog/view/javascript/jquery/jquery-2.1.1.min.js" type="text/javascript"></script>
<link href="catalog/view/javascript/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen" />
<script src="catalog/view/javascript/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<link href="catalog/view/javascript/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<link href="//fonts.googleapis.com/css?family=Open+Sans:400,400i,300,700" rel="stylesheet" type="text/css" />
<link href="catalog/view/theme/default/stylesheet/stylesheet.css" rel="stylesheet">
<link href="catalog/view/theme/default/stylesheet/mobile.css" rel="stylesheet">
<?php foreach ($styles as $style) { ?>
<link href="<?php echo $style['href']; ?>" type="text/css" rel="<?php echo $style['rel']; ?>" media="<?php echo $style['media']; ?>" />
<?php } ?>
<script src="catalog/view/javascript/common.js" type="text/javascript"></script>
<?php foreach ($scripts as $script) { ?>
<script src="<?php echo $script; ?>" type="text/javascript"></script>
<?php } ?>
<?php echo $google_analytics; ?>
</head>
谢谢
要根据屏幕宽度调整显示大小,您必须使用:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link re`l="stylesheet" href="main.css" media="screen>
<link rel="stylesheet" href="mobile.css" media="screen and (max-width: 640px)">
在此示例中,在所有情况下都使用 main.css,当屏幕低于 640px 时将应用 mobile.css
(如果需要,您可以添加另一个以降低分辨率)
在您的代码中,移动 css 应该一直应用,所以也许您应该使用浏览器控制台检查链接是否良好...
并检查您是否没有在
中覆盖您的 css
<?php foreach ($styles as $style) { ?>
<link href="<?php echo $style['href']; ?>" type="text/css" rel="<?php echo $style['rel']; ?>" media="<?php echo $style['media']; ?>" />
<?php } ?>
创建 opencart 主题
- http://code.tutsplus.com/tutorials/create-a-custom-theme-with-opencart-introduction--cms-21786
- http://code.tutsplus.com/tutorials/create-a-custom-theme-with-opencart-part-two--cms-21865
- http://code.tutsplus.com/tutorials/create-a-custom-theme-with-opencart-part-three--cms-21890
- http://code.tutsplus.com/tutorials/create-a-custom-theme-with-opencart-part-four--cms-21932
清除opencart缓存:
- 图像缓存位于 public_html/image/cache
- 如果你有 vqmod public_html/vqmod/vqcache
- 系统缓存public_html/system/cache
不要只删除缓存文件夹中的内容。
我使用的是默认主题的编辑版本。我想为手机和平板电脑准备多个 css 文件。我在 stylesheet.css 代码
之后的头文件中添加了 mobile.css 和 tablet.css但是样式表未加载。如果我调整浏览器大小,则不会进行任何更改。
我的 header.tpl 看起来像这样:
<!DOCTYPE html>
<!--[if IE]><![endif]-->
<!--[if IE 8 ]><html dir="<?php echo $direction; ?>" lang="<?php echo $lang; ?>" class="ie8"><![endif]-->
<!--[if IE 9 ]><html dir="<?php echo $direction; ?>" lang="<?php echo $lang; ?>" class="ie9"><![endif]-->
<!--[if (gt IE 9)|!(IE)]><!-->
<html dir="<?php echo $direction; ?>" lang="<?php echo $lang; ?>">
<!--<![endif]-->
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo $title; ?></title>
<base href="<?php echo $base; ?>" />
<?php if ($description) { ?>
<meta name="description" content="<?php echo $description; ?>" />
<?php } ?>
<?php if ($keywords) { ?>
<meta name="keywords" content= "<?php echo $keywords; ?>" />
<?php } ?>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<?php if ($icon) { ?>
<link href="<?php echo $icon; ?>" rel="icon" />
<?php } ?>
<?php foreach ($links as $link) { ?>
<link href="<?php echo $link['href']; ?>" rel="<?php echo $link['rel']; ?>" />
<?php } ?>
<script src="catalog/view/javascript/jquery/jquery-2.1.1.min.js" type="text/javascript"></script>
<link href="catalog/view/javascript/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen" />
<script src="catalog/view/javascript/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<link href="catalog/view/javascript/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<link href="//fonts.googleapis.com/css?family=Open+Sans:400,400i,300,700" rel="stylesheet" type="text/css" />
<link href="catalog/view/theme/default/stylesheet/stylesheet.css" rel="stylesheet">
<link href="catalog/view/theme/default/stylesheet/mobile.css" rel="stylesheet">
<?php foreach ($styles as $style) { ?>
<link href="<?php echo $style['href']; ?>" type="text/css" rel="<?php echo $style['rel']; ?>" media="<?php echo $style['media']; ?>" />
<?php } ?>
<script src="catalog/view/javascript/common.js" type="text/javascript"></script>
<?php foreach ($scripts as $script) { ?>
<script src="<?php echo $script; ?>" type="text/javascript"></script>
<?php } ?>
<?php echo $google_analytics; ?>
</head>
谢谢
要根据屏幕宽度调整显示大小,您必须使用:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link re`l="stylesheet" href="main.css" media="screen>
<link rel="stylesheet" href="mobile.css" media="screen and (max-width: 640px)">
在此示例中,在所有情况下都使用 main.css,当屏幕低于 640px 时将应用 mobile.css (如果需要,您可以添加另一个以降低分辨率)
在您的代码中,移动 css 应该一直应用,所以也许您应该使用浏览器控制台检查链接是否良好...
并检查您是否没有在
中覆盖您的 css<?php foreach ($styles as $style) { ?>
<link href="<?php echo $style['href']; ?>" type="text/css" rel="<?php echo $style['rel']; ?>" media="<?php echo $style['media']; ?>" />
<?php } ?>
创建 opencart 主题
- http://code.tutsplus.com/tutorials/create-a-custom-theme-with-opencart-introduction--cms-21786
- http://code.tutsplus.com/tutorials/create-a-custom-theme-with-opencart-part-two--cms-21865
- http://code.tutsplus.com/tutorials/create-a-custom-theme-with-opencart-part-three--cms-21890
- http://code.tutsplus.com/tutorials/create-a-custom-theme-with-opencart-part-four--cms-21932
清除opencart缓存:
- 图像缓存位于 public_html/image/cache
- 如果你有 vqmod public_html/vqmod/vqcache
- 系统缓存public_html/system/cache
不要只删除缓存文件夹中的内容。