php - 每个/其他 CSS 技术

标签 php html css wordpress event-handling

我正在创建一个包含 4 个不同部分的页面。每个部分都有一个响应图像,图像上有文本和一些按钮。现在它们有点偏离中心并向右对齐。我正在努力实现,以便第一个 div 文本和按钮向右浮动,第二个 div 文本和按钮向左浮动等等。我正在使用 even odd nth 属性,但它只响应 even css nth 属性。这是CSS和html。请记住,我现在只是使用背景颜色作为示例,如果我让它工作,我会放入 float 和填充。

    .popup-open:nth-child(odd) {
   background: #ff0000;
    }

    .popup-open:nth-child(even) {
    background: #000000;
    }

    <div class="popup-open">
            <div class="icons-large">

                                <?php 

                                $fields = CFS()->get('icons_large');

                                if($fields) :
                                    foreach ($fields as $field) : ?>
                                    <div class="row">
                                            <div class="image">
                                                <img src="<?php echo $field['icons_big'];?>" alt="">
                                            </div>
                                    </div>

                                <?php endforeach; endif; ?>

                            </div>
            <div class="icons-large">

                                <?php 

                                $fields = CFS()->get('tour_titles');

                                if($fields) :
                                    foreach ($fields as $field) : ?>

                                                <?php echo $field['tour_name'];?>

                                <?php endforeach; endif; ?>

                            </div>
            <div class="title"><?php the_title(); ?></div>
            </div>

最佳答案

我认为您应该向 div 添加一个类并以这种方式定位它们,您也将对其进行更多控制。

    if($fields) :
$i = 1;
  foreach ($fields as $field) :

if($i === 2){
 $class = "even";
 $i = 1;
}else if($i === 1){
    $class = "odd";
 $i = 2;
}
<div class="row <?=$class;?>">
<div class="image">
<img src="<?php echo $field['icons_big'];?>" alt="">

</div>
</div>
<?php endforeach; endif; ?>

关于php - 每个/其他 CSS 技术,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33792406/

相关文章:

php - 如何在 Doctrine 中使用 "comment out"注释条目

javascript - 是否可以使用blade 将参数传递给tinymce.init 函数?

javascript - 如何用js替换html中特定属性中的括号?

php - 尝试使用 php 检查 html 文本框是否为空

php - 防止在 laravel 中重新提交后路由

php - 用 PHP 抓取一个网站,然后用 jQuery 遍历它

jQuery 无缝轮播

css - 使用 CSS 向我的工具提示添加底部小箭头

Safari 6.1/7.0 中文本居中对齐的 CSS 字间距问题

css - Firefox 和 Safari 的边距