Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Create 4 <div> below each other in php

Posted on 2016-08-06
2
Medium Priority
?
84 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 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

886 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