HTMLGoodies
The ultimate html resource
Earthweb.com


About the Double-Underlined Links



Search Clipart.com:



internet.commerce
Compare Prices
Web Hosting Directory
Baby Photo Contest
Car Donations
Get Business Software
Online Education
Dental Insurance
Home Improvement
Promotional Items
Promos and Premiums
Memory Upgrades
Server Racks
Auto Insurance Quote
Best Price

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


Quality Management ROI Calculator - Focus on Test Automation
The Rational Quality Management ROI calculator is intended to give you an idea of what return you can garner from implementing our functional testing solutions. Our quality management solutions offer tools to develop a continuous process, powered by automation to govern software delivery. »

Gartner MarketScope: Application Quality Management Solutions, 1Q 08
This Gartner MarketScope provides guidance for enterprises seeking to purchase tools to manage risk and software quality. We focus on tools fit for large-scale enterprise use and that are ready out of the box to manage quality requirements and functional testing. »

Whitepaper: Tips for Writing Good Use Cases
Writing a good use case isnt easy, but, fortunately, our experience can be your guide. The concepts and principles assembled here represent the works of many people at IBM, and they form a foundation of proven best practices. »

Whitepaper: The Role of Integrated Requirements Management in Software Delivery
Learn about the critical role integrated requirements management can play in helping ensure your business goals and IT projects are continuously aligned-whether you are sourcing, integrat-ing, building or maintaining your software. It also looks at ways that integration and automation can help ensure managing projects and the required changes can be executed using manageable processes that satisfy stakeholders and development teams. »

HTML GOODIES TO GO NEWSLETTER


Other Related Newsletters

Silverlight 2 App & Walkthrough: Leverage Silverlight 2 with SQL Server and XML. Learn how to utilize both a database & XML for your Silverlight 2 application.

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 eBook: Planning a Service Oriented Architecture
IBM eBook: Choosing the Right Architecture--What It Means for You and Your Business
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Avaya Article: Using Intelligent Presence to Create Smarter Business Applications
Intel Go Parallel Article: Getting Started with TBB on Windows
Microsoft Article: 7.0, Microsoft's Lucky Version?
Avaya Article: How to Feed Data into the Avaya Event Processor
IBM Article: Developing a Software Policy for Your Organization
Microsoft Article: Managing Virtual Machines with Microsoft System Center
Intel Go Parallel Article: Intel Threading Tools and OpenMP
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
HP Video: StorageWorks EVA4400 and Oracle
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Red Gate Download: SQL Toolbelt and free High-Performance SQL Code eBook
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
Silverlight 2 App and Walkthrough: Leverage Silverlight 2 with SQL Server and XML
IBM Article: Enterprise Search--Do You Know What's Out There?
HP Demo: StorageWorks EVA4400
Microsoft Article: The Progress and Promise of Deep Zoom
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES