【发布时间】:2017-05-04 17:34:22
【问题描述】:
我在循环中有两个 DIV,我需要将一个样式放在一个 DIV 上。
我不知道我是否可以用 PHP、JS 或 CSS 做到这一点。这是我的代码:
-- 样式(这个样式在同一个页面,因为我有一个通用的样式,我包括在内)--
<?php
$style_1 = '<style>
.content .postcontent-0 .layout-item-0 { margin-bottom: 7px; }
.content .postcontent-0 .layout-item-1 { border-spacing: 10px 0px; border-collapse: separate; }
.content .postcontent-0 .layout-item-2 { border-top-style:solid; background: #ffffff; }
</style>';
$style_2 = '<style>
.content .postcontent-0 .layout-item-0 { color: #083752; background: ; border-collapse: separate; }
.content .postcontent-0 .layout-item-1 { color: #083752; }
.content .postcontent-0 .layout-item-2 { border-style:Double; border-radius: 15px; }
.content .postcontent-0 .layout-item-3 { padding-right: 10px;padding-left: 10px; }
</style>';
?>
-- 视图
<?php for ($i = 0; $i < $contador; $i++) { ?>
<!--Here begin the STYLE_1-->
<div class="content-layout-wrapper layout-item-0">
<div class="content-layout layout-item-1">
<div class="content-layout-row">
<div class="layout-cell layout-item-2">
<p> Text #1 </p>
</div>
</div>
</div>
</div>
<!--Here END the STYLE_1-->
<!--Here begin the STYLE_2-->
<div class="postcontent postcontent-0 clearfix">
<div class="content-layout-wrapper layout-item-0">
<div class="content-layout-row">
<div class="content-layout layout-item-1">
Text #2
</div>
<div class="layout-cell layout-item-2" >
<p>
Text #3
</p>
</div>
</div>
</div>
<div class="content-layout">
<div class="content-layout-row">
<div class="content-layout layout-item-3">
<p>Text # 4</p>
</div>
</div>
</div>
</div>
<!--Here END the STYLE_2-->
<?php } // for i ?>
【问题讨论】:
-
您好,您应该使用 id 或 classname 将 css 分配给 div。
-
你为什么要这样做CSS?您应该为 CSS 代码使用单独的文件。不要在 JS 中这样做
-
这就是问题所在,所有的div都有不同的样式和相同的名称
-
那么如何使用循环提供动态 id 并使用这些 id 你应该以相同的方式分配 css
-
@我总是这样。