Showing posts with label css tips. Show all posts
Showing posts with label css tips. Show all posts

Simple Ways to Improve Typography In Your Designs

8ways_typography

Many people, designers included, think that typography consists of only selecting a typeface, choosing a font size and whether it should be regular or bold. For most people it ends there. But there is much more to achieving good typography and it’s in the details that designers often neglect.

These details give the designer total control, allowing them to create beautiful and consistent typography in their designs. While these details can be applied across different types of media, in this articles we’re going to focus on how to apply them to web design using CSS. Here are 8 simple ways you can use CSS to improve your typography and hence the overall usability of your designs.

Measure

The measure is the length of a line of type. To a reader’s eye, long or short lines can be tiring and distracting. A long measure disrupts the rhythm because the reader has a hard time locating the next line of type. The only time a narrow measure is acceptable is with a small amount of text. For optimum readability you want the measure to be between 40-80 characters, including spaces. For a single-column design 65 characters is considered ideal.

Measure

A simple way to calculate the measure is to use Robert Bringhurst’s method which multiples the type size by 30. So if the type size is 10px, multiplying it by 30 gives you a measure of 300px or around 65 characters per line. The code would look something like this:

p {
font-size: 10px;
max-width: 300px;
}

Leading

Leading is the space between the lines of type in a body of copy that plays a big role in readability. Correctly spaced lines make it easier for a reader to follow the type and improves the overall appearance of the text. Leading also alters typographic color, which is the density or tone of a composition.

Many factors affect leading: typeface, type size, weight, case, measure, wordspacing, etc. The longer the measure, the more leading is needed. Also, the larger the type size, the less leading is required. A good rule is to set the leading 2-5pt larger than the type size, depending on the typeface. So if you set the type at 12pt, a 15pt or 16pt leading should work well on the web.

Leading

This takes some finessing to get the right spacing but here is an example of what the code would look like:

body {
font-family: Helvetica, sans-serif;
font-size: 12px;
line-height: 16px;
}

Hanging Quotes

Hang quotes in the margin of the body of text. By not doing so a quotation mark that is flush with the text will interrupt the left margin and disrupt the rhythm of the reader. Hanging quotes keeps the left alignment intact and balanced therefore increasing readability.

Hanging Quotes

This is achieved very easily with CSS using the blockquote element:

blockquote {
text-indent: -0.8em;
font-size: 12px;
}

The negative indent will vary depending on the typeface, type size and margins.

Vertical Rhythm

A baseline grid is the foundation for consistent typographic rhythm on a page. It allows the reader to easily follow the flow of the text, which in turn increases readability. A continuous rhythm in the vertical space keeps all the text on a consistent grid so that proportion and balance are retained throughout the page, no matter the type size, leading or measure.

Vertical Rhythm

To keep a vertical rhythm in CSS, you want the spacing between elements and the line-spacing (leading) to equal the size of the baseline grid. For example, lets say you’re using a 15px baseline grid, meaning that there are 15px between each baseline. The line-spacing would be 15px and the space between each paragraph would also be 15px. Here is an example:

body {
font-family: Helvetica, sans-serif;
font-size: 12px;
line-height: 15px;
}
p {
margin-bottom: 15px;
}

This allows each paragraph element to align with the grid, keeping the vertical rhythm of the text.

Widows & Orphans

A widow is a short line or single word at the end of a paragraph. An orphan is a word or short line at the beginning or end of a column that is separated from the rest of the paragraph. Widows and Orphans create awkward rags, interrupt the reader’s eye and affect readability. They can be avoided by adjusting the type size, leading, measure, wordspacing, letterspacing or by entering manual line breaks

Widows

Unfortunately, there is no easy way to prevent typographic widows and orphans with CSS. One way to remove them has been mentioned above, but there is also a jQuery plug-in called jQWidon’t that places a non-breaking space between the last two words of an element.

Emphasis

Giving emphasis to a word without interrupting the reader is important. Italic is widely considered to be the ideal form of emphasis. Some other common forms of emphasis are: bold, caps, small caps, type size, color, underline or a different typeface. No matter which you choose, try to limit yourself to using only one. Combinations such as caps-bold-italic are disruptive and look clumsy.

Emphasis

Here are some difference ways of creating emphasis with CSS:

span {
font-variant: small-caps;
}
h1 {
font-style: italic;
}
h2 {
text-transform: uppercase;
}
a {
text-decoration: underline;
}

Keep in mind that the font-variant style only works if the font supports the small-caps variant.

Scale

Always compose with a scale, whether it’s the traditional scale developed in the sixteenth century that we’re all familiar with, or one you create on your own. A scale is important because it establishes a typographic hierarchy that improves readability and creates harmony and cohesiveness within the text.

Scale

An example of a typographic scale defined in CSS:

h1 {
font-size: 48px;
}
h2 {
font-size: 36px;
}
h3 {
font-size: 24px;
}
h4 {
font-size: 21px;
}
h5 {
font-size: 18px;
}
h6 {
font-size: 16px;
}
p {
font-size: 14px;
}

Clean Rags

When setting a block of text unjustified with a left or right alignment, be sure to keep the rag (the uneven side) balanced without any sudden “holes” or awkward shapes. A bad rag can be unsettling to the eye and distract the reader. A good rag has a “soft” unevenness, without any lines that are too long or too short. There is no way of controlling this in CSS, so to achieve a good rag you must make manual adjustments to the block of text.

Rags

Hyphenation can also help with producing clean rags, but unfortunately CSS can’t handle this at the moment. Maybe in the near future we’ll see some control in CSS 3. Not all is lost though. There are some server and client side solutions for auto hyphenation like phpHyphenator and Hyphenator as well as online generators.

Special thanks for the source: http://www.aisleone.net/2009/design/8-ways-to-improve-your-typography

Drop Down Menus, Horizontal Style | Css Edge

The first and most important part of creating our menu is the menu structure itself. The best way to do this is to build an unordered list, with each sub-menu appearing as a list within its parent list item. Sound complicated? It’s actually very straightforward:

  <ul> 
<li><a href="#">Home</a></li>
<li><a href="#">About</a>
<ul>
<li><a href="#">History</a></li>
<li><a href="#">Team</a></li>
<li><a href="#">Offices</a></li>
</ul>
</li>
<li><a href="#">Services</a>
<ul>
<li><a href="#">Web Design</a></li>
<li><a href="#">Internet
Marketing</a></li>
<li><a href="#">Hosting</a></li>
<li><a href="#">Domain Names</a></li>
<li><a href="#">Broadband</a></li>
</ul>
</li>
<li><a href="#">Contact Us</a>
<ul>
<li><a href="#">United Kingdom</a></li>
<li><a href="#">France</a></li>
<li><a href="#">USA</a></li>
<li><a href="#">Australia</a></li>
</ul>
</li>
</ul>

That’s it: some simple HTML that is both accessible and easy to edit.

Visually appealing?


If you have previewed the menu above, you’ll see a pretty boring list of items. And I promised you it would be visually appealing! Let’s add some style.

The first step is to remove the indents and bullets from the unordered list and define the width of our menu items.

ul {
margin: 0;
padding: 0;
list-style: none;
width: 150px;
}

Next, we need to position our list items. Fortunately, these will stack vertically by default, which is what we require. However, we must set the position as relative, because we will need to position the sub-menus absolutely within them.

ul li {
position: relative;
}

Next step is the sub-menus. We want each sub-menu to appear to the right of its parent menu item when that item is hovered over.

li ul {
position: absolute;
left: 149px;
top: 0;
display: none;
}

Using the “left” and “top” attributes, we can absolutely position each sub-menu within its parent menu item. You will notice I have set the “left” property to 149px (1px less than the width of the menu items), which allows the sub-menus to overlap the main menu and not produce a double border. (You’ll see what I mean later.)

We have also set display to “none,” as we don’t want the sub-menus to be visible by default.

So now we have the framework in place, but it’s still looking a bit plain. Let’s style those links.

ul li a {
display: block;
text-decoration: none;
color: #777;
background: #fff;
padding: 5px;
border: 1px solid #ccc;
border-bottom: 0;
}

I have styled the links to my taste, but they can be changed to your preference, as you wish. It is important to set display to “block,” as we want each link to take up all the available space of its containing list item.

So things are looking a little better, although users of Internet Explorer for Windows may disagree. Unfortunately, IE Win interprets the line breaks between our nicely formatted HTML list items as white space, so you will notice that the menu items don’t stack up neatly in that browser. However, there is a way around IE’s bugs:

/* Fix IE. Hide from IE Mac \*/
* html ul li { float: left; }
* html ul li a { height: 1%; }
/* End */

We can apply the Holly Hack above, which hides these rules from all browsers but IE Win. Perfect. You will notice the height: 1% rule that has also been added. Unfortunately (again!) the float fix uncovers another IE bug, which requires a height value to make the links display as block-level elements.

You will also notice the need to close the menu, which can be done by adding the missing border to the bottom of the list. So, the ul rule becomes:

ul {
margin: 0;
padding: 0;
list-style: none;
width: 150px;
border-bottom: 1px solid #ccc;
}

With some luck, everyone should now be able to see the unfunctional menu.

Making it work


Now the fun bit. We need to make those sub-menus appear when we hover over the menu items.

li:hover ul { display: block; }

Voila...here’s the bare bones menu in action.

“Woo hoo! It works!” I hear 1% of you shout. “Awesome!”

OK, OK, so that darn IE/Win has to ruin everything and not do as it’s told. IE/Win only allows the :hover pseudo-class to be applied to a link — so the li:hover that makes the sub-menus appear means nothing to IE.

A tiny jot of JavaScript is required to kick IE back into action (line wraps marked » — Ed.):

startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
}
node.onmouseout=function() {
this.className=this.className.replace»
(" over", "");
}
}
}
}
}
window.onload=startList;


Great thanks and appreciation is due here to Patrick Griffiths and Dan Webb, who introduced this trickery in a previous ALA article, Suckerfish Dropdowns. Thanks, guys!

So, the hover rule now becomes:

li:hover ul, li.over ul { 
display: block; }

Additionally, we also need to associate the JavaScript with our main ul, which becomes:

<ul id="nav">

Hopefully, with the above tweaks in place, everyone should be able to see a simple version of the menu in action.

IE5.01 Jumping Menu Bug

Anyone using IE5.01 on Windows will notice that the menu jumps around when you hover over some of its items. The problem is easily fixed by modifying our previous hacks as follows:

/* Fix IE. Hide from IE Mac \*/
* html ul li { float: left; height: 1%; }
* html ul li a { height: 1%; }
/* End */


Mystery IE6 Bug:

During the development of this article, I uncovered a strange bug that I believe is only apparent in IE6. A background must be declared on the li a, else when a sub-menu stretches further (vertically) than the main menu itself, the links start to disappear before you have time to click them. Strange! Try it to see for yourself.

CSS Transparency Settings for All Browsers

Transparency is one of those weird things that is treated completely differently in all browsers. To cover all your bases, you need four separate CSS statements. Fortunately they don’t interfere with each other really, so using them all every time you wish to add transparency is no big hassle and worry-free. Here they are, and are currently set to 50% transparency:

.transparent_class {
filter:alpha(opacity=50);
-moz-opacity:0.5;
-khtml-opacity: 0.5;
opacity: 0.5;
}
 

Here is what each of those CSS properties is for:


  • opacity: 0.5; This is the “most important” one because it is the current standard in CSS. This will work in most versions of Firefox, Safari, and Opera. This would be all you need if all browsers supported current standards. Which, of course, they don’t.
  • filter:alpha(opacity=50); This one you need for IE.
  • -moz-opacity:0.5; You need this one to support way old school versions of the Mozilla browsers like Netscape Navigator.
  • -khtml-opacity: 0.5; This is for way old versions of Safari (1.x) when the rendering engine it was using was still referred to as KTHML

List of CSS Tools : most useful CSS-Tools you can use developing tableless web-sites.


Fonts



Forms



Layout



Navigation


  • Colly’s CSS rollover generator

    CollyLogic CSS Multi-element Rollover Generator
  • CSS Tab Designer

    CSS Tab Designer is a unique and easy to use software to help you
    design css-based lists and tabs visually and without any programming
    knowledge required!
  • Listamatic

    not a tool but very useful! - one list, many options - Using CSS and a simple list to create radically different list
  • Listamatic2

    nested list options
  • List-O-Matic

    Generate CSS-styled navigation menus based on list items
  • List-O-Rama!

    Dreamweaver MX and UltraDev Zone - List-O-Rama will allow you to generate nice CSS inline menus in seconds
  • CSS Menu Generator

    CSS Menu Generator will generate both the CSS and the HTML code
    required to produce a text-based yet appealing set of navigation
    buttons.

Misc Tools


  • CSS Love Child

    The Man in Blue Experiment - I want the body of Site [...] with the face of site [...]
  • CSSVista

    CSSVista is a free Windows application for web developers which lets
    you edit your CSS code live in both Internet Explorer and Firefox
    simultaneously……
  • HTML and CSS Table Border Style Wizard

    Use this wizard to experiment with table border styles and generate style source code.
  • I Like Your Colors!

    Use this tool to extract the colors from the HTML and CSS of any web site. Compare the colors easily using hue groups.
  • Online CSS Scrollbar Color Changer

    Change the scrollbar colors in an HTML page
  • S5Easy: Create S5 Slideshows Easy Online

    Create your slideshow in only 3 steps
  • Spanky Corners

    ‘Spanky Corners’ is an experimental technique for using only CSS to
    produce ’round-cornered content boxes’ with semantically pure markup.
    It does not require JavaScript to work

Formatters and Optimizers



List of CSS Tools : most useful CSS-Tools you can use developing tableless web-sites.

most useful CSS-Tools you can use developing tableless web-sites.

Fonts



Forms



Layout



Navigation


  • Colly’s CSS rollover generator

    CollyLogic CSS Multi-element Rollover Generator
  • CSS Tab Designer

    CSS Tab Designer is a unique and easy to use software to help you
    design css-based lists and tabs visually and without any programming
    knowledge required!
  • Listamatic

    not a tool but very useful! - one list, many options - Using CSS and a simple list to create radically different list
  • Listamatic2

    nested list options
  • List-O-Matic

    Generate CSS-styled navigation menus based on list items
  • List-O-Rama!

    Dreamweaver MX and UltraDev Zone - List-O-Rama will allow you to generate nice CSS inline menus in seconds
  • CSS Menu Generator

    CSS Menu Generator will generate both the CSS and the HTML code
    required to produce a text-based yet appealing set of navigation
    buttons.

Misc Tools


  • CSS Love Child

    The Man in Blue Experiment - I want the body of Site [...] with the face of site [...]
  • CSSVista

    CSSVista is a free Windows application for web developers which lets
    you edit your CSS code live in both Internet Explorer and Firefox
    simultaneously……
  • HTML and CSS Table Border Style Wizard

    Use this wizard to experiment with table border styles and generate style source code.
  • I Like Your Colors!

    Use this tool to extract the colors from the HTML and CSS of any web site. Compare the colors easily using hue groups.
  • Online CSS Scrollbar Color Changer

    Change the scrollbar colors in an HTML page
  • S5Easy: Create S5 Slideshows Easy Online

    Create your slideshow in only 3 steps
  • Spanky Corners

    ‘Spanky Corners’ is an experimental technique for using only CSS to
    produce ’round-cornered content boxes’ with semantically pure markup.
    It does not require JavaScript to work

Formatters and Optimizers



Best CSS tools of the month


solidstategroup
"This article includes 8 helpful solutions which we find essential when designing with CSS".

jarrodspillers
"In
this day it is very common for a stylesheet to contain many times more
line of code than its corresponding XHTML document. Part of the
challenge of witting good CSS is not just learning the correct
properties to use, but formatting and organizing your document in a way
that allows for easy maintenance and speedy display bug fixes.".

search-this
50%
of the job might be to make your website look and act the same in all
major browsers. This is a nightmare for all designers. While you're
swearing you might try this out...

dnevnikeklektika
"Uni-Form
is an attempt to standardize form markup (xhtml) and css, "modularize"
it, so even people with only basic knowledge of these technologies can
get nice looking, well structured, highly customizable, semantic,
accessible and usable forms." - nice job.

csslicingguide
...learn to slice your templates into fully valid XHTML and CSS web pages.
yvoschaap
"This online generator creates your own custom unique WordPress Theme. Without any need for HTML, JS, PHP, or CSS knowledge".

ryanfait
"We've
all tried to use a sticky footer one time or another, but they never
seem to come out right, do they? Well, the days of a hard to understand
CSS-based sticky footer are thankfully over".

wittysparks
"With
new technologies flooding the web,different tools are available with
which a web designer can showcase his creativity and craft. But despite
putting in the effort and sweat, numerous websites with fantastic
creativity fail to get noticed. Also, the surge in designing is driving
designers to dig for creativity, color schemes and layouts."

borkweb
Using
icons in your web pages can have a great visual impact but it also
makes it harder to load. Learn by example how to use concatenation to
speed up your web applications.

campaignmonitor
"Inspired
by the fantastic work of Xavier Frenette, we decided to put each of the
popular email environments to the test and finalize once and for all
what CSS is and isn't supported out there".

csstinderbox
"The
CSS Tinderbox is an effort to support open source web design by
providing very basic, yet solid, CSS/XHTML design templates that web
designers and web developers can use as the foundation for their own
projects."

hostm
"To
help you work with CSS, we've created a free tool called Simple CSS,
which runs on Macs, Windows and Linux. Simple CSS allows you to easily
create Cascading Style Sheets from scratch, and/or modify existing
ones, using a familiar point-and-click interface."

30 Exceptional CSS Techniques and Examples


In this article, I’ve pieced together 30 excellent CSS techniques and examples that showcases the capabilities and robustness of CSS. You’ll see a variety of techniques such as image galleries, drop shadows, scalable buttons, menus, and more - all using only CSS and HTML.


Clicking on the title will direct you to the documentation/tutorial, while clicking on the accompanying image will direct you to the demo page if it’s separate from the documentation.


1. Hoverbox Image Gallery


A pure css-based gallery; hovering over an image enlarges it.


Hoverbox Image Gallery



2. Advanced CSS Menu


A creative and complex navigation scheme.


Advanced CSS Menu


3. Sliding Photograph Galleries


An accordion effect; hovering over an image expands it.


Stu Nicholls: CSSplay- Sliding Photograph Galleries


4. Lightbox Slides


Part of an article entitled "Supercharge your image borders" showcasing how you can use CSS styles to make images look more interesting.


Bite Size Standards - Supercharge your image borders


5. Drop shadow on an image


Aan image effect demo and discussion based on a A List Apart article entitled, "CSS Drop shadows".


Drop shadow on an image


6. Cross Browser Multi-Page Photograph Gallery


Hovering over the tabs changes the category, while hovering over an image enlarges it.


Stu Nicholls: CSSplay - Cross Browser Multi Page Photograph Gallery


7. CSS Photo Zoom


Uses a single image and adjustment of the background-position attribute.


SimpleBits - CSS Photo Zoom


8. CSS gallery layout—smells like a table


Mimics a table layout, but uses lists. The gallery is also fluid width.


Dnevnik eklektika - CSS gallery layout—smells like a table


9. Sticky Footer


A static footer with very little XHTML required.


Sticky Footer


10. whatever: hover


A navigation menu that mimics Window’s Start menu.


Peterned - whatever: hover


11. CSS-Only Accordion Effect


An accordion effect using div’s and :hover; the accordion effect can be vertical or horizontal.


The CSS-Only Accordion Effect - CSSnewbie


12. Scalable CSS Buttons Using PNG and Background Colors


A technique that addresses vertical scaling, the use of many images, and lack of a hover effect.


Scalable CSS Buttons Using PNG and Background Colors - David’s kitchen


13. Pushbutton Links


links that are styled to look like buttons without using images.


MikeCherim.com - Pushbutton Links


14. Scrollable Table with Fixed Header


The table’s captions stay put which is excellent for long tables.


Scrollable Table with Fixed Header


15. Content Overlay with CSS


When you hover over the image, the container div is shown with more text.


Snook.ca -  Content Overlay with CSS


16. A CSS styled table version 2


A beautifully styled, table with semantic mark-up - uses a background image.


A CSS styled table version 2


17. PNG Overlay


Another way to add flare to images (rounds the corners and adds a border and drop shadow).


PNG Overlay


18. Showing Hyperlink Cues with CSS


Simple tutorial on adding icons to different types of links.


Ask the CSS Guy - Showing Hyperlink Cues with CSS


19. Simple Rounded Corner CSS Boxes


Uses only one image and very few lines of code and mark-up.


MODx Content Management System - Simple Rounded Corner CSS Boxes


20. Sitemap Celebration


Tree-like navigation using nested lists, great for sitemap pages.


Zab Design - Sitemap Celebration


21. Easy cross-browser transparency


Opacity technique without the use of JavaScript (but at the cost of using non-valid XHTML code).


Bite Size Standards - Easy cross-browser transparency


 


22. Curved corners 2


Fluid width and height divs with rounded corners.


HTML Dog - Curved corners 2


23. Creating a graph using percentage background images


List items

  • styled into bar graphs.


    Creating a Graph using Percentage Background


    24. CSS Bar Graphs: Examples


    3 bar graph examples - "Basic CSS Bar Graph", "Complex CSS Bar Graph", and "Vertical CSS Bar Graph" using div’s and definition list tags.


    CSS Bar Graphs: Example


    25. Animated Rollover Arrow


    The arrow follows along the entire width of the navigation bar smoothly, without the use of JavaScript or animated gif’s.


    Animated Rollover Arrow


    26. A CSS-based Form Template


    Showcases an accessible web form.


    Nidahas - Forms markup and CSS - Revisite


    27. CSS Image Text Wrap


    Using empty spacer div’s, the page’s text mimics a wrapping effect around the background image.


    CSS Image Text Wrap


    28. Before your very eyes - a fade-in image


    A demo using opacity and a single image that gradually fades in to cover the text.


    CSS Play - Before your very eyes - a fade-in image


    29. Pure CSS Pop-ups


    A pop-up technique that works even in IE 5 Mac.



    30. CSS Gradient Text Effect


    Uses background image overlays, and empty span tag, and position: absolute to create a gradient effect on text.