簡體   English   中英

Joomla 2.5-為iPad添加自定義CSS

[英]Joomla 2.5 - Add Custom CSS for iPad

在iPad上查看我的joomla網站時,我想加載一個CSS文件。

我正在使用的joomla版本是2.5。

我目前為瀏覽器(例如Internet Explorer和Firefox)設置了樣式表,但不確定如何告訴網站加載專門用於設備(​​例如iPad)的CSS文件。

任何幫助,將不勝感激。

@isher的答案是一個好方法,但是要導入CSS文件,我會使用Joomla編碼標准這樣做:

<?php
$isiPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPad');

if ($isiPad){    
   $doc = JFactory::getDocument(); //only include if line doesn't already exist
   $doc->addStyleSheet (JURI::root() . "template/template-name/ipad-styles.css" );
}
?>

這樣的事情應該做到:

<?php
$isiPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPad');

if $isiPad;    
  echo "<link href='ipad-styles.css' rel='stylesheet' type='text/css'>";
?>

或者,您可以使用此腳本並將其添加到模板或自定義模塊(分配給所有頁面)中:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
jQuery(function($){ 
var userAgent = navigator.userAgent.toLowerCase();
var regex = new RegExp('ipad',"i"); 
if(userAgent.match(regex)){
    $('<link href="css/ipad.css" rel="stylesheet" type="text/css"/>').appendTo($('head'));
}});
</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM