Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do you style your PHp with CSS??

    i hope some one can help me...

    im a bit lost on how the hell you add css styling into the PHP page?? Ive got an external link to the css..but im not quite sure exactly WERE in the code i place the CSS??

    Like how would i style this simple table that i have on my page??


    <table width="400" border="1" cellspacing="0" cellpadding="5">
    <?php do { ?>
    <tr>
    <td rowspan="2"><img src="<?php echo $row_rs_index['image']; ?>" /></td>
    <td><?php echo $row_rs_index['title']; ?></td>
    <td><?php echo $row_rs_index['author']; ?></td>
    </tr>
    <tr>
    <td colspan="2"><?php echo $row_rs_index['review']; ?></td>
    </tr>
    <?php } while ($row_rs_index = mysql_fetch_assoc($rs_index)); ?>
    </table>



    i know its probably realy simple!! but im stuck..and all the php code is confusing me (lol)


    thanx guys!!

  • #2
    Regular Coder xconspirisist's Avatar
    Join Date
    Jun 2006
    Location
    Great Britain.
    Posts
    138
    Thanks
    1
    Thanked 6 Times in 6 Posts
    You are using 3 different languages.

    That code you pasted is HTML and CSS. I suggest in the future you use CODE tags when pasting code.

    Add this line to the top of your page header.

    Code:
    <!-- doctype !-->
    
    <head>
        <title><!-- title !--></title>
        <link rel = "stylesheet" href = "style.css" type = "text/css" />
    </head>
    
    <body>
    --- rest of your page ---
    You will then need to learn CSS, and create a new file called "style.css".

    Something to get you started:

    Code:
    table {
        background-color: red;
    }
    
    tr {
        background-color: blue;
    }
    
    td {
        background-color: green;
        color: white;
    }

  • #3
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i dont understand?? maybe i didint explain myself very well...

    i alredy KNOW CSS...and alredy have a linked style sheet...the bit im unsure about is were abouts in the HTML do i put classes and ids and divs for styling?? I know in a normal page i would for example just give the <td> a id...and style that specific <td> BUT with all the extra PHP code in there i am unsure were to place them?

    does that make sense??

  • #4
    Regular Coder xconspirisist's Avatar
    Join Date
    Jun 2006
    Location
    Great Britain.
    Posts
    138
    Thanks
    1
    Thanked 6 Times in 6 Posts
    Is this what you mean?

    Code:
    <td class = "one"><?php echo $row_rs_index['title']; ?></td>
    <td class = "two"><?php echo $row_rs_index['author']; ?></td>
    Reference them like this:

    Code:
    td.one {
        background-color:red;
    }
    
    td.two {
        background-color: blue;
    }

  • #5
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yeah!! the only reason i ask were to place them is because some one else told me to move the all php and place the styling inside divs AROUND the php. .......But i shall try your way and see......

    i guarantee ill be back with more questions hehe

  • #6
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    The CSS styles the HTML after it has been generated from the PHP and sent to the browser so there is no PHP in the page once the CSS is used.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #7
    Regular Coder
    Join Date
    Jan 2004
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You want to put style information in the <head> area of your page, that would be above the code you posted.

    When working with PHP like that, treat it like any normal HTML page, with all the HTML tiddlybits; PHP never actually shows up on the pages users see, all the users get is the HTML.


    Insert CSS Here.
    <table width="400" border="1" cellspacing="0" cellpadding="5">
    <?php do { ?>
    <tr>
    <td rowspan="2"><img src="<?php echo $row_rs_index['image']; ?>" /></td>
    <td><?php echo $row_rs_index['title']; ?></td>
    <td><?php echo $row_rs_index['author']; ?></td>
    </tr>
    <tr>
    <td colspan="2"><?php echo $row_rs_index['review']; ?></td>
    </tr>
    <?php } while ($row_rs_index = mysql_fetch_assoc($rs_index)); ?>
    </table>


    PHP tags "dissappear" in the final page, and when you were told to put CSS "around" the PHP tags, he meant just not to put them inside the PHP code itself.

    Good<?php Not so Good ?>Good
    Last edited by Raraken; 06-22-2006 at 02:29 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •