Skip to main content

Lesson 12: Height and width css

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 91011 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.

Comments

Popular posts from this blog

HTML 5 Comments Tag

HTML 5 Comments Tag Description The HTML 'comments' tag is used for creating comments within your HTML code. Comments aren't displayed in the browser - they are simply there for the programmer's benefit. Comments can assist you, the HTML programmer, because you can write notes to yourself that explain what the code does. This is especially useful when you have a lot of code.

Lesson 10: Margin and padding css

Lesson 10: Margin and padding In the previous lesson you were introduced to the box model. In this lesson, we will look at how you can change the presentation of elements by setting the  margin  and  padding properties. Set the margin in an element Set the padding in an element Set the margin in an element An element has four sides: right, left, top and bottom. The  margin  is the distance from each side to the neighboring element (or the borders of the document). See also the diagram in  lesson 9  for an illustration.

Lesson 11: Borders css

Lesson 11: Borders Borders can be used for many things, for example as a decorative element or to underline a separation of two things. CSS gives you endless options when using borders in your pages. border-width border-color border-style border The width of borders [border-width]