Page 130 - DCAP408_WEB_PROGRAMMING
P. 130

Web Programming




                    Notes          4.9 DIV and SPAN

                                   The  <div>  tag defines  logical  divisions  (defined)  in  your  Web  page.  It  acts  a  lot  like  a
                                   paragraph tag, but it divides the page up into larger sections.

                                   <div> also gives you the chance to define the style of whole sections of HTML. You could define
                                   a section of your page as a call out and give that section a different style from the surrounding
                                   text.
                                   But that’s not all it does! The <div> tag gives you the ability to name certain sections of your
                                   documents so that you can affect them with style sheets or Dynamic HTML.
                                   One thing to keep in mind when using the <div> tag is that it breaks paragraphs. It acts as a
                                   paragraph end/beginning, and while you can have paragraphs within a <div> you can’t have a
                                   <div> inside a paragraph.
                                   The primary attributes of the <div> tag are:
                                      style

                                      class
                                      id
                                   Even if you don’t use style sheets or DHTML, you should get into the habit of using the <div>
                                   tag. This will give you more flexibility when more XML parsers become available. Also, you
                                   can use the id and name attributes to name your sections so that your Web pages are well formed
                                   (always use the name attribute with the id attribute and give them the same contents).

                                   Because the <center> tag has been deprecated in HTML 4.0, it is a good idea to start using
                                   <div  style=”text-align:  center;”>
                                   to center the content inside your div.
                                   <span>
                                   The <span> tag has very similar properties to the <div> tag, in that it changes the style of the text
                                   it encloses. But without any style attributes, the <span> tag won’t change the enclosed items at
                                   all.
                                   The primary  difference between the <span> and <div>  tags is  that <span>  doesn’t do any
                                   formatting of it’s own. The <div> tag acts includes a paragraph break, because it is defining a
                                   logical division in the document. The <span> tag simply tells the browser to apply the style
                                   rules to whatever is within the <span>.
                                   The <span> tag has no required attributes, but the three that are the most useful are:

                                      style
                                      class
                                      id
                                   Use <span> when you want to change the style of elements without placing them in a new block-
                                   level element in the document. For example, if you had a Level 3 Heading  (<h3>) that you
                                   wanted the second word to be red, you could surround that word with

                                   <span  style=”color  :  #f00;”>2ndWord</span>
                                   and it would still be a part of the <h3> tag, just red.






          124                               LOVELY PROFESSIONAL UNIVERSITY
   125   126   127   128   129   130   131   132   133   134   135