NEWSFLASH!

Hi guys,

Hopefully you read some fun and helpful stuff here. This blog is mainly aimed at the novice, mediocre and pretending to be advanced css student. If you have comments, questions or anything don't hesitate to post them. If you are completely new to css, you might want to have a look at a free tutorial of a former student of mine, although it's not a book, it should teach you the basics to give you a head-start in building your very own website.

Any ways enjoy your stay guys,

If it's not here maybe on a new blog somewhere with a decent editor. or if you lads are really generous on a commercial website :)

Cheers!



Cssfreakie



Monday, March 7, 2011

HTML elements and endtags

Hello everybody,

I thought I post the code below after I saw that someone posted a pretty weird code on a forum asking what was wrong with it. The poster is clearly unaware of the concept of the end-tag. Depending on your doctype all* HTML elements require an end-tag (*xhtml). The code that was posted looks like this:

Code:
    <div class="footer">
      <div class="footertxt">
        <div class="footerme"> <>
        <div class="footerright"><>
        <div class="footerimgmail"><>
        <div class="footercopyleft"><>
        <div class="footercopyright">
          <div class=" "><>
        <>
      <> <!-- closes footertext -->
    <> <!-- closes footer -->

this code is pretty much invalid. A good editor would have told this directly. (netbeans does a great job at this)

now back to the code:

the poster did this : <>   but that doesn't mean anything really.

Since all* elements in html require an end-tag we should do the following
for a div-element
  • the start-tag is <div>
  • the end-tag is </div>
and for a p-element
  • the start-tag is <p>
  • the end-tag is </p>

See the / in the end-tag? all end-tags have that.

So in this situation the poster was using a div in a div (nested elements)
so it should look like this:

Code:
<div id="outer-div">
     <div id="inner-div"></div>
</div>

By using clear indentation we can easily see which start-tag is the "partner" of which end-tag. Any-time an element is a nested child, you make an extra indentation. So the code should have looked like this:

Code:
<div class="footer">
      <div class="footertxt">
              <div class="footerme"> </div>
              <div class="footerright"></div>
              <div class="footerimgmail"></div>
              <div class="footercopyleft"></div>
              <div class="footercopyright">
                    <div class=" "></div>
              </div><!-- closes footercopyright -->
      </div> <!-- closes footertext -->
</div> <!-- closes footer -->


Happy coding! Feel free to leave a comment if you have questions or requests

Cssfreakie

2 comments:

  1. You are a freak! Tim Lincecum would be proud.
    You have been ^D in my PHP Dev folder. Thanks for the help with doing a random array, very clean code.

    ReplyDelete
  2. Ha drumz,

    thanks for the compliment!

    For all you lads wondering what code?
    here it is: link

    ReplyDelete