Tuesday, May 15, 2007

CSS Layouts

CSS page layout uses the Cascading Style Sheets format, rather than traditional HTML tables or frames, to organize the content on a web page. The basic building block of the CSS layout is the div tag—an HTML tag that in most cases acts as a container for text, images, and other page elements. When you create a CSS layout, you place div tags on the page, add content to them, and position them in various places. Unlike table cells, which are restricted to existing somewhere within the rows and columns of a table, div tags can appear anywhere on a web page. You can position div tags absolutely (by specifying x and y coordinates), or relatively (by specifying their distance from other page elements).

Creating CSS layouts from scratch can be difficult because there are so many ways to do it. You can create a simple two-column CSS layout by setting floats, margins, paddings, and other CSS properties in a nearly infinite number of combinations. Additionally, the problem of cross-browser rendering causes certain CSS layouts to display properly in some browsers, and display improperly in others. Dreamweaver makes it easy for you to build pages with CSS layouts by providing over 30 pre-designed layouts that work across different browsers.

Using the pre-designed CSS layouts that come with Dreamweaver is the easiest way to create a page with a CSS layout, but you can also create CSS layouts using Dreamweaver absolutely-positioned elements (AP elements). An AP element in Dreamweaver is an HTML page element—specifically, a div tag, or any other tag—that has an absolute position assigned to it. The limitation of Dreamweaver AP elements, however, is that since they are absolutely positioned, their positions never adjust on the page according to the size of the browser window.

If you are an advanced user, you can also insert div tags manually and apply CSS positioning styles to them to create page layouts.

CSS page Layout Tutorial Video

Requirements

To complete this tutorial you will need to download the following software and files:

Dreamweaver CS3 - 30 days trial download

About CSS page layout structure :

Before proceeding with this section, you should be familiar with basic CSS concepts.


Figure 1. A. Container div B. Sidebar div C. Main Content

<!--container div tag-->
<div id="container">
<!--sidebar div tag-->

<div id="sidebar">
<h3>Sidebar Content</h3>

<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>
<p>Maecenas urna purus, fermentum id, molestie in, commodo porttitor, felis.</p>

</div>

<!--mainContent div tag-->

<div id="mainContent">
<h1> Main Content </h1>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent aliquam, justo convallis
luctus rutrum.</p>

<p>Phasellus tristique purus a augue condimentum adipiscing. Aenean sagittis. Etiam leo pede,
rhoncus venenatis, tristique in, vulputate at, odio.</p>

<h2>H2 level heading </h2>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent aliquam,
justo convallis luctus rutrum, erat nulla fermentum diam, at nonummy quam ante ac quam.</p>
</div>

</div>

In the above example, there is no “styling” attached to any of the div tags. Without CSS rules defined, each div tag and its contents fall into a default location on the page. However, if each div tag has a unique id (as in the above example), you can use the ids to create CSS rules that, when applied, change the style and positioning of the div tags. The following CSS rule, which can reside in the head of the document or in an external CSS file, creates styling rules for the first, or “container” div tag on the page:

#container {
width: 780px;
background: #FFFFFF;
margin: 0 auto;
border: 1px solid #000000;
text-align: left;
}

The #container rule styles the container div tag to have a width of 780 pixels, a white background, no margin (from the left side of the page), a solid, black, 1 pixel border, and text that is aligned left. The results of applying the rule to the container div tag are as follows:


Figure 2. Container div tag, 780 pixels, no margin A. Text aligned left B. White background C. 1-pixel solid black border


Figure 2. Container div tag, 780 pixels, no margin

A. Text aligned left B. White background C. 1-pixel solid black border

The next CSS rule creates styling rules for the sidebar div tag:

#sidebar {
float: left;
width: 200px;
background: #EBEBEB;
padding: 15px 10px 15px 20px;
}

The #sidebar rule styles the sidebar div tag to have a width of 200 pixels, a gray background, a top and bottom padding of 15 pixels, a right padding of 10 pixels, and a left padding of 20 pixels. Additionally, the rule positions the sidebar div tag with float: left—a property that pushes the sidebar div tag to the left side of the container div tag. The results of applying the rule to the sidebar div tag are as follows:


Figure 3. Sidebar div, float left  A. Width 200 pixels B. Top and bottom padding, 15 pixels


Figure 3. Sidebar div, float left

A. Width 200 pixels B. Top and bottom padding, 15 pixels

Last, the CSS rule for the main container div tag finishes the layout:

#mainContent {
margin: 0 0 0 250px;
padding: 0 20px 20px 20px;
}

The #mainContent rule styles the main content div with a left margin of 250 pixels, which means that it places 250 pixels of space between the left side of the container div, and the left side of the main content div. Additionally, the rule provides for 20 pixels of spacing on the right, bottom, and left sides of the main content div. The results of applying the rule to the mainContent div are as follows:


Figure 4. Main Content div, left margin of 250 pixels  A. 20 pixels left padding B. 20 pixels right padding C. 20 pixels bottom padding


Figure 4. Main Content div, left margin of 250 pixels


A. 20 pixels left padding B. 20 pixels right padding C. 20 pixels bottom padding

The complete code looks as follows



Note: The above example code is a simplified version of the code that creates the two-column fixed left sidebar layout when you create a new document using the predesigned layouts that come with Dreamweaver.

Create a page with a CSS layout using DREAMWEAVER

When creating a new page in Dreamweaver, you can create one that already contains a CSS layout. Dreamweaver comes with over 30 different CSS layouts that you can choose from. Additionally, you can create your own CSS layouts and add them to the configuration folder so that they appear as layout choices in the New Document dialog box.

Dreamweaver CSS layouts render correctly in the following browsers: Firefox (Windows and Macintosh) 1.0, 1.5, and 2.0; Internet Explorer (Windows) 5.5, 6.0, 7.0; Opera (Windows and Macintosh) 8.0, 9.0; and Safari 2.0.

  1. Select File > New.
  2. In the New Document dialog box, select the Blank Page category. (It’s the default selection.)
  3. For Page Type, select the kind of page you want to create. Note: You must select an HTML page type for the layout. For example, you can select HTML, ColdFusion®, JSP, and so on. You cannot create an ActionScript™, CSS, Library Item, JavaScript, XML, XSLT, or ColdFusion Component page with a CSS layout. Page types in the Other category of the New Document dialog box are also restricted from including CSS page layouts.
  4. For Layout, select the CSS layout you want to use. You can choose from over 30 different layouts. The Preview window shows the layout and gives a brief description of the selected layout.

    The pre-designed Dreamweaver CSS layouts provide the following types of columns:

  • Fixed Column width is specified in pixels. The column does not resize based on the size of the browser or the site visitor’s text settings. (Non recommended)
  • Elastic Column width is specified in a unit of measurement (ems) relative to the size of the text. The design adapts if the site visitor changes the text settings, but does not change based on the size of the browser window. (Yahoo.com Layout)
  • Liquid Column width is specified as a percentage of the site visitor’s browser width. The design adapts if the site visitor makes the browser wider or narrower, but does not change based on the site visitor’s text settings. (Accessible layouts)
  • Hybrid Columns are a combination of any of the previous three options. For example, the two-column hybrid, right sidebar layout has a main column that scales to the size of the browser, and an elastic column on the right that scales to the size of the site visitor’s text settings.
5. Select a document type from the DocType pop‑up menu.

6. Select a location for the layout’s CSS from the Layout CSS in pop‑up menu.
  • Add To Head Adds CSS for the layout to the head of the page you’re creating.
  • Create New File Adds CSS for the layout to a new external CSS stylesheet and attaches the new stylesheet to the page you’re creating.
  • Link To Existing File Lets you specify an existing CSS file that already contains the CSS rules needed for the layout. This option is particularly useful when you want to use the same CSS layout (the CSS rules for which are contained in a single file) across multiple documents.

7. Do one of the following:

  • If you selected Add to Head from the Layout CSS in pop‑up menu (the default option), click Create.
  • If you selected Create New File from the Layout CSS pop‑up menu, click Create, and then specify a name for the new external file in the Save Style Sheet File As dialog box.
  • If you selected Link to Existing File from the Layout CSS in pop‑up menu, add the external file to the Attach CSS file text box by clicking the Add Style Sheet icon, completing the Attach External Style Sheet dialog box, and clicking OK. When you’re finished, click Create in the New Document dialog box.Note: When you select the Link to Existing File option, the file you specify must already have the rules for the CSS file contained within it.

Note: Internet Explorer conditional comments (CCs), which help work around IE rendering issues, remain embedded in the head of the new CSS layout document, even if you select New External File or Existing External File as the location for your layout CSS.(Optional) You can also attach CSS style sheets to your new page (unrelated to the CSS layout) when you create the page. To do this, click the Attach Style Sheet icon above the Attach CSS file pane and select a CSS style sheet.

    Add custom CSS layouts to the list of choices

    1. Create an HTML page that contains the CSS layout you’d like to add to the list of choices in the New Document dialog box. The CSS for the layout must reside in the head of the HTML page.
      TIP: To make your custom CSS layout consistent with the other layouts that come with Dreamweaver, you should save your HTML file with the .htm extension.
    2. Add the HTML page to the Adobe Dreamweaver CS3\Configuration\BuiltIn\Layouts folder.
    3. (Optional) Add a preview image of your layout (for example a .gif or .png file) to the Adobe Dreamweaver CS3\Configuration\BuiltIn\Layouts folder. The default images that come with Dreamweaver are 227 pixels wide x 193 pixels high PNG files. TIP: Give your preview image the same file name as your HTML file so that you can easily keep track of it. For example, if your HTML file is called myCustomLayout.htm, call your preview image myCustomLayout.png.
    4. (Optional) Create a notes file for your custom layout by opening the Adobe Dreamweaver CS3\Configuration\BuiltIn\Layouts\_notes folder, copying and pasting any of the existing notes files in the same folder, and renaming the copy for your custom layout. For example, you could copy the oneColElsCtr.htm.mno file, and rename it myCustomLayout.htm.mno.
    • (Optional) After you’ve created a notes file for your custom layout, you can open the file and specify the layout name, description, and preview image.

    Labels:

    Monday, October 02, 2006

    CSS2 and Internet Explorer 7

    As many of you know, Microsoft has announced that it will be releasing Internet Explorer 7.0 this summer to those who are on the XP operating system in a project code named “Rincon”. The move is reportedly being done to improve the security of the IE browser. However, with browsers such as Firefox gaining market share, many people speculate that the new Internet Explorer will come with more than just security enhancements. Features such as tabbed browsing, built in anti-spyware, and RSS aggregating are all features that appear to be coming with the Rincon project.

    The real question, however, for any website owner and developer is whether Microsoft will create a browser that interprets CSS2 in a standard way. Currently Microsoft does not support all of CSS2’s functionalities and also adds some functionalities that CSS2 never initially supported. The result is nothing more than a major headache for those developing a website (SEO Herald) that is accessible to all people, regardless of the browser they are using.

    So will Microsoft finally adhere to the official CSS2 specifications? Don’t bet on it. A look at Microsoft’s history and their current position in the market place seems to point to the idea that they will continue to buck the open source development trend and try to mold the marketplace according to their vision.

    Microsoft Views Incompatibility as a Competitive Advantage

    Most website developers develop a website for Internet Explorer first, and for the secondary browsers second. The reason for this is obvious. If you have a website that works in Firefox, but appears broken in Internet Explorer, the site appears broken to over 90% of its visitors. On the flip side, if the site works fine in Internet Explorer, but not in Firefox, only a small percentage of your website visitors are inconvenienced.

    Microsoft, being the vast market share holder in the browser market, can influence the behavior of website owners and web surfers. Because not every site is optimized for browsers such as Firefox, web surfers who try to make the transition to Firefox will find themselves on familiar sites that appear broken to them in Firefox, but not Internet Explorer because Internet Explorer does not follow a standard set of rules that any browser can comply with. The result is that these surfers who try to make the transition over to Firefox will go back to the more familiar Internet Explorer.

    Keep the Advantage, Eliminate the Disadvantages

    There are a few reasons for people making the switch from Internet Explorer to Firefox. There is the obvious group of people that truly believe Microsoft is evil, so they will do anything to avoid a Microsoft product no matter how much it inconveniences them. Microsoft is not worried about these people so much because they will always represent a small group of people. What Microsoft does need to worry about is the real advantages of making the switch to Firefox.

    Security
    Security is probably the top reason people make the switch to Firefox. Now that most people have been introduced to spyware, awareness of PC security is becoming a bigger issue. Any person who does a little research will quickly realize that most spyware programs focus on the vulnerabilities of Internet Explorer, since that is what most surfers use. Making the switch to Firefox not only gives surfers new security features that are not available with Internet Explorer, but they also remove themselves from the target of spyware creators.

    Since security is the one of the biggest reasons people leave Internet Explorer, the people at Microsoft have decided to make security a major priority. And, in the interest of giving credit where credit is due, they should be commended for finally looking to improve the security of their browser . Who knows how many countless computers were infected with spyware programs due to the vulnerabilities Internet Explorer presented.

    Features
    Firefox also offers unique features that users cannot get with Internet Explorer. Features such as tabbed browsing, RSS Aggregation, and others have proven to be more than just nice ideas or some programmer’s pet hobby. Unfortunately for Firefox, they have proved to be the market testing for Microsoft, without Microsoft having to spend any money on development. Look for Microsoft to continue to copy the successful features of Firefox in the future, and ignore those features that are not successful.

    Back to CSS2

    What is CSS2 really? CSS2 is nothing more than a set of recommendations for controlling layout and design of websites put forth by the World Wide Web Consortium. The W3C’s goal for their recommendations is to avoid market fragmentation on the Internet, thus creating a more uniform and more enjoyable surfing experience for web users. Ironically enough, Microsoft and the W3C have the same goal, although Microsoft would like to have uniformity on the web as a result of everyone using Internet Explorer.

    As long as Microsoft is able to hold onto its market share through segmenting the market, they will do so. They will have this ability as long as they have an overwhelming majority of the market share. Unfortunately for those who make their living designing and developing websites, there are only two hopeful outcomes to make life easier: either Microsoft loses enough market share that they decide to adopt the W3C’s recommendations, or Microsoft successfully eliminates all browser competitors and is the only option for web surfers. Until one of these two options occurs, expect Microsoft to continue to interpret the web as they see fit, and in a way that will keep users on Microsoft products.



    About This Author :
    Mark Daoust is the owner of Site-Reference.com. Discuss this article further at
    http://forums.site-reference.com/

    Labels:

    Blog's RSS Feed

    Add to Google
    Subscribe to del.icio.us
    Add to My Yahoo!
    Add to Technorati Favorites!
    Web Design India Feed
    Subscribe with Bloglines
    Subscribe in NewsGator Online
    Add to My AOL
    Add One Million Subscribers to Newsburst from CNET News.com

    Subscribe with Pluck RSS reader
    Simpify!


    Find Blogs in the Blog
Directory