Setting margins with the margin property - HTML

In general, you need to be careful when using margins because they are the outermost layer of a page. If you set the margins of a body element to three inches on either side, for example, be sure to set the width of that same body element as well, or your page will look like that shown.

However, in theory, you should be able to set margins for the printed page without worrying about the body text running off to one side of the browser when you neglect to set the width of the page’s other elements.

This is because margins can be set using the margin property in CSS within an @page rule. Margins were covered in Chapter 20, Padding, Margins, and Borders. You can set the page margins, by simply using the margin property in the same manner as you use it anywhere else, as shown here:

@page { size: 3in 3in;margin: .5in; page-break-after: left; {

Bad margins

Bad margins

The margin settings should be ignored when being viewed on the Web when they’re set in an @page rule. However, once again, at the time of this writing, browser support for this feature is weak.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

HTML Topics