CSS 101: Block & Inline elements
Play with Display
If your new to CSS, you've probably stayed away from the "Display" property. Well you might be missing out on a powerful tool. It only has to values, or three things it can do, so it's easy to remember .
- display: inline;
- display: block;
- displa; none;
All three of these values are extremely useful. Think of the display:none that we used in last weeks tip on hiding elements on a page, like the birthday element that so many ladies hate... display:none; You can even hide sorts of stuff you don't want on your page and is not yet an option in the layout manager.
Block and Inline are just as powerful. Lets say you want the background color of a DIV with a ad or image in it to automatically span the width of your text, so as not to worry about setting an exact pixel width. You would use the INLINE value to do this, because a DIV is a block element.
The difference between Block and Inline These are the most common elements that are blocks, and it's pretty easy to see this because they are usually designed visually as blocks.
<div>
<p> </p>
<ul>
<li> <form>
<h1>
A Block element starts on it's own line. Think of everything on your web page like the flowing of text a paragraph. Block elements are when you hit the enter key and go to a new line. So if you have say a Block element like a H1 under a inline element (think text) your block element will drop down like you hit the enter key.
Here are some inline elements:
<span>
<strong>
<a>
<img>
<em>
The main difference between a block and a inline is hight and width, or those are at-least the most effective differences. A inline element's height and width, line hight, and top and bottom margins CAN NOT be changed. It will also span the width always of the image or text and can't be changed. It also begins on the same line.. so no enter key.
Useful Block Useful Inline A good way to use the inline value is in setting a Block element, say a DIV, to be inline, giving it a background color, and allowing it to span the width of that inline element. See, a Inline element will just go and go until something stops it, so you can allow that background color to go the width of the text and you don't even have to specify a width. So that's about it. Inline is kind of useful, you will find places for it as you get deeper in CSS, but Block is very useful, and a must in many situations.
2 Comments
Fishing Rods My friend may have his own reasons, louis vuitton handbagsbut I don't think
his decision is wise in reality. yy2010.5.5
Click here to sign up now.