Solved

Create 4 <div> below each other in php

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

751 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