SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jan 2009
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    is including <style> in body a serious issue?

    <style..></style> should be kept inside <head> tag, i do realize, but the way i am developing a site, i am including small parts of php script for different outputs and some of those scripts use styles which I would prefer not to put in <head> tag , this is because of the fact i am using imperfect design, headers are included by main script at the begining.

    Html validators gives error for putting <style></style> in side body, is it a serious issue to keep it that way or is it absolutely necessary to move any <style>s inside <head> tag?

    thanks

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,872
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Well it is invalid and so browsers are supposedto ignore it. How they treat that error (ignoring the content or moving it up to the head where it belongs) is up to the browser writers.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Wizard bronze trophy Tailslide's Avatar
    Join Date
    Feb 2006
    Location
    Bedford, UK
    Posts
    1,687
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can't you have the styles in a separate stylesheet? just use IDs and Class names that aren't used elsewhere in the page and when the PHP echoes the code it will use those classes or IDs in the styesheet.
    Little Blue Plane Web Design
    Blood, Sweat & Rust - A Land Rover restoration project

  4. #4
    SitePoint Wizard bronze trophy C. Ankerstjerne's Avatar
    Join Date
    Jan 2004
    Location
    The Kingdom of Denmark
    Posts
    2,702
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Just store the head and body contents in two seperate variables, rather than outputting them, until the end of the script. That way, you can add more contents to the head section during the script. Better yet, use templates.
    Christian Ankerstjerne
    <p<strong<abbr/HTML/ 4 teh win</>
    <>In Soviet Russia, website codes you!

  5. #5
    SitePoint Member
    Join Date
    Jan 2009
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the suggestins. I am well aware of the things you guys have said but the way i am making this site is in my onw style which is in many way 'poor' in design. I have different templates(basically page wrapper, like certain backgrounded paper) which will include different scripts like latest songs( a script whta will generate and echo a table containing the list of songs, for eg) and so on. The issue arises due tho the fact these scripts which are being included by the main caller script have their own styles for diff lay outs. Yes I could just keep all the style used by different scripts in external style sheet(something that i haven't done yet and probably do so soon to get rid of errors on validation)

    something Anker said has interested me, storing styles in a var and echoing them at the end of the script. This is exactly what i have wanted to do but because the way i have designed the page,the caller scrript will go on including diff parts of the scripts and will have already started echoing contents, ie, meaning the head part will have already been echoed by the template(in my case) so I am unable to echo stuff in the head or body tag at the end of script.

    To do this, is this the way to go:: Store all the echo in a var which will be a long string and at the end you replace certain vars with <style> and other elements then echo the whole string at the end???

    In my case the template style is basically a wrapper table with some layout design, hence , like i said the echo is alreadted started since the begining of the main script agg, this is not good is it?

    I would apppreciate your suggestions. Thanks a bunch.


Bookmarks

Posting Permissions

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