CIS195 Web Authoring 1: HTML

More Page Layout Using CSS

Topics by Week for the Ten-Week Term
1. Intro to HTML 6. Layout with CSS
2. More HTML, file paths 7. CSS Grid, Flexbox
3. Site structure and navigation 8. HTML Forms
4. Formatting with CSS 9. Multimedia, Final
5. Project Propposal, Midterm 10. HTML Tables, Project Completion
11. Final

Contents

Q and A

 

The Box Model

All HTML elements can be thought of as having a box that wraps around the element's content with the three layers shown below:

CSS box model
By Nasir Darwish, Code Project Open License

 

Setting the border style

By default, the border is not visible. You need to set a visible border style before you can see it. These are the options for border-style:

Example:

 

Setting the width of border, margin or padding

Example of setting all widths:

You can set border, padding and margin independently for each side:

You can set them all at once using the shorthand property. The sequence is: top, right, bottom, left.

Example: border: 5px 10px 15px 20px;

Setting Colors

Border

You can set the color of the border like this: border-color: blue.

Padding

The color of an element's padding will be the same as the background color of the element. You can't set it separately.

Margin

The color of an element's margin will be the same color as the background of whatever element contains it. You can't set it separately. For example, a section contains a paragraph:

If the section has a blue background, and it contains a paragraph with a 10px margin. The margin of the paragraph will be blue too. Here's are the CSS rules that would do that:

 

Combined Settings

You can set width, style, and color in one property like this:

 

Creating Rounded Corners

Use the CSS border-radius property to give a block element rounded corners.

Example: border-radius: 5px 10px 15px 20px;

Example

References

 


Creative Commons License Web Authoring Lecture Notes, written by Brian Bird in 2018 and revised by Brian Bird in , are licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.