CSS Border Properties - Midterm
CSS Border Properties - Midterm
The CSS border properties allow you to specify the style, A groove border. The effect depends on the
width, and color of an element's border. border-color value.
Border Style
A ridge border. The effect depends on the
border-color value.
The border-style property specifies what kind of border
to display.
An inset border. The effect depends on the
The following values are allowed: border-color value.
p.two {
A dashed border. border-style: solid;
border-width: medium;
A solid border. }
p.three {
border-style: dotted; The border-color property can have from one to four
border-width: 2px; values (for the top border, right border, bottom border,
} and the left border).
p.four { Example:
border-style: dotted;
border-width: thick; <!DOCTYPE html>
} <html>
<head>
p.five { <style>
border-style: double; p.one {
border-width: 15px; border-style: solid;
} border-color: red;
}
p.six {
border-style: double; p.two {
border-width: thick; border-style: solid;
} border-color: green;
}
p.seven {
border-style: solid; p.three {
border-width: 2px 10px 4px 20px; border-style: solid;
} border-color: red green blue yellow;
</style> }
</head> </style>
<body> </head>
<body>
<h2>The border-width Property</h2>
<p>This property specifies the width of the four <h2>The border-color Property</h2>
borders:</p> <p>This property specifies the color of the four
<p class="one">Some text.</p> borders:</p>
<p class="two">Some text.</p>
<p class="three">Some text.</p> <p class="one">A solid red border</p>
<p class="four">Some text.</p> <p class="two">A solid green border</p>
<p class="five">Some text.</p> <p class="three">A solid multicolor border</p>
<p class="six">Some text.</p> <p><b>Note:</b> The "border-color" property does not
<p class="seven">Some text.</p> work if it is used alone. Use the "border-style" property
<p><b>Note:</b> The "border-width" property does to set the borders first.</p>
not work if it is used alone.
Always specify the "border-style" property to set the </body>
borders first.</p> </html>
</body>
</html> Border - Shorthand Property
The border property is a shorthand property for the
Border Color following individual border properties:
The border-color property is used to set the color of the
four borders. The color can be set by: border-width
border-style (required)
name - specify a color name, like "red" border-color
Hex - specify a hex value, like "#ff0000"
RGB - specify a RGB value, like "rgb(255,0,0)"
transparent
Example: <style>
p.one {
<!DOCTYPE html> border: 1px solid red;
<html> background-color: yellow;
<head> padding-top: 50px;
<style> padding-right: 30px;
div { padding-bottom: 50px;
border: 5px solid red; padding-left: 80px;
} }
</style> </style>
</head> </head>
<body> <body>
The CSS padding properties are used to generate space Padding - Shorthand Property
around content. The padding properties set the size of
the white space between the element content and the To shorten the code, it is possible to specify all the
element border. The padding clears an area around the padding properties in one property.
content (inside the border) of an element. The padding property is a shorthand property for the
following individual padding properties that should be
Padding - Individual Sides in order:
CSS has properties for specifying the padding for each padding-top
side of an element: padding-right
padding-bottom
padding-top padding-left
padding-right
padding-bottom Example:
padding-left
<!DOCTYPE html>
All the padding properties can have the following <html>
values: <head>
<style>
length - specifies a padding in px, pt, cm, etc. p.one {
% - specifies a padding in % of the width of the border: 1px solid red;
containing element background-color: yellow;
inherit - specifies that the padding should be padding: 50px 30px 50px 80px;
inherited from the parent element }
</style>
Example: </head>
<body>
<!DOCTYPE html>
<html> <h2>Using The padding Shorthand Property:</h2>
<head>
<p>This is a paragraph with no specified padding.</p> </body>
<p class="one">This paragraph has a top and bottom </html>
padding of 50px, a left padding of 80px, and a right
padding of 30px.</p> Example for a Bottom Tooltip:
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
z-index: 1;
bottom: 100%;
left: 50%;
margin-left: -60px;
.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 1;
}
</style>
<body style="text-align:center;">
visible.</p>
</body>
</html>
CSS Links Links with Backgrounds:
<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content"> }
<a href="#">Link 1</a> img:hover {
<a href="#">Link 2</a> opacity: 1.0;
<a href="#">Link 3</a> filter: alpha(opacity=100); /* For IE8 and earlier */
</div> }
</div> </style>
</head>
<p><strong>Note:</strong> We use href="#" for test <body>
links. In a real web site this would be URLs.</p> <h1>Image Transparency</h1>
</body> <img src="pic.jpg" width="150" height="113" alt="pic">
</html> <img src="pic2.jpg" width="150" height="113"
alt="pic2">
CSS Image Opacity / Transparency
<p><b>Note:</b> In IE, a !DOCTYPE must be added for
Opacity is defined as the condition of lacking the :hover selector to work on other elements than the
transparency or translucence; opaqueness. a element.</p>
</body>
Example: </html>
<!DOCTYPE html>
<html> Text in Transparent Box
<head>
<style> <!DOCTYPE html>
img { <html>
opacity: 0.4; <head>
filter: alpha(opacity=40); /* For IE8 and earlier */ <style>
} div.background {
</style> background: url(klematis.jpg) repeat;
</head> border: 2px solid black;
<body> }
div.transbox {
<h1>Image Transparency</h1> margin: 30px;
<img src="picture.jpg" width="150" height="113" background-color: #ffffff;
alt="this is a picture of…"> border: 1px solid black;
opacity: 0.6;
</body> filter: alpha(opacity=60); /* For IE8 and earlier */
</html> }
div.transbox p {
The opacity property can take a value from 0.0 - 1.0. margin: 5%;
The lower value, the more it goes transparent. font-weight: bold;
color: #000000;
IE8 and earlier use filter:alpha(opacity=x). The x can }
take a value from 0 - 100. A lower value makes the </style>
element more transparent. </head>
<body>
Image Transparency - Hover Effect <div class="background">
<div class="transbox">
<!DOCTYPE html> <p>This is some text that is placed in the transparent
<html> box.</p>
<head> </div>
<style> </div>
img { </body>
opacity: 0.4; </html>
filter: alpha(opacity=40); /* For IE8 and earlier */