IMG-LOGO

CSS3 Box Sizing

andy - 13 May, 2014 4195 Views 0 Comment

As you know many browsers treat margin and padding differently. When you combine with width or height of an element box, you find out that the final dimension is completely different when you view with different browser. Well, this now can be easily taken care by using the new CSS box-sizing property. In CSS3, box-sizing property is used to define the dimension of its element by combining the size of padding, content or border. There are types of box-sizing available. They are as follow:

1. content-box

The height and width properties will only include size dimension only. Padding, margin and border dimension are not included.

2. border-box

The height and width properties will only include padding and border dimension only.

3. padding-box

The height and width properties will only include include padding dimension only.

Example of CSS3 box-sizing

Example 1
Using content-box style



Example 2
Using border-box style



Example 3
Using padding-box style



Style sheet codes

<style type="text/css">
	.content-box{
		width:240px;
		height:70px;
		margin:10;
		padding:10px;
		border:5px solid #ccc;
		box-sizing: content-box;
		-webkit-box-sizing: content-box;
		-moz-box-sizing: content-box;
		background:#365be8;
		color:#fff;
		text-transform:uppercase;
		text-align:center;
	}

	.border-box{
		width:240px;
		height:70px;
		margin:10;
		padding:10px;
		border:5px solid #ccc;
		box-sizing: border-box;
		-webkit-box-sizing: border-box;
		-moz-box-sizing: border-box;
		background:#365be8;
		color:#fff;
		text-transform:uppercase;
		text-align:center;
	}

	.padding-box{
		width:240px;
		height:70px;
		margin:10;
		padding:10px;
		border:5px solid #ccc;
		box-sizing: padding-box;
		-webkit-box-sizing: padding-box;
		-moz-box-sizing: padding-box;
		background:#365be8;
		color:#fff;
		text-transform:uppercase;
		text-align:center;
	}
</style>

Comments

There are no comments available.

Write Comment
0 characters entered. Maximum characters allowed are 1000 characters.

Related Blogs

How to draw a circle in CSS?

In this article, we are going to learn how to draw a circle in CSS. Firstly what needs to do is to create a CSS class called circle.

Related Tutorials

Media Queries

Learn how to use media queries in CSS3 Media queries are simple conditions used to targetting different devices for tables phones or desktop computers As each device may have different view size media queries become so handy to use to ...

CSS3 Border Radius

With new CSS3 border radius style you can easily create rounded corners for an image or html tag object Back in old days when we want to create a rounded border around an image or object we usually create 4 ...

CSS3 Multiple Column

Learn how to use multiple column property in CSS3 To create multiple columns in CSS3 is now so handy you just need to include a css built in keyword column count to do the job for you No more table ...

CSS3 Opacity

Learn how to use opacity property in CSS3. So what is actually opacity? CSS3 Opacity defines a transparency level of an element. The property value of opacity is range from 0 to 1.

Advanced Selectors

Learn how to use advanced selectors in CSS3. By using the built in pseudo-class, performing a selector in CSS3 is so much easy.