使用css的if循环的php语法有问题
我不是一个很好的程序员,我的技术主要包括复制粘贴和编辑,直到它工作 我在index.php中为joomla 2.5站点编写了这段代码,该站点只在主页上输出特定的css样式使用css的if循环的php语法有问题,php,syntax,Php,Syntax,我不是一个很好的程序员,我的技术主要包括复制粘贴和编辑,直到它工作 我在index.php中为joomla 2.5站点编写了这段代码,该站点只在主页上输出特定的css样式 <?php $app = JFactory::getApplication(); $menu = $app->getMenu(); ?> <?php if ($menu->getActive() == $menu->getDefault()): ?> <style type="t
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu(); ?>
<?php if ($menu->getActive() == $menu->getDefault()): ?>
<style type="text/css">
#contentonderaan {min-height: 462px;}
</style>
<?php endif; ?>
#contentonderaan{最小高度:462px;}
这工作正常,但现在我想对所有不是主页的页面使用一个“else”语句,以提供一个备用的最小高度css。这应该很容易吧?然而,我的语法有点问题,因为我无法让它工作。那么应该如何写呢?谢谢您的无效语法是什么 它应该是一个
,否则:
<style type="text/css">
<?php if ($menu->getActive() == $menu->getDefault()): ?>
#contentonderaan {min-height: 462px;}
<?php else: ?>
#contentonderaan {min-height: YOUR_HEIGHTpx;}
<?php endif; ?>
</style>
#contentonderaan{最小高度:462px;}
#contentonderaan{min height:YOUR_HEIGHTpx;}
#contentonderaan{最小高度:462px;}
还有别的事
您可以使用大括号:
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu();
?>
<?php if ($menu->getActive() == $menu->getDefault()){ ?>
<style type="text/css">
#contentonderaan {min-height: 462px;}
</style>
<?php }else{ ?>
<!-- foo -->
<?php } ?>
#contentonderaan{最小高度:462px;}
为了便于阅读,请使用速记语法:
<style type="text/css">
<?php if ($menu->getActive() == $menu->getDefault()): ?>
#contentonderaan {min-height: 462px;}
<?php else: ?>
#contentonderaan {min-height: 642px;}
<?php endif; ?>
</style>
#contentonderaan{最小高度:462px;}
#ContentOnDelaan{最小高度:642px;}
#contentonderaan{最小高度:462px;}
#contentOnDelaan{min height:100px;}//给出最小高度
快乐编码:)是标签给我带来了php方面的麻烦。我想试试这样的东西:#contentonderaan{min height:300px;}@joskevermeulen不,我是说你用
其他试试?对不起,我也按了回车键early@joskevermeulen啊好的。。。它只是一个:
而不是代码>但其余的都很好;)谢谢。在整个if语句中添加标签确实可以解决我的问题。我认为只有css语句应该在这些标记中。。。没有任何if循环
,只有if条件
。哈哈,你说得对。它确实让这个问题看起来很无聊:)谢谢,你的第一个解决方案真的让我更了解php!但是:在第二个例子中究竟做了什么?没有什么区别:都是关于语法:if(x){some;}else{another;}
与if(x):some是一样的;其他:另一个;endif代码>检查:我以前去过那个网站,当时没有什么意义。不过你的解释很好,谢谢,我想我现在明白了…谢谢你!一个简短的问题,你给出的答案几乎与bwoebi完全相同,但他使用了“else:”,而你只使用了“else”。这里有什么不同?两者都一样,只是风格不同而已。我们可以使用:或{}覆盖块中的语句集。哦,好的,但是你不需要把{}放在你的else语句后面吗?因为您没有使用“:”@joskevermeulen:因为它只是else块中的一个语句,“{}”花括号是不需要的。这看起来确实好多了。在我的情况下,这是我让它工作的唯一方法:)
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu(); ?>
<?php if ($menu->getActive() == $menu->getDefault()) { ?>
<style type="text/css">
#contentonderaan {min-height: 462px;}
</style>
<?php } else { ?>
<style type="text/css">
#contentonderaan {min-height: 500px;}
</style>
<?php } ?>
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu(); ?>
<?php if ($menu->getActive() == $menu->getDefault()): ?>
<style type="text/css">
#contentonderaan {min-height: 462px;}
</style>
<?php else: ?>
<style type="text/css">
#contentonderaan {min-height: 500px;}
</style>
<?php endif; ?>
<style type="text/css">
<?php if ($menu->getActive() == $menu->getDefault()): ?>
#contentonderaan {min-height: 462px;}
<?php else: ?>
#contentonderaan {min-height: 642px;}
<?php endif; ?>
</style>
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu(); ?>
<style type="text/css">
<?php if ($menu->getActive() == $menu->getDefault()): ?>
#contentonderaan {min-height: 462px;}
<?php else?>
#contentonderaan {min-height: 100px;} //giving min height
<?php endif; ?>
</style>