Noob question about aligning divs in PHp

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
Xaos
Posts: 940
Joined: Wed Jan 11, 2012 4:01 am

Noob question about aligning divs in PHp

Post by Xaos »

So, I have this code

Code: Select all

             for($i=0;$i <= $stock; $i++){     //creates a loop that checks versus stock
            if($i % 25 == 0){    //break every 25 Fs
              echo "</br>";
            }
            echo "F";          //echo F to symbolize number of fish, will be reproduced by graphic so
          } 
and I want to put all of the Fs (which will be graphics eventually)on one side of the page, so logically they need to be put into a div and be manipulated with CSS. But the question is....how do I make this happen? Thanks guys :D
User avatar
Gunner
Posts: 276
Joined: Sun Aug 14, 2011 12:07 am

Re: Noob question about aligning divs in PHp

Post by Gunner »

Just make it like this

Code: Select all

echo "<div align='center'>" . "F" . "</div>"
Or did I get your question wrong?
Skype: mrvictordiaz
User avatar
Xaos
Posts: 940
Joined: Wed Jan 11, 2012 4:01 am

Re: Noob question about aligning divs in PHp

Post by Xaos »

Gunner wrote:Just make it like this

Code: Select all

echo "<div align='center'>" . "F" . "</div>"
Or did I get your question wrong?
Duh, now I feel dumb :D But now that I did that, all of the fish are lining up in a line, like so http://gyazo.com/d9630c4b67ec38f48b9f2e415cff7f81 when they should really be in blocks, like so http://gyazo.com/6b646e0d5aea2227bf9332ec39d2222e

Also, how would I get them in-line wth the text? IE the block of fish starting at the top of the page on the right? Do I just use CSS? How do I call the CSS in PHP, just include orrr?
User avatar
Script47
Posts: 147
Joined: Thu Nov 21, 2013 6:11 pm

Re: Noob question about aligning divs in PHp

Post by Script47 »

Xaos wrote:
Gunner wrote:Just make it like this

Code: Select all

echo "<div align='center'>" . "F" . "</div>"
Or did I get your question wrong?
Duh, now I feel dumb :D But now that I did that, all of the fish are lining up in a line, like so http://gyazo.com/d9630c4b67ec38f48b9f2e415cff7f81 when they should really be in blocks, like so http://gyazo.com/6b646e0d5aea2227bf9332ec39d2222e

Also, how would I get them in-line wth the text? IE the block of fish starting at the top of the page on the right? Do I just use CSS? How do I call the CSS in PHP, just include orrr?
Put a line break after the "F" like so:

Code: Select all

echo "<div align='center'>" . "F<br/>" . "</div>"
It may work I'm not sure. :)
User avatar
Xaos
Posts: 940
Joined: Wed Jan 11, 2012 4:01 am

Re: Noob question about aligning divs in PHp

Post by Xaos »

I put the stuff in divs and tried to use a CSS, but it made it so it pushed it all the way to the right of the page and only showed 1 fish per row, all lined up in a column, like this:

Text X
X


when it should be like


Text XXXXXXX


and etc.
User avatar
mahks
Posts: 50
Joined: Fri Nov 22, 2013 11:07 am

Re: Noob question about aligning divs in PHp

Post by mahks »

Code: Select all

for($i=0;$i <= $stock; $i++){     //creates a loop that checks versus stock
     echo '<div class="fish_pic '
          .(($i % 25 == 0)? 'fish_brk':'')
          .'"></div>';
}
CSS:
.fish_pic{float:left;background:url(url_to_fish)}
.fish_brk{clear:left}
Image
Diplomacy, Trade & Conquest in the 4th Millenium

http://www.starlords3k.com
User avatar
Xaos
Posts: 940
Joined: Wed Jan 11, 2012 4:01 am

Re: Noob question about aligning divs in PHp

Post by Xaos »

User avatar
MikuzA
Posts: 394
Joined: Thu Aug 08, 2013 8:57 am

Re: Noob question about aligning divs in PHp

Post by MikuzA »

Code: Select all

<style>
div {display:inline}
</style>
<div>Fish</div>
<div>Fish</div>
<div>Fish</div>
This you looking for? :)
Why so serious?

Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
User avatar
mahks
Posts: 50
Joined: Fri Nov 22, 2013 11:07 am

Re: Noob question about aligning divs in PHp

Post by mahks »

HTML should look like this:
http://jsfiddle.net/mahks/FrY4J/
Image
Diplomacy, Trade & Conquest in the 4th Millenium

http://www.starlords3k.com
User avatar
Xaos
Posts: 940
Joined: Wed Jan 11, 2012 4:01 am

Re: Noob question about aligning divs in PHp

Post by Xaos »

I have this:

Code: Select all

                    for($i=0;$i <= ($stock/5); $i++){

            if($i % 45 == 0){
              echo '<div class="fish_brk">';
              echo "</br></div>";
            }
            echo '<div class ="fish_pic">';
            echo '<img src = "smallfish.png"></div>';
          }
 
in the PHP file and

Code: Select all

.fish_pic{
  float:right;
  background:url(url_to_fish)
  }
.fish_brk{
  clear:right
  }
for the CSS.
Post Reply

Return to “Beginner Help and Support”