如何在同一页面中有两种不同的样式

时间:2017-05-04 17:34:23

标签: php html css styles

我在循环中有两个 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  ?>

1 个答案:

答案 0 :(得分:0)

您可以为两个单独的div使用不同的类名,但如果您想在不更改现有类名的情况下使用它,请使用内联css。请尝试以下代码:

<?php for ($i = 0; $i < $contador; $i++) { ?>
<!--Here begin the STYLE_1-->
    <div class="content-layout-wrapper layout-item-0" style="margin-bottom: 7px;">
       <div class="content-layout layout-item-1" style=" border-spacing: 10px 0px; border-collapse: separate; ">
         <div class="content-layout-row">
           <div class="layout-cell layout-item-2" style="border-top-style:solid; background: #ffffff;">
             <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" style="color: #083752; background: ;  border-collapse: separate;">
            <div class="content-layout-row">
                 <div class="content-layout layout-item-1" style="color: #083752;">
                       Text #2
                 </div>
                 <div class="layout-cell layout-item-2" style"border-style:Double; border-radius: 15px;">
                     <p>
                      Text #3
                    </p>
                 </div>
            </div>
        </div>
        <div class="content-layout">
             <div class="content-layout-row">
                  <div class="content-layout layout-item-3" style="padding-right: 10px;padding-left: 10px;">
                      <p>Text # 4</p>
                  </div>
             </div>
        </div>
     </div>
<!--Here END the STYLE_2-->

  <?php   } // for i  ?>