Lesson 12: Height and width

Up until now, we have not cared much about the dimensions of the elements we have worked with. In this lesson, we will take a look at how you easily can define the height and width of an element.

Setting the width [width]

With the width-property, you can define a certain width of an element.

The simple example below provides us with a box wherein text can be typed:

	
	div.box {
		width: 200px;
		border: 1px solid black;
		background: orange;
	}
	
	

Setting the height [height]

In the example above notice how the height of the box is set by the content of the box. You can affect the height of an element with the property height. As an example let us try to make the box in the example 500px high:

	
	div.box {
		height: 500px;
		width: 200px;
		border: 1px solid black;
		background: orange;
	}
	
	

Summary

Lesson 9, 10, 11 and 12 have given you an introduction to the box model in CSS. As you can probably see, the box model gives you many new options. You might have been using tables in HTML to create your layouts until now, but with CSS and the box model you should now be able to achieve elegant layouts more precisely and in accordance with the recommendations of W3C.


Related topics in the CSS ForumRepliesViews
Css style class for line height23316
I need to stretch the content width of my Weebly site14815
Css-lesson 12: height&width27818
Nav UL Bottom Border & LI Width?18883
Height and width - div.box210036

+ Post a new topic


<< Lesson 11: Borders

Lesson 13: Floating elements (floats) >>