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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    New Coder
    Join Date
    Jan 2011
    Posts
    29
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Echoing styled divs

    I'm trying to echo div tags externally styled, but for some reason they're not doing the job.
    Can anyone clarify for me what been done wrong in my code? The index.php is in the same folder as style.css
    So I really don't know what more I can do to get it to work.

    Thanks!

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="#" />
    <meta name="description" content="#" />
    <link href="style.css" rel="stylesheet" type="text/css" />
    <title>Untitled Document</title>
    </head>
    <body>
    <div id="wrapper">123</div>
    </body>
    </html>
    <?php
    
    echo "<div id='wrapper'>abc</div>"; 
       
    ?>

    style.css

    // stylesheet content

    #wrapper {
    color: red;
    border: 1px solid red;
    }

  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    i don't see any issue here, what exactly is the problem? is the second div in the echo not getting styled?

  • #3
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by tkm76 View Post
    I'm trying to echo div tags externally styled, but for some reason they're not doing the job.
    Can anyone clarify for me what been done wrong in my code? The index.php is in the same folder as style.css
    So I really don't know what more I can do to get it to work.

    Thanks!

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="#" />
    <meta name="description" content="#" />
    <link href="style.css" rel="stylesheet" type="text/css" />
    <title>Untitled Document</title>
    </head>
    <body>
    <div id="wrapper">123</div>
    </body>
    </html>
    <?php
    
    echo "<div id='wrapper'>abc</div>"; 
       
    ?>

    style.css

    // stylesheet content

    #wrapper {
    color: red;
    border: 1px solid red;
    }
    your echo output the content after the document is closed using </html>

    best regards

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Id's should not be replicated. You need to use class when you want multiple tags to apply similar styles, although best I know the actual CSS should still apply.

    As this is currently sitting, this is not a problem with PHP. If the echo itself is not showing up, that would be a PHP problem, but if the tag is there and the style is not applied that is an HTML/CSS issue, not PHP. I'll await the OP to reply with whether this echo is not being produced.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    Quote Originally Posted by oesxyl View Post
    your echo output the content after the document is closed using </html>

    best regards
    yes but in most browser that won't make any difference. just tested in google chrome and the styling works fine after the body/html tags are closed.

  • #6
    New Coder
    Join Date
    Jan 2011
    Posts
    29
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by angst View Post
    i don't see any issue here, what exactly is the problem? is the second div in the echo not getting styled?
    Yes.
    The fonts are default black.
    Should be red.

  • #7
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by angst View Post
    yes but in most browser that won't make any difference. just tested in google chrome and the styling works fine after the body/html tags are closed.
    that means chrome is a garbage, first is the end of the document, second op use same id for both divs.

    best regards

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Since the div is echoing, this is not a PHP issue.
    Moving from PHP to html/css. What you should double check is that the html source does not include the <?php echo within it, otherwise it is improperly interpreting the entire tag (which also means you do not have PHP installed).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #9
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    strange, it works fine here, it will likely depend on the browser your using. however as Fou-Lu mentioned, this is not a php issue. it's a css issue: http://www.codingforums.com/html-css/

  • #10
    New Coder
    Join Date
    Jan 2011
    Posts
    29
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Id's should not be replicated. You need to use class when you want multiple tags to apply similar styles, although best I know the actual CSS should still apply.

    As this is currently sitting, this is not a problem with PHP. If the echo itself is not showing up, that would be a PHP problem, but if the tag is there and the style is not applied that is an HTML/CSS issue, not PHP. I'll await the OP to reply with whether this echo is not being produced.
    I'm getting my echos, but they're not styled at all : (

    So, I tried ending html like this as suggested :

    ?>
    </body>
    </html>


    PHP inside html, but it changed nothing.
    I'm using Firefox 4, just for the record...

  • #11
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by tkm76 View Post
    I'm getting my echos, but they're not styled at all : (

    So, I tried ending html like this as suggested :

    ?>
    </body>
    </html>


    PHP inside html, but it changed nothing.
    I'm using Firefox 4, just for the record...
    now change one of the id because must be uniq,

    Edit: except that echo, this is a html proble, why is not in the mysql forum,

    best regards

  • #12
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    Quote Originally Posted by oesxyl View Post
    that means chrome is a garbage, first is the end of the document, second op use same id for both divs.

    best regards
    well i guess firefox is garbage too, because it also works there

  • #13
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by angst View Post
    well i guess firefox is garbage too, because it also works there
    i'm prefectly agree with you,

    best regards

  • #14
    New Coder
    Join Date
    Jan 2011
    Posts
    29
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by oesxyl View Post
    now change one of the id because must be uniq,

    Edit: except that echo, this is a html proble, why is not in the mysql forum,

    best regards
    I didn't realize it was a html problem..
    My apologies.

  • #15
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    There is a space at the end of the id in the div that is echoed.
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  
    Page 1 of 2 12 LastLast

    Tags for this Thread

    Posting Permissions

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