HTMLGoodies
The ultimate html resource
Earthweb.com


About the Double-Underlined Links


Become a Partner




Search Clipart.com:



internet.commerce















HTML Goodies : Beyond HTML : Cascading Style Sheets: So, You Want Positioning, Huh?

HTML GOODIES TO GO NEWSLETTER


Other Related Newsletters

So, You Want Positioning, Huh?


By Joe Burns

     Please Note: You will need Netscape 4.x or Explorer 3.x or 4.x to finish this tutorial. This specific page will run in any browser, but the examples will need the higher level browser.

Use these to jump around or read it all...

[Positioning and Image] [How It's Done]
[Can This Be Done With Text?]
[Where's This List of Style Commands?]

     Wouldn't it be great if you could make a point of placing every item on your page exactly where you want it? Even more -- make that placement exactly the same on every browser your page is viewed in? It looks like the answer is a series of Cascading Style Sheet commands that allow you to denote to the pixel where you want an item to be pinned up.

     You should know that Style Sheets are not universal as the moment (1/8/98). Netscape's version 4.0 and Explorer 3 and 4 level browsers understand the style commands, but not always exactly the same way. This is a bit buggy at the moment. In fact, it's quite buggy. Netscape users will find that this works on the text but sometimes not on the images. You'll need to make sure those viewing your page are using one of the browsers above for this to work. I stress "need." If the browser doesn't get these positioning commands, then the page will just look bad.

     I suggest you either use a routing JavaScript to send those with the correct browsers to one place and others to another place (I have one here) or don't use these commands, and Style Sheets in general, a great deal until they are more standard across browsers and platforms.

     That said, we go forward....

Positioning An Image

     You may notice soon that I am doing this by including all of the style sheet commands inside the items that I am positioning. You might wonder that if these are style sheets, why not put these in the text/css file or in the head commands inside <STYLE> commands. Well, you can. You can see how it's done in my Cascading Style Sheet tutorial. But, in order to teach this, it was easier to include the commands with the item that I am positioning. Plus I like doing it this way. To each their own I guess....

     Avid readers of HTML Goodies might remember the commands for positioning an image from the Netscape Layering Commands. What you are going to do is tell the browser to position the upper left-hand corner of and image in a specific plot point on the page. Here's an example:

This new window will pop up with an image positioned 25 pixels from the top of the browser screen and 170 pixels from the left of the browser screen.


How It's Done

     Here's the code I used to place the image at that specific plot point:

<IMG STYLE="position:absolute; TOP:35px; LEFT:170px; WIDTH:50px; HEIGHT:50px" SRC="circle.gif">

Here's What's Happening

  • IMG denotes that this will be an image.
  • STYLE= proclaims what will follow are style commands.
  • position:absolute; states that the image will go exactly where I say it will. If text or another picture is already there -- tough. This will go right over top of it. That is one of the drawbacks to this positioning stuff.
  • TOP:35px;LEFT:170px; These are the plot points for the image: 35 pixels down from the top and 170 pixels in from the left.
  • WIDTH:50px;HEIGHT:50px This is the height and width of the image itself.

     Notice the semicolon between each section.

     In order to demonstrate that the positioning of these images is absolute, here's the same example page as before with text where the image is positioned.


Can This Be Done With Text?

     You bet. If you noticed in the last example, that yellow box that told you to close the window to get back to the tutorial also sat over top of the text.

Here's an example where a block of text is positioned 80 pixels from the top of the window
and 400 pixels from the left of the browser window.

     Here's the command I used to position the text:

<DIV style="position: absolute; top:80px; left:400px; width:200px; height:25px">80 from the top and 400 from the left</DIV>

     ...and...

Here's What's Happening

  • DIV denotes that this is a "division" of the page, a section, if you will.
  • STYLE= denotes that some style commands will be put to work.
  • position: absolute; denotes that this division will be placed exactly where you want it placed.
  • top:80px; left:400px; is the positioning of the division.
  • width:200px; height:25px denotes the height and width of the division.
  • /DIV ends the division section.


Why Is The Text Jumped Down?

     Because I made the width of the division too small for the text in it. Here's the same example with the division width set to 300px.


What Happened to the Color?

     Easy fellah! It's simple enough to get back. Just add this command to the mix:

background-color: yellow

     Now the division you set up is filled in with the color. It looks like this.
     This will work with either word color codes or hex color codes. However, if you use a hex color code, make sure to place a hash mark (#) in front of the six characters. Like so: background-color: #FFFFFF


Can I Set Other Styles?

     Sure, you can set just about any style command that works on text. Just make sure that if you set the font size higher that you give the division enough space to house it. Here's an example where I've used as many text-based style commands as I could find before it got boring.

     The code looked like this:

<DIV style="position: absolute; font-family: arial; font-style: italic; font-variant:small-caps;
     font-weight:bold; text-decoration:underline; letter-spacing: 2px; top: 80px; width: 400px;
     left: 400px; height: 25px; background-color: yellow">80 from the top and 400 from the left</DIV>


Where's This List of Style Commands?

     I have a pretty good one in my Cascading Style Sheet tutorial. You'll also find a very full list at C-Net and there's always the World Wide Web Consortium's Style Site.

     You could even simplify the process by using Classes and ID's. But that's another tutorial.

  Enjoy!

 

[Positioning and Image] [How It's Done]
[Can This Be Done With Text?]
[Where's This List of Style Commands?]

Tools:
Add htmlgoodies.com to your favorites
Add htmlgoodies.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed

IT Management Networking & Communications Web Development Hardware & Systems Software Development Earthwebnews.com



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
Avaya Article: Call Control XML - Powerful, Standards-Based Call Control
Tripwire Whitepaper: Seven Practical Steps to Mitigate Virtualization Security Risks
Internet.com eBook: The Pros and Cons of Outsourcing
Go Parallel Article: Scalable Parallelism with Intel(R) Threading Building Blocks
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Go Parallel Video: Intel(R) Threading Building Blocks: A New Method for Threading in C++
HP Video: Is Your Data Center Ready for a Real World Disaster?
Microsoft Partner Portal Video: Microsoft Gold Certified Partners Build Successful Practices
HP On Demand Webcast: Virtualization in Action
Go Parallel Video: Performance and Threading Tools for Game Developers
Rackspace Hosting Center: Customer Videos
Intel vPro Developer Virtual Bootcamp
HP Disaster-Proof Solutions eSeminar
HP On Demand Webcast: Discover the Benefits of Virtualization
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Microsoft Download: Silverlight 2 Software Development Kit Beta 2
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt
Iron Speed Designer Application Generator
Microsoft Download: Silverlight 2 Beta 2 Runtime
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
IBM IT Innovation Article: Green Servers Provide a Competitive Advantage
Microsoft Article: Expression Web 2 for PHP Developers--Simplify Your PHP Applications
Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES