不同的CSS样式的PHP数组第2篇的最后一个元素 [英] Different css styling for last element of a php array Pt.2
问题描述
确定这里是我的新问题,什么我试图完成一个完整的描述。我用你给我的建议,它工作得很好,但是当我改变了ORDER BY信息,以不同的字段和if语句,它疯了。
下面是我需要的,我有一个页面上的两列,当阵列被处理,我需要它来显示结果填写每一列从左到右从上到下。目前各项目之间的分割线
< DIV CLASS =centerBoxContentsFeatured centeredContent回U电源的风格=宽度:50%;>
和各一个项目下
< DIV CLASS =产品-COL取代。
如果该项目是第3,第5,第7,等等...这将是在左侧和前它不需要U电源分区,如果它是最后一个项目(S)它不需要产物-COL下它的div作为最后的2项不必具有底部分频器,但如果它是仅有的两个整页上的项目的底部分频器可以保持。我在做什么错了?
< PHP
$ count_temp =计数($产品ID);
为($ I = 0; $ I< $ count_temp ++ $ I){
$艺术家= get_the_title();
如果(($ productartist [$ i] == $艺术家)及和放大器; $的categoryID [$ i] == 1){
?>
//内容//
<?PHP的IF(($ I === 0)及!&安培;!($ I%2)及和放大器;
($的productid [$ i] == 1)及和放大器;
($ I ===(计数($产品ID) - 1))){
呼应'< DIV CLASS =产品-COL-无>';
}
其他{回声'< DIV CLASS =产品-COL>';}
?>
//内容//
&LT ;?如果($ I ===(计数($产品ID) - 1))!
{
呼应'< DIV CLASS =centerBoxContentsFeatured centeredContent回U电源'。
风格=宽度:50%;>';
}
其他{
呼应'< DIV CLASS =centerBoxContentsFeatured centeredContent回来'。
风格=宽度:50%;>';}
?>
您应该写在这里对你的CSS文件code,你使事情复杂,目前还不清楚你的HTML嵌入PHP code
如果你只是想为你的奇编号(3,5,7 ......)项目不同的风格,不同的风格为您的最后项目,然后我会推荐使用 CSS伪类
您可以使用CSS伪类最后的孩子为你的最后一个项目。
李:最后一个孩子
{
//您的最后一个项目特定的样式放在这里
}
您还可以使用CSS伪类第n个子(奇数)交替奇数项
李:第n个孩子(奇数)
{
//您的奇品特定样式放在这里
}
我希望这是你在找什么,为什么给一个服务器端的负载的时候可以设置的东西在客户最终完成。
Ok here is my new issue, and a complete description of what I am trying to accomplish. I used the suggestions you gave me and it worked fine, but when I changed the ORDER by information to a different field and the if statement, it went crazy.
Here is what I need, I have two columns on a page, when the array is processed I need it to display results filling each column left to right top to bottom. There is a division line between each item
<div class="centerBoxContentsFeatured centeredContent back vLine " style="width:50%;">
and one under each item
<div class="product-col" >.
If the item is the 3rd, 5th, 7th and so on… it will be on the left and does not need the "vLine " div before it and if it is the last item(s) it does not need the "product-col" div under it as the last 2 items do not have to have the bottom divider, but if it is only two items on the whole page the bottom divider can stay. What am I doing wrong?
<?php
$count_temp = count ($productid);
for ($i = 0; $i < $count_temp; ++$i) {
$artist = get_the_title();
if (($productartist[$i] == $artist ) && $categoryID[$i] ==1 ) {
?>
//Content//
<?php if (!($i === 0) && !($i % 2) &&
($productid[$i] == 1) &&
( $i === (count ($productid) - 1))) {
echo'<div class="product-col-none" >';
}
else { echo '<div class="product-col" >';}
?>
//Content//
<? if !( $i === (count ($productid) - 1))
{
echo '<div class="centerBoxContentsFeatured centeredContent back vLine " '.
'style="width:50%;">';
}
else {
echo '<div class="centerBoxContentsFeatured centeredContent back " '.
'style="width:50%;">';}
?>
You should write here about your css file code, you are making things complicated and unclear with your html embedded php code.
If you just want a different style for your odd numbered (3,5,7..) items and a different style for your last item then I'll recommend to use css pseudo classes
You can use css pseudo class last-child for your last item.
li:last-child
{
// Your specific style for last item goes here
}
You can also use css pseudo class nth-child(odd) for alternating odd numbered items
li:nth-child(odd)
{
// Your specific style for odd items goes here
}
I hope this is what you are looking for, Why to give a server side load when you can set things done at client end.
这篇关于不同的CSS样式的PHP数组第2篇的最后一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!