Solved

Create 4 <div> below each other in php

Posted on 2016-08-06
2
58 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
2 Comments
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

911 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now