tag. – Billu Jul 28 '17 at 12:29

  • What are you talking about ? I'm already using tag in the footer.php, as I showed in my question. – Rackover Jul 28 '17 at 12:31
  • 'footer' should be inside of `scoped-content` as a child - to work scoped for it. See [this](https://www.w3schools.com/tags/att_style_scoped.asp) - anyway there is not enough support for it – sTx Jul 28 '17 at 12:31
  • 1
    Use tag at top of your code, not inside any tag. – Billu Jul 28 '17 at 12:33
  • @sTx : Okay understood, done it, but there are still errors. – Rackover Jul 28 '17 at 12:37
  • @BilluG This is not possible, as the footer.php is included at the end of the body tag. This means that even if I removed the
    stuff, it would still be in , and so would trigger an error.
    – Rackover Jul 28 '17 at 12:38
  • Best way to use "header.php" with all of your style files, when you will indclude header.php in any other php file, style will work on that php file. – Billu Jul 28 '17 at 12:38
  • 1
    Doesn't your website have a common css file? Like a css file which have all the common styles for your site? Put the footer style in there – Huangism Jul 28 '17 at 12:40
  • @Rackover - cannot understand why you can't put `footer` styles in you global styles.css file, `div.footer` mean that only divs with class footer wil have those styles – sTx Jul 28 '17 at 12:41
  • @Huangism No : not here, where the site is subdivised in sub-sites that have completely different layouts. – Rackover Jul 28 '17 at 12:41
  • @sTx The different sub-sites have different layouts, making it impossible to use a global style.css without rewriting the whole site and changing every class name. – Rackover Jul 28 '17 at 12:42
  • ok, so for the rest of the subsite how did you styled it? – sTx Jul 28 '17 at 12:42
  • Which ever sub site this footer belongs to, add the style into that site's common css – Huangism Jul 28 '17 at 12:43
  • @Huangism The point is displaying the same footer everywhere whatever the current sub-site here : different layouts, but the footer is a constant. – Rackover Jul 28 '17 at 12:44
  • an alternative would be to write a script into footer.php that would insert some code in head when `footer.php` is required – sTx Jul 28 '17 at 12:44
  • @sTx : Well the code that I posted here, up in my question, ( – Rackover Jul 28 '17 at 12:44
  • @sTx This looks neat, how can I do that? – Rackover Jul 28 '17 at 12:45
  • If this footer is a constant then can't you just add an external css to the main controller template? this would be the main file that includes all other files for sub sites – Huangism Jul 28 '17 at 12:46
  • @Huangism What do you mean by main controller template ? – Rackover Jul 28 '17 at 12:47
  • `scoped` only works in mozila 21 as I see – sTx Jul 28 '17 at 13:05
  • @Rackover like one file that controls them all. Isn't there a template that includes other sub site files? – Huangism Jul 28 '17 at 13:07
  • 3 Answers3

    3

    The error is coming because you are putting the <style> inside <div>. Do not do that. It is better to move that code to internal or separate external CSS.
    External CSS is preferred because it increases the reusability.

    Priyanjit
    • 305
    • 3
    • 9
    • I would prefer not make it external for reasons explained in the third comment of the question. How can you make it internal ? If I delete the
      the error stays the same. Everywhere on the internet it is said to create a "style scoped" element but it still shows as an error.
      – Rackover Jul 28 '17 at 12:30
    • Unfortunately, the scoped style concept [has been dropped](https://github.com/w3c/html/issues/231) from the HTML spec. Browsers didn't want to implement it. It it supposed to be replaced by Shadow DOM. – Ilya Streltsyn Jul 28 '17 at 14:05
    1

    script in body will (likely) be allowed in HTML 5.2 (W3C’s next HTML Recommendation).

    The current HTML 5.2 Working Draft for the style element specifies:

    Contexts in which this element can be used:

    • Where metadata content is expected.
    • In a noscript element that is a child of a head element.
    • In the body, where flow content is expected.

    (This last line is not included in HTML 5.1, which is the current HTML Recommendation.)

    Here’s the issue asking to update the validator used by the W3C:
    style element conforming in body in w3c HTML

    unor
    • 92,415
    • 26
    • 211
    • 360
    -1

    Check in inspect element for styles in head

    var styles = "<style>"+
        "@font-face { "+
          "font-family: 'LilyUPC'; "+
          "src: url('/common/upcll.ttf');}"+
    
       "div.footer {"+
            "position: fixed;" +
            "bottom: 0;" +
           "left:0;" +
            "right:0;" +
           "background-color: black;" +
            "float:down;" +
            "text-align:center;" +
            "z-index: 20;"+
            "font-family: 'LilyUPC';" +
            "color:red;" +
            "font-size:12pt;" +
            "text-decoration:underline;}" +
    "</style>";
    
    $("head").append(styles);
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div class="other">Unstyled content here</div>
    <div class="footer">Styled content here</div>

    then in php you put this js inside <script </script> and echo the whole script

    Like this:

    echo("
         <script>
            var styles = \"<style>\"+
            \"@font-face { \"+
                  \"font-family: 'LilyUPC'; \"+
                  \"src: url('/common/upcll.ttf');}\"+
    
             \"div.footer {\"+
                   \"position: fixed;\" +
                   \"bottom: 0;\" +
                   \"left:0;\" +
                    \"right:0;\" +
                   \"background-color: black;\" +
                   \"float:down;\" +
                   \"text-align:center;\" +
                    \"z-index: 20;\"+
                    \"font-family: 'LilyUPC';\" +
                    \"color:red;\" +
                    \"font-size:12pt;\" +
                    \"text-decoration:underline;}\" +
            \"</style>\";
    
            $(\"head\").append(styles);
    
         </script>
       ");
    
    sTx
    • 1,213
    • 13
    • 32
    • I've use jQuery here, to do it with only javascript check [this](https://stackoverflow.com/questions/524696/how-to-create-a-style-tag-with-javascript) – sTx Jul 28 '17 at 13:06
    • Thanks ! Did it using only javascript. This works ! Just one more question : when I load the page, I've got a slight delay before any JS code executes. Do you know why? (the page is only 14kb) – Rackover Jul 28 '17 at 14:31
    • because code executes after all html to `footer` has rendered, then after `php require`(or what you do to load footer) has loaded – sTx Jul 28 '17 at 14:40
    • you can always make a loading screen on top of all html from body and hide it after code from footer executes, or on `window.onload`(javascript) or `$(document).ready`(jQuery) – sTx Jul 28 '17 at 14:43