Teacher: Stephen H. Herbilla Subject: Web Design 2 Date: September 21, 2020 References: Lesson Summary
Teacher: Stephen H. Herbilla Subject: Web Design 2 Date: September 21, 2020 References: Lesson Summary
Herbilla
Subject: Web Design 2
Date: September 21, 2020
References: https://www.w3schools.com/css/css_border.asp
Lesson Summary
CSS Borders
CSS Border Properties
The CSS border properties allow you to specify the style, width, and color of an element's
border.
The border-style property can have from one to four values (for the top border, right border, bottom
border, and the left border).
p.dotted {border-style: dotted;}
p.dashed {border-style: dashed;}
p.solid {border-style: solid;}
p.double {border-style: double;}
p.groove {border-style: groove;}
p.ridge {border-style: ridge;}
p.inset {border-style: inset;}
p.outset {border-style: outset;}
p.none {border-style: none;}
p.hidden {border-style: hidden;}
p.mix {border-style: dotted dashed solid double;}
p.two {
border-style: solid;
border-width: medium;
}
p.three {
border-style: dotted;
border-width: 2px;
}
p.four {
border-style: dotted;
border-width: thick;
}
p.two {
border-style: solid;
border-width: 20px 5px; /* 20px top and bottom, 5px on the sides */
}
p.three {
border-style: solid;
border-width: 25px 10px 4px 35px; /* 25px top, 10px right, 4px bottom and 35px left */
}
p.two {
border-style: solid;
border-color: green;
}
p.three {
border-style: dotted;
border-color: blue;
}
p {
border-top-style: dotted;
border-right-style: solid;
border-bottom-style: dotted;
border-left-style: solid;
}
/* Four values */
p {
border-style: dotted solid double dashed;
}
/* Three values */
p {
border-style: dotted solid double;
}
/* Two values */
p {
border-style: dotted solid;
}
/* One value */
p {
border-style: dotted;
}
You can also specify all the individual border properties for just one side:
Left border
p {
border-left: 6px solid red;
background-color: lightgrey;
}
Bottom Border
p {
border-bottom: 6px solid red;
background-color: lightgrey;
}
Teacher: Stephen H. Herbilla
Subject: Web Design 2
Date: September 28, 2020
References: https://www.w3schools.com/css/css_border.asp
Lesson Summary
CSS Borders
CSS Rounded Borders
The border-radius property is used to add rounded borders to an element:
p {
border: 2px solid red;
border-radius: 5px;
}
Teacher: Stephen H. Herbilla
Subject: Web Design 2
Date: September 29, 2020
References: https://www.w3schools.com/css/css_border.asp
Lesson Summary
CSS Margins
The CSS margin properties are used to create space around elements, outside of any defined
borders.
With CSS, you have full control over the margins. There are properties for setting the margin for
each side of an element (top, right, bottom, and left).
Margin - Individual Sides
CSS has properties for specifying the margin for each side of an element:
margin-top
margin-right
margin-bottom
margin-left
All the margin properties can have the following values:
auto - the browser calculates the margin
length - specifies a margin in px, pt, cm, etc.
% - specifies a margin in % of the width of the containing element
inherit - specifies that the margin should be inherited from the parent element
ex.
p {
margin-top: 100px;
margin-bottom: 100px;
margin-right: 150px;
margin-left: 80px;
}
Margin - Shorthand Property
To shorten the code, it is possible to specify all the margin properties in one property.
The margin property is a shorthand property for the following individual margin properties:
margin-top
margin-right
margin-bottom
margin-left
So, here is how it works:
If the margin property has four values:
margin: 25px 50px 75px 100px;
o top margin is 25px
o right margin is 50px
o bottom margin is 75px
o left margin is 100px
ex.
p {
margin: 25px 50px 75px 100px;
}
If the margin property has three values:
margin: 25px 50px 75px;
o top margin is 25px
o right and left margins are 50px
o bottom margin is 75px
p {
margin: 25px 50px 75px;
}
If the margin property has two values:
margin: 25px 50px;
o top and bottom margins are 25px
o right and left margins are 50px
p {
margin: 25px 50px;
}
If the margin property has one value:
margin: 25px;
o all four margins are 25px
Use the margin shorthand property with one value:
p {
margin: 25px;
}
The auto Value
You can set the margin property to auto to horizontally center the element within its container.
The element will then take up the specified width, and the remaining space will be split equally
between the left and right margins.
div {
width: 300px;
margin: auto;
border: 1px solid red;
}
The inherit Value
This example lets the left margin of the <p class="ex1"> element be inherited from the parent
element (<div>):
div {
border: 1px solid red;
margin-left: 100px;
}
p.ex1 {
margin-left: inherit;
}
Ex.
div {
padding-top: 50px;
padding-right: 30px;
padding-bottom: 50px;
padding-left: 80px;
}
ex.
Use the padding shorthand property with two values:
div {
padding: 25px 50px;
}
If the padding property has one value:
padding: 25px;
o all four paddings are 25px
Here, the <div> element is given a width of 300px. However, the actual width of the <div> element
will be 350px (300px + 25px of left padding + 25px of right padding):
div {
width: 300px;
padding: 25px;
}
To keep the width at 300px, no matter the amount of padding, you can use the box-sizing property.
This causes the element to maintain its width; if you increase the padding, the available content
space will decrease.
Use the box-sizing property to keep the width at 300px, no matter the amount of padding:
div {
width: 300px;
padding: 25px;
box-sizing: border-box;
}
div {
height: 200px;
width: 50%;
background-color: powderblue;
}
div {
height: 100px;
width: 500px;
background-color: powderblue;
}
Setting max-width
The max-width property is used to set the maximum width of an element.
The max-width can be specified in length values, like px, cm, etc., or in percent (%) of the containing
block, or set to none (this is default. Means that there is no maximum width).
The problem with the <div> above occurs when the browser window is smaller than the width of
the element (500px). The browser then adds a horizontal scrollbar to the page.
Using max-width instead, in this situation, will improve the browser's handling of small windows.
This <div> element has a height of 100 pixels and a max-width of 500 pixels:
div {
max-width: 500px;
height: 100px;
background-color: powderblue;
}
div {
width: 300px;
border: 15px solid green;
padding: 50px;
margin: 20px;
}
p.ex1 {
border: 2px solid black;
outline-style: solid;
outline-color: red;
}
p.ex2 {
border: 2px solid black;
outline-style: dotted;
outline-color: blue;
}
p.ex3 {
border: 2px solid black;
outline-style: outset;
outline-color: grey;
}
HEX Values
The outline color can also be specified using a hexadecimal value (HEX):
p.ex1 {
outline-style: solid;
outline-color: #ff0000; /* red */
}
RGB Values
Or by using RGB values:
p.ex1 {
outline-style: solid;
outline-color: rgb(255, 0, 0); /* red */
}
HSL Values
You can also use HSL values:
p.ex1 {
outline-style: solid;
outline-color: hsl(0, 100%, 50%); /* red */
}
Invert Color
The following example uses outline-color: invert, which performs a color inversion. This ensures
that the outline is visible, regardless of color background:
p.ex1 {
border: 1px solid yellow;
outline-style: solid;
outline-color: invert;
}
CSS Outline - Shorthand property
The outline property is a shorthand property for setting the following individual outline
properties:
outline-width
outline-style (required)
outline-color
The outline property is specified as one, two, or three values from the list above. The order of
the values does not matter.
The following example shows some outlines specified with the shorthand outline property:
p.ex1 {outline: dashed;}
p.ex2 {outline: dotted red;}
p.ex3 {outline: 5px solid yellow;}
p.ex4 {outline: thick ridge pink;}
Teacher: Stephen H. Herbilla
Subject: Web Design 2
Date: October 9, 2020
References: https://www.w3schools.com/css/css_border.asp
Lesson Summary
CSS Outline Offset
The outline-offset property adds space between an outline and the edge/border of an element.
The space between an element and its outline is transparent.
The following example specifies an outline 15px outside the border edge:
p {
margin: 30px;
border: 1px solid black;
outline: 1px solid red;
outline-offset: 15px;
}
The following example shows that the space between an element and its outline is transparent:
p {
margin: 30px;
background: yellow;
border: 1px solid black;
outline: 1px solid red;
outline-offset: 15px;
}