Page 2 of 2 FirstFirst 12
Results 16 to 29 of 29

Thread: CSS in PHP include header and footer not working

  1. #16
    Join Date
    May 2014
    oh.. and I was unable to find the href with no value. And...thanks for hating bootstrap and wordpress, it sparked me to with this all on my own with out the over load of these two programs.

  2. #17
    Join Date
    Mar 2012
    Quote Originally Posted by kirsten View Post
    Ok, let me catch up and make all of these changes.
    Should my files be: header and footer html or .php?
    Makes no difference.

    Quote Originally Posted by kirsten View Post
    should my css file be inside of my php file?
    Technically, no. There are good reasons for using separate .css file(s). On the other hand, it SHOULD work, so long as it is included correctly. I.e. Php include files are included at the point where the "include" instruction is in the .php file. So something like:

    PHP file:
    <?php include 'header.inc'; ?>
    <!-- html goes here -->
    INC file:
    <!-- the include file -->
    <title>my web site</title>
    <!-- CSS goes here -->
    <!-- end include file -->

    <!-- the include file -->
    <title>my web site</title>
    <!-- CSS goes here -->
    <!-- end include file -->
    <!-- html goes here -->
    See how the text inside the include file is substituted for the "include" instruction? So the CSS is included between the <head> </head> tags and has <style> </style> tags, and will work. But position the "include" instruction elsewhere (e.g. between the <body> </body> tags, or before the <head> tag) won't work.

  3. #18
    Join Date
    May 2014
    I'm sorry, I do not understand this:<html>
    <?php include 'header.inc'; ?>

    <!-- html goes here -->


    Why would I start this as <html> when the html is included in the includes file?

  4. #19
    Join Date
    May 2014
    If you look at my header file you will see that the css is linked in.

  5. #20
    Join Date
    May 2014
    OMG I think I got it but now my body html is not showing up.<?php /* My References page */
    include('../images/kirstenEaton (2).png')

    <!DOCTYPE html>
    <title>My References</title>
    <h3>My References</h3>
    <p>John Mierzwa Deep Dive Coders</p>



  6. #21
    Join Date
    Mar 2012
    I suspect that you are confusing CSS link files with PHP include files. They work very differently:

    CSS link files:
    - Contain only CSS instructions.
    - Must be called "name.css", e.g. "screen.css".
    - Can be linked to HTML and/or PHP files.
    - Must not contain <style> </style> tags ('cos they are HTML not CSS instructions).
    - Work in browsers as well as on web sites (i.e. do not need a host).
    - Must be linked between the <head> </head> tags with the syntax:
    <link rel="stylesheet" href="name.css" type="text/css">

    PHP include files:
    - Contain any valid HTML, CSS and/or PHP instructions.
    - Can be called anything, e.g. "name.inc".
    - By default can only be linked to PHP files (depending on server configuration).
    - Only work on a web server (or a local host).
    - Are included in the PHP file where their content is intended to go, using the syntax:
    <?php include 'name.inc'; ?>

    You should use CSS link files to link the CSS instructions rather than PHP include files.
    Last edited by jedaisoul; 05-31-2014 at 01:03 PM.

  7. #22
    Join Date
    Mar 2012
    Press <ctrl> U to view the source code of the references page. You will see that there is a spurious:

    <!DOCTYPE html>
                <title>My References</title>
    inserted BEFORE the original doctype instruction.

  8. #23
    Join Date
    Mar 2012
    Basically, you should NOT put any instructions BEFORE the doctype declaration, and it would be better to avoid putting <head> </head> <body> </body> codes in include files until you have a better understanding of how PHP include files work.

    Until then, use include files only to contain common code that is otherwise duplicated in every web page, like nav bars, headers and footers. Note: by "headers" I mean visible headings on the web ages, not the <head> </head> area of the HTML code. You will probably get on better if you are less ambitious at the start:

    1. Write your web pages and get them working WITHOUT PHP include files.
    2. Save a copy of the working site (in case you mess up).
    3. Then identify a block of duplicated code, and put it in an ".inc" file.
    E.g. "name.inc".
    4. Substitute the instruction <?php include 'name.inc' ?> for the code it contains in just one page of the web site.
    5. When you have got that working, do the same in the other pages.
    6. When you have got that working, identify any other blocks of duplicated code, and repeat steps 3. to 5. above (using different names for each include file).

  9. #24
    It's loading a screen.css here, the one that's in the same directory as it... which doesn't look very good. Are you trying to have it use the screen.css that's in the root instead?

    Basically is this what you meant to use:

    Or this?

    If the former, it's working just fine from here. If the latter, you'll need to ../ again... or put your .php file in the root and stop making a subdirectory for it.

    Once again though you have multiple doctypes meaning you are pasting separate HTML files together instead of PARTS of a HTML file.

    As to the file extension, if you are using include then name it PHP. Really though when it's include it doesn't matter, but I'd make it .php so you can run PHP inside it, that way you could use things like functions so you can make ALL your pages use the same header and footer code while passing the unique values like page title and key/desc meta.

    I tell you what; I do this every now and then -- I'll do a rewrite example of your page using "poor man's CMS" style includes (what you are trying to do here it seems) so you can learn from the markup and PHP -- and I'll write up full line-by-line section-by-section breakdowns of the PHP, HTML and CSS for you to learn from.

  10. #25
    Alright, I have a live copy of my rewrite of your main page here:

    ... and the references page here:

    The main directory:

    Contains a .rar of the entire "poor man's" setup and a variety of useful files. The site1_phps directory:


    Contains viewable PHP source files so we can refer to the code online easily.

    I will now attempt to break this down to explain the process it was built with, and how it all works. I'll likely be teaching you some HTML stuff you probably never heard of, particularly if you took classes on the subject since most "educators" when it comes to web technologies do NOT know enough to be opening their traps on the subject.

    --- Directory Structure ---

    Before we start diving into code, I want to go over the directory structure used by this example. Planning where things will be BEFORE you even THINK about writing a line of code is a really good practice I cannot recommend highly enough. In this case it's gutted down from my normal system, which works as follows.

    -- root, contains all user-callable .php or .html files.

    -- contains content images, aka images that are not part of the template

    -- contains the various .template.php bits and pieces, like the header, footer, etc, as well as the .css file for that template.

    -- because images called by the CSS are part of the skin, and are called in relation to the CSS file's location, keeping them separate makes file management easier and makes any future reskin of the site simple too.

    Really keeping all user callable files in the root makes directory management really, REALLY simple, as everything can be linked downtree.

    From the PHP include of the 'common' template elements:

    To the content images:
    <img src="images/test.jpg" alt="test image" />

    To the CSS:
    <link type="text/css" rel="stylesheet" src="template/screen.css" media="screen, projection, tv" />

    To the images included from the CSS

    That last one resolving to /template/images/h1Logo.png

    This way you don't have to up-tree with ../ and everything is well organized and easy to get to.

    The distinction between a content image (one that belongs in the markup) and a presentational image (one that goes in the CSS) is a very important one to establish early on. Your logo for example is a presentational affectation of text - like most logos -- which means it has NO business in the markup in a IMG tag. We'll get more into that once we get to markup and CSS.

    --- Logical Document Structure ---

    When building a site it helps to have a gameplan that works to how HTML and CSS are supposed to work, and the rules of how they are SUPPOSED to be used. Sadly, most people working on sites don't take the time to do this, and rarely if ever learn the actual rules of using HTML. You can see this when people omit fieldsets and labels from forms, when they don't use numbered headings properly (which you weren't), or when you see nonsense like <td class="heading"> or <td rowspan="4"><b>My Table</b></td>.

    I'm going to outline my process -- you can take it or leave it, but it helps to at least have one.

    The first thing I do when working on a new site, is take my content, or a reasonable facsimile of future content, and just write it flat in a text editor in an order that would make sense as if HTML didn't even exist. This is the lowest common denominator you can start with.

    I included what I did for this rewrite here:

    Things simply in the order of importance or use. I use a few special characters to say 'this will be a heading' or 'this links to or is a image of this'... with three hyphens to clearly divide 'sections' of the page.

    I then take that simple outline and mark it up semantically, which you can see here:

    The first thing you'll notice there is I start with an H1... so lets talk headings. You were using numbered headings in a willy-nilly nonsensical manner; mind you, that willy-nilly nonsensical manner is used by a LOT of developers who passed it on to others out of their own ignorance... You learned from a bad source.

    First up, if you were choosing the headings based on their default text size, you were choosing the wrong tags for the wrong reasons -- tags should be chosen for what they MEAN, NOT what they look like.

    The reason heading tags have numbers stems from professional writing of documents like research papers, science papers and reports. (what Tim Berners Lee actually created HTML to do). In professional writing differerent level headings indicate the start of subsections of the page -- lower order (higher numbered in HTML) headings indicating the start of a subsection of the higher order (lower numbered in HTML) heading preceeding it.

    Because of that, used properly you should have one and ONLY one H1. (HTML 5 changes this slightly, we'll cover that bit of idiocy in a moment) -- as a H1 is the heading under which EVERY subsection of the page is... well, a subsection. This is why a H1 for the main article is often gibberish -- while the site title (or logo) is often the best candidate for it.

    Think of a newspaper -- is the headline the top-most heading in terms of structural importance? (as opposed to important importance -- there is a difference) Of course not. Structurally the main giant headline is NOT the heading for every other article on the front page. The name of the paper is the H1, as evidenced by it being at the top of every sub-page, even if it is shown smaller on those sub-pages. All the articles are H2 as they are siblings to each-other, even if the first one is shown in bigger text. You would hope that "Man mugged and left for dead near downtown diner" and "K-6 gets new school building" are not subsections of "MAYOR CAUGHT TAKING MILLION DOLLAR BRIBE" If they were, that would be one screwed up town. - they are all H2 regardless of their appearance.

    Likewise, H2 means subsections of the h1... H3 mean subsections of the H2, and so forth down to H6... If you don't have H4 or H5, you have no business using a H6 on a page. If you don't have a h1, you have no business using a H2. HR also has a semantic meaning -- a change in topic/section when a heading is unwanted/unwarranted.

    Think of it like a 'tree' -- headings should 'fan out' in a logical structural order. This can help with search, AND in certain user-agents (browsers) can also help with navigating the page when the user isn't on a mouse or touch interface. You can actually see this tree if you have the web developer toolbar installed in Firefox. -- just go into information -> document structure and it will yell at you about missing headings and broken structure!

    That's why numbered headings exist, and why if you're not doing that you are using them wrong.

    Now that said, the steaming pile known as HTML 5 (can you tell I'm a fan?) destroys this usefulness as every time you open a "SECTION" you revert to a new H1, resulting in a gibberish multiple H1 on a page. Think about it though -- semantically if numbered headings and horizontal rules divide the page into sections, why do we need a SECTION tag? If heading navigation lets you skip from the h1 to the first H2 (which should be your main content) why do we need a NAV tag? If the last heading, set of headings, or everything after the last HR on the page are the start of the footer, why do we need a FOOTER tag? They are ALL just pointless redundant code bloat put together by a group (the WHATWG) that never grasped how to use HTML properly in the first place!

    Which is just part of why I do NOT advocate the use of HTML 5, and prefer a RECOMMENDATION doctype like HTML 4.01 STRICT or XHTML 1.0 STRICT. Well, and I remember what happened the last time people started deploying websites using draft specifications; two years later it was called "Quirks" and we pay for it to this day.

    So as you can see, I just have the semantic markup, with an ID or two on elements that we may want to target. H1 as the structural root, ul#mainMenu for the menu, H2/img/P/a.more for the three 'panel' areas, H2+P and H2+UL for the footer subsections. ALL those subsections get H2 because they are NOT subsections of each-other.

    The next step in this is 'rounding out' the markup with the rest of what a page should have, and providing hooks for the application of appearance. I ALWAYS write a static version of the very first page on a site first, so I can cut it up into the pieces needed by the PHP or skinning system of whatever it is going into. It is just easier at this point to design a flat page and split it up, than it is to try and design with the PHP in the way.

    The final markup for the page being this:

    Alright, coming close to the 10k post limit, so I'll continue this in the next post.

    ... to be continued.
    Last edited by deathshadow; 06-01-2014 at 05:06 AM.

  11. #26
    ... continued

    You'll notice the final source uses XHTML 1.0 STRICT. I like XHTML 1.0 for it's more consistent structural rules -- I like STRICT because it means code elements that have no business on any website written after 1997 like TARGET, ALIGN, BORDER, BGCOLOR, CENTER, FONT -- wil throw an error in validation.

    EVEN IF I was forced to use the halfwit garbage known as HTML 5 for the one or two useful things like MANIFEST and SANDBOX, or that are shoved down our throats thanks to the freetards Apple zealots like the pointlessly redundant AUDIO and VIDEO, I'd design in XHTML 1.0 STRICT, ignore the validation errors for those elements/attributes, then swap to the HTML 5 doctype right before deployment... something that a LOT of developers who have given up on fighting HTML 5 now advocate. Like Don Quixote, I'm still tilting at that particular windmill.

    Another thing you'll probably see is I'm a nut when it comes to using tab and enter -- they are your friend and it's much clearer whats going on if you don't stuff everything onto one long incomprehensible line. This is REALLY true of attributes on really long tags like HTML, META and LINK. For the most part there's nothing too fancy going on, but let's hit a couple of things before moving on to BODY.

    --- META ---

    Content-type -- handy in local testing so the browser knows what you are working with when there is no content-type headers being served; you never know if headers are going to be sent or sent properly, so despite what the HTML 5 nutters say, keep this one around.

    Content-Language -- always good to state it, even with lang and xml:lang on HTML.

    viewport -- the 'fix' to tell mobile devices we actually know what we are doing. You now need to say height as well as width since some versions of Android now seem to report the height as width when in portrait mode.

    keywords -- a LOT of people say the keywords meta is ignored, even some folks at Google; guess what? They're full of it. It's ignored IF YOU USE IT WRONG!

    It is called keyWORDS -- not keysentences, not keyphrases, keyWORDS! Seven or eight single words, proper names or compound terms that exist inside BODY as CDATA you want a slight ranking boost on, preferably totalling less than 96 characters. Do NOT word-jumble evey possible combination as that does absolutely nothing, and NEVER DID -- no matter how many examples you'll find online doing exactly that.

    For example, this is bloated gibberish likely to be ignored:

    content="babysitting in new hampshire, new hampshire babysitting, new hampshire child care, child care and babysitting, daycare, daycare in new hampshire"+

    New Hampshire is a proper name, child care is a compound term, so this on the other hand:
    content="new hampshire, babysitting, daycare, child care"

    Would most likely still work -- assuming ALL of those terms exist inside BODY as content text. It's ignored if you don't use it right -- who'd have thought?!?

    description -- a natural language paragraph you want shown below your TITLE on the SERP. That's ALL it's for. It is NOT a place to stuff with keywords (though if they happen naturally then fine) -- it is where you describe what the current page IS.

    When it comes to METADATA, those are really the only ones that you should have before you add things like tracking scripts or advertising. Most of the rest of the META people put on their sites aren't actually used by anything.

    --- LINK ---

    stylesheet -- You'll notice I have a TYPE on that so, well... it knows what type of stylesheet is in use. In STRICT that's NOT an optional value. Likewise I am targeting with the MEDIA attribute "screen, projection, tv" -- as projection is what kiosks use operating fullscreen, and there are still a number of folks out there using things like MSN web TV boxes. (scary as that is). If you omit the MEDIA attribute your CSS will be sent to all -- and that might not make the least bit of sense for print, handheld, aural, braille...

    Ok, on to

    --- BODY ---

    First notice I put <html><head>, </head><body> and </body></html> on the same line together. Some people assume I do this to save two bytes -- no so. This is a reminder that nothign should EVER go between those elements. WAY too many times I've seen people paste stuff between them, and putting them on the same line reduces the odds of somebody screwing things up that way.

    I added span inside the anchor so that first when images are off, the text is shown instead -- this is called 'image replacement' and we'll get more into detail on that in the CSS. The inner span will be our image replacement, the outer one is to apply color styling near identical to your image so that it still kinda looks the same should images be disabled/blocked.

    A lot of users are starting to block images and scripting to save bandwidth on metered connections (like our friends in Canada and Australia), and increase performance on mobile (since images chew a lot of RAM and mobile... doesn't have a lot of RAM). Your page should be ready to adjust to that, and doing it this way gives us a H1 for structure, actual text for screen readers, and graceful degradation images off. Serious win/win.

    Because of the nature of the styling we end up with several DIV -- DIV and SPAN are 'semantically neutral containers' -- they do not impart ANY semantic meaning to the structure or the tags and data inside them. They exist to be hooks for presentation, without saying WHAT that presentation is. I try to use the same philosophy on my ID's and classes, though sometimes (like with the widthwrapper) you end up just not being able to come up with a better name for it.

    div#content and div.widthwrapper would be around all content on all pages, the former for float wrapping and background effects if desired, the latter to apply a 'max-width' so long lines of text don't become painful to read.

    div.panels is specific to the home page, and is there to wrap the three panels so we can hook them by that class.

    Which is why you'll notice a distinct lack of classes (other than .more) inside each of the panel DIV. Since we don't have DIV inside the DIV and all three would get the same CSS, none of them need classes or ID's. The only reason I have a.more in there is on the odd chance you might want an anchor inside your H2 or P, or around the IMG.

    When it comes time to close my DIV you'll notice I have comments to say what is being closed. I do this because </div> is a bit vague, particularly if you're a good ways down the page. I don't say "end" because that's wastefully stupid, what else would </div> mean?!?

    You'll often see comments like:
    <!-- start content -->
    <div id="content">
    <!-- end content -->

    Really? Opening a DIV called #content is the start of the content?!? Who'd have thunk it? That's just stupid.... likewise </div> is the end, we don't need to say end...

    Now, you'll notice I put the comment BEFORE the closing tag. In certain versions of IE and FF if you have comments between floats, inline-blocks, or a number of other types of positioned elements you can trip rendering bugs. YES, I said COMMENTS can trip rendering bugs! Sounds really stupid doesn't it? Well, I did say Internet Explorer didn't I? When the errors occur, the content of the second sibling element can just up and disappear, while the content of the first element can often be drawn a second time in a random location. They are called the "disappearing content" and "double render" bugs respectively... but, it only occurs when commments are BETWEEN elements... solution? If you put the comment BEFORE you close the tag, it's not between elements is it?

    Also, you'll notice I say <!-- #content --> or <!-- .panels -->, just as in CSS so I know if it's a class or ID being closed.

    It's just a good habit for code clarity.

    in #footer we just have a bunch of DIV that I DID end up wanting to target, so they all get ID saying what each of them ARE. This is where things like bootcrap can fall falt on their face with their needlessly vague presentational classes.

    Now, even with all of that, the larger XHTML 1.0 header, the closing comments, tripple wrapping of DIV at the content area -- it's still three quarters the size of your original... another reason using semantic markup and logical structure can really rock!

    Alright, gimme a few and I'll break down the CSS, then I'll go through and document the PHP.

    ... to be continued.

  12. #27
    ... continued

    Alright, on to the CSS:

    The top section is stuff common to all pages. The second half is page specific. I put everything for one media target (like screen) into a single "monolithic" file as properly written websites shouldn't need enough CSS for the extra size to have an impact. Sure, the halfwits vomiting up 200k of CSS might thing monolithic is bad, but when there is no real excuse for the stylesheet of an entire forum or CMS to break 48k, it's really stupid to break it into separate files which results in extra handshakes, especially when it means you can pre-cache on first load the appearance of sub-pages the user might visit. Maybe a half second more load time on first visit to have sub-pages load and render almost instantly? Not a hard choice.

    I always start out with a reset -- The simple fact is across browsers elements do NOT start out with the same padding or margin behavior, and it's a pain in the ass to have to set padding and margins on EVERY element as you use them.

    There are smaller resets, like the so called "universal reset" of:
    * { margin:0; padding:0; }

    But that can cause problems with form elements as FF and IE both apply their own 'extra' padding you have no control over, and stripping the padding off INPUT, SELECT and TEXTAREA can cause those elements to be wildly different sizes across the four (well, now three) major browser engines.

    There are also larger resets, like Eric Meyer's "Reset Reloaded" -- problem with that is it does MORE than just reset, and is very close to becoming a framework. It's big, it's fat, and most of what it does has nothing to do with being a reset. Resets like that one are what gives them a bad name.

    The one I use is a nice safe middle ground. It targets what is needed, comes in at under a quarter-k, and has never failed me.

    The comment on the HR says it all -- HR in my markup are for semantic structure, not drawing lines on the screen. Usually as I use other elements to make the 'sections' clear on the page, I hide my HR by default.

    @media (max-width:600px) { * - The first media query is to address a text sizing issue in lower resolution mobile devices. It's in a media query as sending this value to desktop Safari will prevent being able to zoom in that browser -- a laugh since iOS Safari has no such issues making that... well... just really stupid on Apple's part.

    body - Font, color, background... nothign too fancy. I set the background color to the footer's blue so that when the page is shorter than the screen the footer color continues. The other alternative would be a min-height layout, but given how well a flex inside a flex works (which is to say not at all) and that we really shouldn't fix the height of such a simple footer, I wouldn't consider that a viable choice.

    h1 - padding and background color. Gecko based browsers (firefox, iceweasel) have this goof assed bug where if you declare PX inside an element as font size, the PARENT inherits it -- which is COMPLETELY the wrong behavior and probaly one of the dumbest things a browser can do... so we need to explicity set 100% font-size so our 1em padding is actually system 1em and not the 28px of the anchor inside it.

    h1 a -- Now, I'm well known for ranting and raving about using PX on font sizes, but in this case because we are behind a fixed size image we really don't have a choice. If we left it elastic, the text under our image replacement would peek out. The position:relative is so we can absolute position the span inside it. The zoom trips a IE condition called "haslayout" so our absolute positioning isn't screwed up in IE7/earlier. I added letter spacing and used "trebuchet ms" so it at least comes close to looking like your image on windows.

    You'll notice I explicity set text-decoration:none -- I advise against setting that globally since removing it from flow content is poor accessibility.

    Also you might notice I always use the 'condensed' font property of

    font:weight style size/line-height family;

    This is because if you change the font size EXPLICITLY REDECLARE YOUR LINE-HEIGHT. Line-height does NOT inherit reliably when you change the size, which can lead to broken layouts, particularly if designing elastic with dynamic fonts. There is a LIE being circulated on some forums that omitting a metric (px, em, whatever) will make a value that does inherit properly... aka:


    But as the word "lie" would imply, that's 100% ignorant fiction; the laugh being no matter how many live examples of it not working you show the advocates of that technique, they more vehemently they claim it works. Then they wonder why I call them a string of expletives that would make truckers tell me "watch your mouth, there are mechanics in here."

    h1 a span -- different color to match the image for our images off appearance.

    h1 a span span -- the inner span is sized to our logo image and absolute positioned over the text. This requires an opaque image, and as such I remastered the logo into a palettized png.

    Losing the transparency and dropping it to 6 bit / 64 color reduced it to a mere 1.4k in size. /WIN/ compared to the 12k or so of the original.

    #mainMenu -- turn off bullets, set the alignment, pad the top and bottom, color and border. Nothing fancy.

    #mainMenu li -- I set these to display:inline as LI can cause real headache rendering bugs in IE8, the worst of which being the staircase bug. Setting that means we can't set heights or top/bottom padding, but we can use padding to space the anchors apart.

    #mainMenu a -- these get set to inline-block so we can set top/bottom padding on them. I also set them to nowrap for mobile. The uneven top/bottom padding accounts for oddball alignments of the vertical position of fonts and to compensate for a slight optical illusion the color choices are creating. I also set up some nice transitions for our hover states as well as rounding off the corners. The box shadows being the same color as #mainMenu's background are invisible until we hover.

    #mainMenu a:psuedostates -- the hover state is just background-color change and text-shadow. This gives it that really cool glow effect for a minimum of effort. You'll notice I use :active, :focus AND :hover. :focus is for keyboard navigation in modern browsers, legacy IE will incorrectly use :active (meaning it's been clicked on) for keyboard nav, and of course :hover is for mouse users. It's a good idea to state all three the same in most cases... (at least until you start using CSS3's WONDERFUL HEAVEN SENT :target attribute)

    #content -- full width, the white background of the content area, and I gave it a inset box-shadow to slightly darken the corners for another bit of attractiveness.

    .widthWrapper -- I made this container semi-fluid (min/max-width) and elastic (values in EM) so long lines aren't painful, and pre media-query browsers don't try to go narrower than the content is designed for. The 100% width also trips haslayout, to TRY and fix some positioning bugs in IE.

    #content h2 -- size and padding -- yawn.

    #content p -- padding, yawn -- but on both of these, notice I use padding not margin. I try to use padding instead of margin whereever possible so I don't have to keep track of margin-collapse headaches.

    #footer -- overflow to wrap floats, set the text color, border... again, yawn.

    -- align their text center, float them right. Floating these three shrinks them to their smallest size, so that nice heading and paragraph on the right can use as much of the remaining space as possible. Ends up looking really nice.

    #footerCopyright -- I add some extra right padding to address a browser flaw common after a flex container, where the floats in the next element lose half an em on the right. No clue WHY it happens, but it does. I also align it right, so it counterparts #footerAbout's left alignment nicely.

    #footerAbout -- overflow:hidden can have a number of strange effects, in this case I'm leveraging that it prevents the text inside this container from dropping UNDER the three stacked floats.

    #footer h2 - padding, fonts, yawn

    #footer p -- Zzzzzzzzzzz.....

    #footer ul -- kill bullets, pad it...

    #footer li -- a little extra space between them.

    #footer a -- more attractive (and legible) color, and a fade transition for:

    #footer a:pseudostates -- color for the hover states.

    Alright, getting close to the post limit again, so once again I'll continue on the next post with media queries and page specific CSS.

    ... to be continued.

  13. #28
    ... continued

    My responsive process is a bit different -- I like to start out designing for middle-resolution desktop FIRST, becuase the most likely browsers to not have media query support are NOT mobile, it's IE8 and earlier! That's the most common lowest common denominator, so that's my starting point. As such my media queries strip off columns and work towards mobile, or if need be towards larger screen sizes -- basically if you start in the middle, you have less distance to travel each direction!

    @media (max-width:56em) --he first media query just strips off the min-width for media query browsers and shrinks the menu padding... Notice that I declare my breakpoints in EM so that it's based on the user's default font size, NOT pixels -- since pixels could result in a broken layout on large font/120dpi or other systems NOT using the 16px = 1em default. [i]LIKE MINE![/b]

    @media (max-width:46em) -- I test by shrinking the page until it breaks, then figure out how many EM that is to reflow whatever broke. In this case it's just the footer. Easiest fix is to turn that four columns into three, and put the wide text below it. That's just changing the floats, setting 33% width, some alignment, and breaking the copyright area's h2 into two lines with that little span I tossed in there. Clearing floats on #footerAbout makes sure it doesn't ride up accidentally.

    @media (max-width:38em) -- again the footer is the only thing in the main template that needs more tweaking at small sizes. At this point it's just too narrow for attractive columns, so we strip the floats and sizes, resulting in no columns. I also added a border between the elements.

    --- and that's the template CSS, onto the page specific stuff

    .panels - overflow:hidden fixes a oddball firefox bug with flex where the footer rides up over the flex container for no fathomable reason at certain sizes. I kept the flex-box model you were using (for the most part) but a word of warning, it barely works in IE10 and not at all in IE9/earlier. If you care about legacy IE this type of layout used to be "not viable for web deployment" in concept. Honestly, the page is still usable in IE9/earlier, it's just ugly... You could probably live with it as-is. If I really cared about it this would be one of the few scenario's I'd load a second stylesheet behind a IE conditional comment to make these all just 33% width floats... that or maybe a media selector hack, though for targeting IE9/earlier wholesale that could get ugly. I pad the right side so the flex boxes can margin just one direction -- this makes having the same space between the child DIV a lot easier as we then don't have margin stacking in the way.

    .panels>div -- this lets us target those child DIV without wasting classes on 'nothing'. They get the flex model, overflow:hidden to wrap floats and crop the drop-shadow on the nested H2, margin with the right side left as zero... alignment, border radius and drop-shadow shouldn't be unfamiliar given what you had... BUT

    There's that bottom padding. I used a 'trick' to make the '.more' buttons line up. First I padded the bottom of all the DIV a sufficient amount to place those buttons -- we'll explain why when we get to a.more

    #content .panels h2 -- we have to say #content on these to resolve a specificity issue since the 'generic' #content h2 for normal pages sets some values we want to change. Doing this beats the tar out of using !important. Padding, margin, size, border, shadow -- nothing fancy.

    #content .panels h2 small -- after some playing with it I found the de-emphasized subtext (what small means semantically) just looked nicer on it's own line. The vertical-align:middle fixes a odd chrome rendering bug where the small line appears too close or even overlaps the text above it on zoom.

    .panels img -- setting it to display:block and using margin to center it removes a LOT of the headaches leaving it inline can cause, such as inconsistent behavior after a margin and extra padding at the bottom that's not the same across browsers.

    I set a max-width so that they do NOT resize larger automatically, since that generally looks like a blurry mess, but they will shrink as needed.

    #content .panels p -- as with H2 we have to say #content to get around the specificity of the generic version (as used on the references page). Other than that, we're not doing anything too wild with these.

    .panels .more -- here's that magic I mentioned earlier. I absolute position the .more buttons over that bottom padding, using the left:50% margin-left: negative half the fixed width trick to center them across the display. I use uneven top/bottom padding to actually center the text top to bottom due to oddities in alignments of fonts that way. The rest of it is just style and color.

    I changed them to blue for two reasons -- first, for consistency with the rest of the design, second that blue creates less luminance making the white text legible, something that light yellow/orange you were using didn't provide. If you were to use that yellow/orange you'd have to switch to a dark text if you want things actually legible -- and in testing I thought that looked horrible. (probably why you were using white even if you couldn't read it).

    .panels .more:psuedostates -- simple color and background change, but that nice transition on the non-pseudo makes it a smooth and pretty change. Blessed be - CSS3.

    Then the media queries specific to pages with .panels on them.

    @media (max-width:56em)
    Setting .panels to display:block removes the flex-box model, making the DIV be displayed one over the other. Removing the block from the SMALL text reduces the title to a single line, then floating the image rides the paragraph up next to it making better use of the available screen space at smaller display sizes. Likewise a negative bottom margin rides the bottom padding up into the image, so we can move the a.more over to the right side where it looks nicer in this version of the layout.

    @media (max-width:38em)
    This narrow we are better off pulling the floated image and making them centered again as they were on the large screen layout, likewise moving .more back to it's original position as well.

    ... and that's the CSS. Ok, in our next episode I'll dig into explaining the PHP version of this, starting with the common.template.php -- might be a bit, I need to have some lunch first.

    ... to be continued.

  14. #29
    ... continued.

    In our common.template.php -- read along with the .phps here:

    The first thing I have in there looks pretty complex -- it is. It's a simple hook I provide to automatically add gzip compression to the page. Normally php output isn't gzipped, and manually setting up to support it is tricky; that one simple snippet of the first 20 lines of code handles it for you by starting buffering if the browser supports it, and using a shutdown function to compress it and send it properly. Don't worry about that part, it does the work for you.

    Inside this .php I put both the header and the footer as functions. This makes it easy to pass values to the header like a unique page title, keywords and description. Similar values could be passed to the footer if desired in a later version.

    function template_header -- this function takes three OPTIONAL parameters, if you exclude them when you call the function they will be treated as false.

    I use echo to output the markup. You could close PHP and re-open it again all over the place, but to me that just always feels like ugly code bloat -- probably because it's NOT how real programming languages (C, Pascal, Modula) handle output. I echo using single quoutes, which as a rule of thumb means we can use double quotes normally and only have to "escape" single quotes -- which usually won't exist in a theme anyways.

    we take from our original testing source the first part right up until our variable based META. I use an IF statement to test if $keywords is set, and if it is we echo it out as the content of META[keywords], then do the same thing for $description and META[description].

    then output the CSS link, and then use an if statement on $pageTitle. If it's set, we output $pageTitle - SiteName, if it's not set, we just have Sitename -- which in this case is "Kirsten Eaton Website". Having a unique title for every page is good usability, Google also suggests it to aid with search; using a hyphen between the page and site names works great.

    From there we just echo out the rest of the markup right up until where we'd have the page-unique content... and that's where the template_header ends. Again, you'll see I put a closing commment in so I know what's being closed.

    function template_footer -- this one doesn't get any parameters for now -- it just outputs the rest of the template after where the page unique content would go as per our original template.

    ... and that's all that's there. Now, how do we use it? Well, lets use the smaller "references" page as an example. If we look at it's code:

    We open PHP, include template/common.template.php, and call the header function passing it a unique title for the current page, keywords we want to use (those should be changed to reflect your final page content), and a short paragraph describing the page (you'll want to write one of those)

    After we close PHP your page unique content can be plugged in. In this case a simple DIV#references with a h2 and a couple paragraphs.

    After your content, we just open up PHP again, call template_footer, close PHP and we're done.

    If you take a look a the source for the index.php

    You'll see it works exactly the same way, the only real difference is my passing FALSE to $pageTitle so that just the sitename is shown on the homepage.

    Pretty slick, pretty simple, and pretty powerful.

    ... and that's the most basic of what used to be called a "Poor Man's CMS" in action. Oddly, it was commonplace to call it that a decade ago, seems like I'm the only one still using the term now?

    I know all this is a LOT to take in. Take your time, go over it, and if you have any questions, I'll be here.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.22076 seconds
  • Memory Usage 3,081KB
  • Queries Executed 13 (?)
More Information
Template Usage (37):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (4)bbcode_code
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (14)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (14)postbit
  • (14)postbit_onlinestatus
  • (14)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates