Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Create 4 <div> below each other in php

Posted on 2016-08-06
2
Medium Priority
?
79 Views
Last Modified: 2016-08-07
Hello;

I want to create 4 <div> exactly below  each other with 30px margin from  other in a container as below in php with loop,please let me know its codes.
My css are minimum,and maybe you need modify it.
Thanks

<div class="container">
    <div  class="div1">this is div1</div>
    <div  class="div2">this is div2</div>
    <div  class="div3">this is div3</div>
    <div  class="div4">this is div4</div>
</div>

Open in new window


CSS
.container{
   width:600px;
   height:auto;
 }
.div1{
width:600px;
height:200px;
background-color:red;
}
.div2{
width:600px;
height:200px;
background-color:blue;
}
.div3{
width:600px;
height:200px;
background-color:orange;
}
.div4{
width:600px;
height:200px;
background-color:pink;
}

Open in new window

0
Comment
Question by:MOSTAGHASSI
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 2000 total points
ID: 41745976
Try this:

php
<div class="container">
<?php
for ($i=0; $i<4; $i++){
    $counter = $i+1;
    echo '<div id="div$counter" class="div">this is div$counter</div>';
}
?>
</div>

Open in new window


css
.container{
   width:600px;
   height:auto;
 }
.div{
   width:600px;
   height:200px;
   margin: 15px 0;
   display: block;
}
#div1{
   background-color:red;
}
#div2{
   background-color:blue;
}
#div3{
   background-color:orange;
}
#div4{
   background-color:pink;
}

Open in new window

0
 

Author Closing Comment

by:MOSTAGHASSI
ID: 41746111
Thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question