Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TITLE: HTML Styles - CSS
- TAGS: Example
- TIME: 6:27 AM Monday, January 03, 2022
- CONTENT: Internal CSS Example:-
- <!DOCTYPE html>
- <html>
- <head>
- <style>
- body {background-color: powderblue;}
- h1 {color: blue;}
- p {color: red;}
- </style>
- </head>
- <body>
- <h1>This is a heading</h1>
- <p>This is a paragraph.</p>
- </body>
- </html>
- -=-=-=-=-=-=-=-=-=-=-END=-=-=-=-=-=-=-=-=-=--=-=-=-
- External CSS Example:-
- "styles.css":
- body {
- background-color: powderblue;
- }
- h1 {
- color: blue;
- }
- p {
- color: red;
- }
- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- <!DOCTYPE html>
- <html>
- <head>
- <link rel="stylesheet" href="styles.css">
- </head>
- <body>
- <h1>This is a heading</h1>
- <p>This is a paragraph.</p>
- </body>
- </html>
- -=-=-=-=-=-=-=-=-=-=-END=-=-=-=-=-=-=-=-=-=--=-=-=-
- Example
- Use of CSS color, font-family and font-size properties:
- <!DOCTYPE html>
- <html>
- <head>
- <style>
- h1 {
- color: blue;
- font-family: verdana;
- font-size: 300%;
- }
- p {
- color: red;
- font-family: courier;
- font-size: 160%;
- }
- </style>
- </head>
- <body>
- <h1>This is a heading</h1>
- <p>This is a paragraph.</p>
- </body>
- </html>
- -=-=-=-=-=-=-=-=-=-=-END=-=-=-=-=-=-=-=-=-=--=-=-=-
- Example
- Use of CSS border property:
- p {
- border: 2px solid powderblue;
- }
- -=-=-=-=-=-=-=-=-=-=-END=-=-=-=-=-=-=-=-=-=--=-=-=-
- Example
- Use of CSS border and padding properties:
- p {
- border: 2px solid powderblue;
- padding: 30px;
- }
- -=-=-=-=-=-=-=-=-=-=-END=-=-=-=-=-=-=-=-=-=--=-=-=-
- Example
- Use of CSS border and margin properties:
- p {
- border: 2px solid powderblue;
- margin: 50px;
- }
- -=-=-=-=-=-=-=-=-=-=-END=-=-=-=-=-=-=-=-=-=--=-=-=-
- Example 1
- This example uses a full URL to link to a style sheet:
- <link rel="stylesheet" href="https://www.w3schools.com/html/styles.css">
- Example 2
- This example links to a style sheet located in the html folder on the
- current web site:
- <link rel="stylesheet" href="/html/styles.css">
- Example 3
- This example links to a style sheet located in the same folder as the
- current page:
- <link rel="stylesheet" href="styles.css">
- -=-=-=-=-=-=-=-=-=-=-END=-=-=-=-=-=-=-=-=-=--=-=-=-
- CSS Example
- body {
- background-color: lightblue;
- }
- h1 {
- color: white;
- text-align: center;
- }
- p {
- font-family: verdana;
- font-size: 20px;
- }
- -=-=-=-=-=-=-=-=-=-=-END=-=-=-=-=-=-=-=-=-=--=-=-=-
- Example
- In this example all <p> elements will be center-aligned, with a red text
- color:
- p {
- color: red;
- text-align: center;
- }
- Example
- Here, all <p> elements on the page will be center-aligned, with a red text
- color:
- p {
- text-align: center;
- color: red;
- }
- Example
- The CSS rule below will be applied to the HTML element with id="para1":
- #para1 {
- text-align: center;
- color: red;
- }
- Example
- In this example all HTML elements with class="center" will be red and
- center-aligned:
- .center {
- text-align: center;
- color: red;
- }
- Example
- In this example only <p> elements with class="center" will be red and
- center-aligned:
- p.center {
- text-align: center;
- color: red;
- }
- Example
- In this example the <p> element will be styled according to class="center"
- and to class="large":
- <p class="center large">This paragraph refers to two classes.</p>
- Example
- The CSS rule below will affect every HTML element on the page:
- * {
- text-align: center;
- color: blue;
- }
- -=-=-=-=-=-=-=-=-=-=-END=-=-=-=-=-=-=-=-=-=--=-=-=-
- The CSS Grouping Selector
- The grouping selector selects all the HTML elements with the same style
- definitions.
- Look at the following CSS code (the h1, h2, and p elements have the same
- style definitions):
- h1 {
- text-align: center;
- color: red;
- }
- h2 {
- text-align: center;
- color: red;
- }
- p {
- text-align: center;
- color: red;
- }
- Example
- In this example we have grouped the selectors from the code above:
- h1, h2, p {
- text-align: center;
- color: red;
- }
- -=-=-=-=-=-=-=-=-=-=-END=-=-=-=-=-=-=-=-=-=--=-=-=-
- How To Add CSS
- Three Ways to Insert CSS
- There are three ways of inserting a style sheet:
- 1 External CSS
- 2 Internal CSS
- 3 Inline CSS
- Example
- External styles are defined within the <link> element, inside the <head>
- section of an HTML page:
- "mystyle.css"
- body {
- background-color: lightblue;
- }
- h1 {
- color: navy;
- margin-left: 20px;
- }
- -=-=-=-=-=-=-=-=-=-=-
- <!DOCTYPE html>
- <html>
- <head>
- <link rel="stylesheet" href="mystyle.css">
- </head>
- <body>
- <h1>This is a heading</h1>
- <p>This is a paragraph.</p>
- </body>
- </html>
- -=-=-=-=-=-=-=-=-=-=-
- Example
- Internal styles are defined within the <style> element, inside the <head>
- section of an HTML page:
- <!DOCTYPE html>
- <html>
- <head>
- <style>
- body {
- background-color: linen;
- }
- h1 {
- color: maroon;
- margin-left: 40px;
- }
- </style>
- </head>
- <body>
- <h1>This is a heading</h1>
- <p>This is a paragraph.</p>
- </body>
- </html>
- -=-=-=-=-=-=-=-=-=-=-
- Example
- Inline styles are defined within the "style" attribute of the relevant
- element:
- <!DOCTYPE html>
- <html>
- <body>
- <h1 style="color:blue;text-align:center;">This is a heading</h1>
- <p style="color:red;">This is a paragraph.</p>
- </body>
- </html>
- -=-=-=-=-=-=-=-=-=-=-END=-=-=-=-=-=-=-=-=-=--=-=-=-
- Example
- If the internal style is defined after the link to the external style sheet,
- the <h1> elements will be "orange":
- <head>
- <link rel="stylesheet" type="text/css" href="mystyle.css">
- <style>
- h1 {
- color: orange;
- }
- </style>
- </head>
- -=-=-=-=-=-=-=-=-=-=-
- Example
- However, if the internal style is defined before the link to the external
- style sheet, the <h1> elements will be "navy":
- <head>
- <style>
- h1 {
- color: orange;
- }
- </style>
- <link rel="stylesheet" type="text/css" href="mystyle.css">
- </head>
- -=-=-=-=-=-=-=-=-=-=-END=-=-=-=-=-=-=-=-=-=--=-=-=-
- CSS Comments
- Example
- /* This is a single-line comment */
- p {
- color: red;
- }
- Example
- p {
- color: red; /* Set text color to red */
- }
- Example
- /* This is
- a multi-line
- comment */
- p {
- color: red;
- }
- HTML and CSS Comments
- From the HTML tutorial, you learned that you can add comments to your HTML
- source by using the <!--...--> syntax.
- In the following example, we use a combination of HTML and CSS comments:
- Example
- <!DOCTYPE html>
- <html>
- <head>
- <style>
- p {
- color: red; /* Set text color to red */
- }
- </style>
- </head>
- <body>
- <h2>My Heading</h2>
- <!-- These paragraphs will be red -->
- <p>Hello World!</p>
- <p>This paragraph is styled with CSS.</p>
- <p>CSS comments are not shown in the output.</p>
- </body>
- </html>
- -=-=-=-=-=-=-=-=-=-=-END=-=-=-=-=-=-=-=-=-=--=-=-=-
- CSS/HTML support 140 standard color names.
- CSS Background Color
- AliceBlue
- #F0F8FF
- AntiqueWhite
- #FAEBD7
- Aqua
- #00FFFF
- Aquamarine
- #7FFFD4
- Azure
- #F0FFFF
- Beige
- #F5F5DC
- Bisque
- #FFE4C4
- Black
- #000000
- BlanchedAlmond
- #FFEBCD
- Blue
- #0000FF
- BlueViolet
- #8A2BE2
- Brown
- #A52A2A
- BurlyWood
- #DEB887
- CadetBlue
- #5F9EA0
- Chartreuse
- #7FFF00
- Chocolate
- #D2691E
- Coral
- #FF7F50
- CornflowerBlue
- #6495ED
- Cornsilk
- #FFF8DC
- Crimson
- #DC143C
- Cyan
- #00FFFF
- DarkBlue
- #00008B
- DarkCyan
- #008B8B
- DarkGoldenRod
- #B8860B
- DarkGray
- #A9A9A9
- DarkGrey
- #A9A9A9
- DarkGreen
- #006400
- DarkKhaki
- #BDB76B
- DarkMagenta
- #8B008B
- DarkOliveGreen
- #556B2F
- DarkOrange
- #FF8C00
- DarkOrchid
- #9932CC
- DarkRed
- #8B0000
- DarkSalmon
- #E9967A
- DarkSeaGreen
- #8FBC8F
- DarkSlateBlue
- #483D8B
- DarkSlateGray
- #2F4F4F
- DarkSlateGrey
- #2F4F4F
- DarkTurquoise
- #00CED1
- DarkViolet
- #9400D3
- DeepPink
- #FF1493
- DeepSkyBlue
- #00BFFF
- DimGray
- #696969
- DimGrey
- #696969
- DodgerBlue
- #1E90FF
- FireBrick
- #B22222
- FloralWhite
- #FFFAF0
- ForestGreen
- #228B22
- Fuchsia
- #FF00FF
- Gainsboro
- #DCDCDC
- GhostWhite
- #F8F8FF
- Gold
- #FFD700
- GoldenRod
- #DAA520
- Gray
- #808080
- Grey
- #808080
- Green
- #008000
- GreenYellow
- #ADFF2F
- HoneyDew
- #F0FFF0
- HotPink
- #FF69B4
- IndianRed
- #CD5C5C
- Indigo
- #4B0082
- Ivory
- #FFFFF0
- Khaki
- #F0E68C
- Lavender
- #E6E6FA
- LavenderBlush
- #FFF0F5
- LawnGreen
- #7CFC00
- LemonChiffon
- #FFFACD
- LightBlue
- #ADD8E6
- LightCoral
- #F08080
- LightCyan
- #E0FFFF
- LightGoldenRodYellow
- #FAFAD2
- LightGray
- #D3D3D3
- LightGrey
- #D3D3D3
- LightGreen
- #90EE90
- LightPink
- #FFB6C1
- LightSalmon
- #FFA07A
- LightSeaGreen
- #20B2AA
- LightSkyBlue
- #87CEFA
- LightSlateGray
- #778899
- LightSlateGrey
- #778899
- LightSteelBlue
- #B0C4DE
- LightYellow
- #FFFFE0
- Lime
- #00FF00
- LimeGreen
- #32CD32
- Linen
- #FAF0E6
- Magenta
- #FF00FF
- Maroon
- #800000
- MediumAquaMarine
- #66CDAA
- MediumBlue
- #0000CD
- MediumOrchid
- #BA55D3
- MediumPurple
- #9370DB
- MediumSeaGreen
- #3CB371
- MediumSlateBlue
- #7B68EE
- MediumSpringGreen
- #00FA9A
- MediumTurquoise
- #48D1CC
- MediumVioletRed
- #C71585
- MidnightBlue
- #191970
- MintCream
- #F5FFFA
- MistyRose
- #FFE4E1
- Moccasin
- #FFE4B5
- NavajoWhite
- #FFDEAD
- Navy
- #000080
- OldLace
- #FDF5E6
- Olive
- #808000
- OliveDrab
- #6B8E23
- Orange
- #FFA500
- OrangeRed
- #FF4500
- Orchid
- #DA70D6
- PaleGoldenRod
- #EEE8AA
- PaleGreen
- #98FB98
- PaleTurquoise
- #AFEEEE
- PaleVioletRed
- #DB7093
- PapayaWhip
- #FFEFD5
- PeachPuff
- #FFDAB9
- Peru
- #CD853F
- Pink
- #FFC0CB
- Plum
- #DDA0DD
- PowderBlue
- #B0E0E6
- Purple
- #800080
- RebeccaPurple
- #663399
- Red
- #FF0000
- RosyBrown
- #BC8F8F
- RoyalBlue
- #4169E1
- SaddleBrown
- #8B4513
- Salmon
- #FA8072
- SandyBrown
- #F4A460
- SeaGreen
- #2E8B57
- SeaShell
- #FFF5EE
- Sienna
- #A0522D
- Silver
- #C0C0C0
- SkyBlue
- #87CEEB
- SlateBlue
- #6A5ACD
- SlateGray
- #708090
- SlateGrey
- #708090
- Snow
- #FFFAFA
- SpringGreen
- #00FF7F
- SteelBlue
- #4682B4
- Tan
- #D2B48C
- Teal
- #008080
- Thistle
- #D8BFD8
- Tomato
- #FF6347
- Turquoise
- #40E0D0
- Violet
- #EE82EE
- Wheat
- #F5DEB3
- White
- #FFFFFF
- WhiteSmoke
- #F5F5F5
- Yellow
- #FFFF00
- YellowGreen
- #9ACD32
- -=-=-=-=-=-=-=-=-=-=-END=-=-=-=-=-=-=-=-=-=--=-=-=-
- Example:CSS Background Color
- <h1 style="background-color:DodgerBlue;">Hello World</h1>
- <p style="background-color:Tomato;">Lorem ipsum...</p>
- Example:CSS Text Color
- <h1 style="color:Tomato;">Hello World</h1>
- <p style="color:DodgerBlue;">Lorem ipsum...</p>
- <p style="color:MediumSeaGreen;">Ut wisi enim...</p>
- Example:CSS Border Color
- <h1 style="border:2px solid Tomato;">Hello World</h1>
- <h1 style="border:2px solid DodgerBlue;">Hello World</h1>
- <h1 style="border:2px solid Violet;">Hello World</h1>
- -=-=-=-=-=-=-=-=-=-=-=-=-=-
- Example:CSS Color Values
- rgb(255, 99, 71)
- #ff6347
- hsl(9, 100%, 64%)
- Same as color name "Tomato", but 50% transparent:
- rgba(255, 99, 71, 0.5)
- hsla(9, 100%, 64%, 0.5)
- Example
- <h1 style="background-color:rgb(255, 99, 71);">...</h1>
- <h1 style="background-color:#ff6347;">...</h1>
- <h1 style="background-color:hsl(9, 100%, 64%);">...</h1>
- <h1 style="background-color:rgba(255, 99, 71, 0.5);">...</h1>
- <h1 style="background-color:hsla(9, 100%, 64%, 0.5);">...</h1>
- Example HEX
- body {
- background-color: #fc9; /* same as #ffcc99 */
- }
- h1 {
- color: #f0f; /* same as #ff00ff */
- }
- p {
- color: #b58; /* same as #bb5588 */
- }
- -=-=-=-=-=-=-=-=-=-=-END-=-=-=-=-=-=-=-=-
- CSS Backgrounds
- In these chapters, you will learn about the following CSS background
- properties:
- 1 background-color
- 2 background-image
- 3 background-repeat
- 4 background-attachment
- 5 background-position
- 6 background (shorthand property)
- CSS background-color
- Example1
- The background color of a page is set like this:
- body {
- background-color: lightblue;
- }
- Example2
- Here, the <h1>, <p>, and <div> elements will have different background
- colors:
- h1 {
- background-color: green;
- }
- div {
- background-color: lightblue;
- }
- p {
- background-color: yellow;
- }
- Example:Opacity / Transparency
- The opacity property specifies the opacity/transparency of an element. It
- can take a value from 0.0 - 1.0. The lower value, the more transparent:
- div {
- background-color: green;
- opacity: 0.3;
- }
- Example:Transparency using RGBA
- div {
- background: rgba(0, 128, 0, 0.3) /* Green background with 30% opacity */
- }
- ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- END -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- TITLE: HTML Styles - CSS PART 2
- TAGS: Examples
- TIME: 9:45 AM Monday, January 03, 2022
- CONTENT: CSS Background Image
- Example
- Set the background image for a page:
- body {
- background-image: url("paper.gif");
- }
- Example 2
- This example shows a bad combination of text and background image. The text
- is hardly readable:
- body {
- background-image: url("bgdesert.jpg");
- }
- The background image can also be set for specific elements, like the <p>
- element:
- Example 3
- p {
- background-image: url("paper.gif");
- }
- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- END -=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- =-=-=-=-=-=-
- CSS Background Image Repeat
- Example
- body {
- background-image: url("gradient_bg.png");
- }
- Example 2
- body {
- background-image: url("gradient_bg.png");
- background-repeat: repeat-x;
- }
- CSS background-repeat: no-repeat
- Showing the background image only once is also specified by the background-
- repeat property:
- Example 3
- Show the background image only once:
- body {
- background-image: url("img_tree.png");
- background-repeat: no-repeat;
- }
- CSS background-position
- The background-position property is used to specify the position of the
- background image.
- Example 5
- Position the background image in the top-right corner:
- body {
- background-image: url("img_tree.png");
- background-repeat: no-repeat;
- background-position: right top;
- }
- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- END -=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- =-=-=-=-=-=-
- CSS Background Attachment
- Example 1
- Specify that the background image should be fixed:
- body {
- background-image: url("img_tree.png");
- background-repeat: no-repeat;
- background-position: right top;
- background-attachment: fixed;
- }
- Example 2
- Specify that the background image should scroll with the rest of the page:
- body {
- background-image: url("img_tree.png");
- background-repeat: no-repeat;
- background-position: right top;
- background-attachment: scroll;
- }
- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- END -=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- =-=-=-=-=-=-
- CSS Background Shorthand
- CSS background - Shorthand property
- To shorten the code, it is also possible to specify all the background
- properties in one single property. This is called a shorthand property.
- Instead of writing:
- body {
- background-color: #ffffff;
- background-image: url("img_tree.png");
- background-repeat: no-repeat;
- background-position: right top;
- }
- You can use the shorthand property background:
- Example 2
- Use the shorthand property to set the background properties in one
- declaration:
- body {
- background: #ffffff url("img_tree.png") no-repeat right top;
- }
- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- END -=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- =-=-=-=-=-=-
- All CSS Background Properties
- Property Description
- background Sets all the background properties in one declaration
- background-attachment Sets whether a background image is fixed or scrolls
- with the rest of the page
- background-clip Specifies the painting area of the background
- background-color Sets the background color of an element
- background-image Sets the background image for an element
- background-origin Specifies where the background image(s) is/are
- positioned
- background-position Sets the starting position of a background image
- background-repeat Sets how a background image will be repeated
- background-size Specifies the size of the background image(s)
- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- END -=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- =-=-=-=-=-=-
- CSS Borders
- CSS Border Style
- The border-style property specifies what kind of border to display.
- The following values are allowed:
- dotted - Defines a dotted border
- dashed - Defines a dashed border
- solid - Defines a solid border
- double - Defines a double border
- groove - Defines a 3D grooved border. The effect depends on the border-
- color value
- ridge - Defines a 3D ridged border. The effect depends on the border-
- color value
- inset - Defines a 3D inset border. The effect depends on the border-
- color value
- outset - Defines a 3D outset border. The effect depends on the border-
- color value
- none - Defines no border
- hidden - Defines a hidden border
- The border-style property can have from one to four values (for the top
- border, right border, bottom border, and the left border).
- Example
- Demonstration of the different border styles:
- 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;}
- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- END -=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- =-=-=-=-=-=-
- CSS Border Width
- Example 1
- Demonstration of the different border widths:
- p.one {
- border-style: solid;
- border-width: 5px;
- }
- p.two {
- border-style: solid;
- border-width: medium;
- }
- p.three {
- border-style: dotted;
- border-width: 2px;
- }
- p.four {
- border-style: dotted;
- border-width: thick;
- }
- Specific Side Widths
- The border-width property can have from one to four values (for the top
- border, right border, bottom border, and the left border):
- Example 2
- p.one {
- border-style: solid;
- border-width: 5px 20px; /* 5px top and bottom, 20px on the sides */
- }
- 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 */
- }
- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- END -=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- =-=-=-=-=-=-
- CSS Border Color
- The border-color property is used to set the color of the four borders.
- The color can be set by:
- name - specify a color name, like "red"
- HEX - specify a HEX value, like "#ff0000"
- RGB - specify a RGB value, like "rgb(255,0,0)"
- HSL - specify a HSL value, like "hsl(0, 100%, 50%)"
- transparent
- Note: If border-color is not set, it inherits the color of the element.
- Example 1
- Demonstration of the different border colors:
- p.one {
- border-style: solid;
- border-color: red;
- }
- p.two {
- border-style: solid;
- border-color: green;
- }
- p.three {
- border-style: dotted;
- border-color: blue;
- }
- Specific Side Colors
- The border-color property can have from one to four values (for the top
- border, right border, bottom border, and the left border).
- Example
- p.one {
- border-style: solid;
- border-color: red green blue yellow; /* red top, green right, blue bottom
- and yellow left */
- }
- HEX Values
- The color of the border can also be specified using a hexadecimal value
- (HEX):
- Example
- p.one {
- border-style: solid;
- border-color: #ff0000; /* red */
- }
- RGB Values
- Or by using RGB values:
- Example
- p.one {
- border-style: solid;
- border-color: rgb(255, 0, 0); /* red */
- }
- HSL Values
- You can also use HSL values:
- Example
- p.one {
- border-style: solid;
- border-color: hsl(0, 100%, 50%); /* red */
- }
- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- END -=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- =-=-=-=-=-=-
- CSS Border Sides
- CSS Border - Individual Sides
- From the examples on the previous pages, you have seen that it is possible
- to specify a different border for each side.
- In CSS, there are also properties for specifying each of the borders (top,
- right, bottom, and left):
- Example 1
- p {
- border-top-style: dotted;
- border-right-style: solid;
- border-bottom-style: dotted;
- border-left-style: solid;
- }
- The example above gives the same result as this:
- Example 2
- p {
- border-style: dotted solid;
- }
- Example 3
- /* 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;
- }
- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- END -=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- =-=-=-=-=-=-
- CSS Shorthand Border Property
- Like you saw in the previous page, there are many properties to consider
- when dealing with borders.
- To shorten the code, it is also possible to specify all the individual
- border properties in one property.
- The border property is a shorthand property for the following individual
- border properties:
- border-width
- border-style (required)
- border-color
- Example 1
- p {
- border: 5px solid red;
- }
- Left Border
- p {
- border-left: 6px solid red;
- background-color: lightgrey;
- }
- Bottom Border
- p {
- border-bottom: 6px solid red;
- background-color: lightgrey;
- }
- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- END -=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- =-=-=-=-=-=-
- CSS Rounded Borders
- The border-radius property is used to add rounded borders to an element:
- Normal border
- Round border
- Rounder border
- Roundest border
- Example
- p {
- border: 2px solid red;
- border-radius: 5px;
- }
- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- END -=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- =-=-=-=-=-=-
- All CSS Border Properties
- Property Description
- border Sets all the border properties in one declaration
- border-bottom Sets all the bottom border properties in one declaration
- border-bottom-color Sets the color of the bottom border
- border-bottom-style Sets the style of the bottom border
- border-bottom-width Sets the width of the bottom border
- border-color Sets the color of the four borders
- border-left Sets all the left border properties in one declaration
- border-left-color Sets the color of the left border
- border-left-style Sets the style of the left border
- border-left-width Sets the width of the left border
- border-radius Sets all the four border-*-radius properties for rounded
- corners
- border-right Sets all the right border properties in one declaration
- border-right-color Sets the color of the right border
- border-right-style Sets the style of the right border
- border-right-width Sets the width of the right border
- border-style Sets the style of the four borders
- border-top Sets all the top border properties in one declaration
- border-top-color Sets the color of the top border
- border-top-style Sets the style of the top border
- border-top-width Sets the width of the top border
- border-width Sets the width of the four borders
- ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- END -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- TITLE: HTML Styles - CSS
- TAGS: Examples
- TIME: 4:40 PM Monday, January 03, 2022
- CONTENT: CSS Margins
- 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
- Example
- Set different margins for all four sides of a <p> element:
- 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;
- top margin is 25px
- right margin is 50px
- bottom margin is 75px
- left margin is 100px
- Example
- Use the margin shorthand property with four values:
- p {
- margin: 25px 50px 75px 100px;
- }
- If the margin property has three values:
- margin: 25px 50px 75px;
- top margin is 25px
- right and left margins are 50px
- bottom margin is 75px
- Example
- Use the margin shorthand property with three values:
- p {
- margin: 25px 50px 75px;
- }
- If the margin property has two values:
- margin: 25px 50px;
- top and bottom margins are 25px
- right and left margins are 50px
- Example
- Use the margin shorthand property with two values:
- p {
- margin: 25px 50px;
- }
- If the margin property has one value:
- margin: 25px;
- all four margins are 25px
- Example
- Use the margin shorthand property with one value:
- p {
- margin: 25px;
- }
- Example
- Use margin: auto:
- div {
- width: 300px;
- margin: auto;
- border: 1px solid red;
- }
- Example
- Use of the inherit value:
- div {
- border: 1px solid red;
- margin-left: 100px;
- }
- p.ex1 {
- margin-left: inherit;
- }
- -=-=-=-=-=-=-=-=-=-=-END=-=-=-=-=-=-=-=-=-=--=-=-=-
- CSS Margin Collapse
- Example
- Demonstration of margin collapse:
- h1 {
- margin: 0 0 50px 0;
- }
- h2 {
- margin: 20px 0 0 0;
- }
- All CSS Margin Properties
- Property Description
- margin A shorthand property for setting the margin properties in one
- declaration
- margin-bottom Sets the bottom margin of an element
- margin-left Sets the left margin of an element
- margin-right Sets the right margin of an element
- margin-top Sets the top margin of an element
- ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- END -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Add Comment
Please, Sign In to add comment