Solved

Create 4 <div> below each other in php

Posted on 2016-08-06
2
46 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 30

Accepted Solution

by:
Marco Gasi earned 500 total points
Comment Utility
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
Comment Utility
Thanks
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
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:
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

743 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

14 Experts available now in Live!

Get 1:1 Help Now