Professional Documents
Culture Documents
Examples of block elements include <div>, <p>, <h1>, <form>, <ul> and
<li>. Inline elements on the other hand have the opposite
characteristics:
To change an element's status you can use display: inline or display: block.
But what's the point of changing an element from being block to inline, or
vice-versa? Well, at first it may seem like you might hardly ever use this, but
in actual fact this is a very powerful technique, which you can use any time
you want to:
padding: 2em;
border: 1em solid green;
width: 20em;
width/**/:/**/ 14em;
The first width command is read by all browsers; the second by all browsers
except IE5.x on PC. Because the second command comes second it
takes precedence over the first - any command that comes second will
always override a preceding command. So, how does all this work?
By placing empty comment tags (/**/) before the colons, IE5.0 will ignore the
command. Likewise, by placing these empty comment tags after the colon,
IE5.5 will ignore the command. By using these two rules in conjunction with
each other, we can hide the command from all of IE5.x.
A very handy CSS command that exists is the min-width command, whereby
you can specify a minimum width for any element. This can be particularly
useful for specifying a minimum width for a page.
<body>
<div id="container">
The first command is the regular minimum width command; the second is a
short JavaScript command that only IE understands. Do note though, this
command will cause your CSS document to invalidate so you may prefer to
insert it into the head of each HTML document to get round this.
You might also want to combine this minimum width with a maximum width:
#container
{
min-width: 600px;
max-width: 1200px;
width:expression(document.body.clientWidth < 600? "600px" :
document.body.clientWidth > 1200? "1200px" : "auto");
}
IE has a rather strange way of doing things. It doesn't understand the min-
width and min-height commands, but instead interprets width and height as
min-width and min-height - go figure!
This can cause problems, because we may need boxes to be resizable should
more text need to go in them or should the user resize text. If we only use
the width and height commands on a box then non-IE browsers won't allow
the box to resize. If we only use the min-width and min-height commands
though then we can't control the width or height in IE!
To resolve this problem, you can use the following code for a box with
class="box":
.box
{
width: 80px;
height: 35px;
}
html>body .box
{
width: auto;
height: auto;
min-width: 80px;
min-height: 35px;
}
All browsers will read through the first CSS rule but IE will ignore the second
rule because it makes use of the child selector command. Non-IE browsers
will read through the second one and will override the values from the first
rule because this CSS rule is more specific, and CSS rules that are more
specific always override those that are less specific.
5. Text-transform command
One of the lesser known, but really useful CSS commands is the text-
transform command. Three of the more common values for this rule are:
text-transform: uppercase, text-transform: lowercase and text-transform:
capitalize. The first rule turns all characters into capital letters, the second
turns them all into small letters, and the third makes the first letter of each
word capitals.
7. Invisible text
Sometime you may actually want to make text invisible. Invisible text can be
especially useful for screen reader users, perhaps to assign a label to a
form item or insert a heading ahead of a section. Don't want to change the
visual appearance by inserting these? Make them invisible and no one using
a visual browser knows that they're there.
You may also want to make text invisible if using a print or handheld CSS
file, as some information may not need to be displayed on either of these
mediums (see below for more on this).
To make text invisible you can use display: none - easy! This works fine for
hiding text from handhelds (if CSS is supported) and printed web pages, but
isn't so great for many screen readers. Screen readers are now becoming too
clever for their own good, and some will actually ignore the any text that has
the rule display: none assigned to it.
A separate CSS document can be created for PDAs and mobile phones, and
only activated when one of these devices is being used to access your site.
More and more websites are creating separate CSS documents for
printing, so web pages automatically become print-friendly when users
choose to print them. You can also do the same for handheld devices.
The following command is used to call up the CSS document for handhelds:
CSS commands in the handheld CSS file override any equivalent commands
in the main CSS document. So, what commands should you place in this file?
Ideally, you want handheld web users to avoid having to scroll across. To
test this, open up your website in a regular browser window and resize it to
150px in width. Then, open up your main CSS file and insert some new
commands at the very bottom of the document. The commands you place
here should adjust the layout of the website so that it doesn't require
horizontal scrolling at a 150px width. Then, open up a new document, cut
and paste these new commands over, and save it as handheldstyle.css (or
whatever name you want to give it).
What your website offers to handheld web users should be quite different to
what it offers on traditional web browsers, as the user experience is quite
different. For further information, a book such as Handheld Usability is a
great read.
9. 3-d push button effect
Back in the early days of the web, 3-d buttons that appeared to become
pushed in when moused over were all the rage. At that time, this could only
be achieved through images and JavaScript, but now with the advent of CSS
we can go all retro and re-create this effect:
a{
display: block;
border: 1px solid;
border-color: #aaa #000 #000 #aaa;
width: 8em;
background: #fc0;
}
a:hover
{
position: relative;
top: 1px;
left: 1px;
border-color: #000 #aaa #aaa #000;
}
Aside from these commands, you can insert any other commands to achieve
the desired presentation effect - the only limit is your imagination!
Most websites highlight the navigation item of the user's location in the
website, to help users orientate themselves. This is a fundamental
requirement for basic usability, but can be a pain as you'll need to tweak the
HTML code behind the navigation for each and every page. So can we have
the best of both worlds? Is it possible to have the navigation highlighted
on every page, without having to tweak the HTML code on each and
every page? Of course it is...
First of all, you'll need to assign a class to each navigation item:
<ul>
<li><a href="#" class="home">Home</a></li>
<li><a href="#" class="about">About us</a></li>
<li><a href="#" class="contact">Contact us</a></li>
</ul>
You'll then need to insert an id into the <body> tag. The id should be
representative of where users are in the site and should change when users
move to a different site section. When in ‘Home’ it should read <body
id="home">, in ‘About Us’ it should be <body id="about"> and in ‘Contact
Us’ <body id="contact">.
This basically creates a rule that only takes effect when class="home" is
contained within id="home", and when class="about" is in id="about" and
class="contact" is in id="contact". These situations will only occur when the
user is in the appropriate site section, seamlessly creating our highlighted
navigation item.
Configuration Engineer