Example:
HTML structure
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
Explanation
<!DOCTYPE html> declaration defines that this document is an HTML5 document<html> element is the root element of an HTML page<head> element contains meta information about the HTML page<title> element specifies a title for the HTML page (which is shown in the browser's title bar or in the page's tab)<body> element defines the document's body, and is a container for all the visible contents, such as headings, paragraphs, images, hyperlinks, tables, lists, etc.<h1> element defines a large heading<p> element defines a paragraphAn HTML element is defined by a start tag, some content, and an end tag:
<tagname>Content goes here...</tagname>
The HTML element is everything from the start tag to the end tag:
<h1>My First Heading</h1>
<p>My first paragraph.</p>
| Start tag | Element content | End tag |
|---|---|---|
| <h1> | My First Heading | </h1> |
| <p> | My first paragraph. | </p> |
| <br> | none | none |
<html>
<head>
<title>Page title</title>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>
</html>
Here below are some example of Element
HTML elements with no content are called empty elements.
The <br> tag defines a line break, and is an empty element without a closing tag:
The <hr> tag defines a thematic break in an HTML page, and is most often displayed as a horizontal rule.
HTML headings are defined with the <h1> to <h6> tags.
<h1> defines the most important heading. <h6> defines the least important heading:
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
HTML paragraphs are defined with the <p> tag:
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
HTML links are defined with the <a> tag:
<a href="https://www.w3schools.com">This is a link</a>
HTML images are defined with the <img> tag.
The source file (src), alternative text (alt), width, and height are provided as attributes:
<img src="w3schools.jpg" alt="W3Schools.com" width="104" height="142">
The <a> tag defines a hyperlink. The href attribute specifies the URL of the page the link goes to:
<a href="https://www.google.com">Visit google</a>
The <img> tag is used to embed an image in an HTML page. The src attribute specifies the path to the image to be displayed:
<img src="img_girl.jpg">
The <img> tag should also contain the width and height attributes, which specifies the width and height of the image (in pixels):
<img src="img_girl.jpg" width="500" height="600">
The required alt attribute for the <img> tag specifies an alternate text for an image, if the image for some reason cannot be displayed. This can be due to slow connection, or an error in the src attribute, or if the user uses a screen reader.
<img src="img_girl.jpg" alt="Girl with a jacket">
The HTML style attribute is used to add styles to an element, such as color, font, size, and more.
The style attribute is used to add styles to an element, such as color, font, size, and more.
The CSS background-color property defines the background color for an HTML element.
<h1 style="background-color:powderblue;">This is a heading</h1>
<p style="background-color:tomato;">This is a paragraph.</p>
The CSS color property defines the text color for an HTML element:
<h1 style="color:blue;">This is a heading</h1>
<p style="color:red;">This is a paragraph.</p>
The CSS font-family property defines the font to be used for an HTML element:
<h1 style="font-family:verdana;">This is a heading</h1>
<p style="font-family:courier;">This is a paragraph.</p>
The CSS font-size property defines the text size for an HTML element:
<h1 style="font-size:300%;">This is a heading</h1>
<p style="font-size:160%;">This is a paragraph.</p>
The CSS text-align property defines the horizontal text alignment for an HTML element:
<h1 style="text-align:center;">Centered Heading</h1>
<p style="text-align:center;">Centered paragraph.</p>
Formatting elements were designed to display special types of text:
<b> - Bold text<strong> - Important text<i> - Italic text<em> - Emphasized text<mark> - Marked text<small> - Smaller text<del> - Deleted text<ins> - Inserted text<sub> - Subscript text<sup> - Superscript textThe HTML <b> element defines bold text, without any extra importance.
<b>This text is bold</b>
The HTML <strong> element defines text with strong importance. The content inside is typically displayed in bold.
<strong>This text is important!</strong>
HTML colors are specified with predefined color names, or with RGB, HEX, HSL, RGBA, or HSLA values.
In HTML, a color can be specified by using a color name (e.g. Tomato, Orange, DodgerBlue, MediumSeaGreen, Gray, SlateBlue, Violet, LightGray).
You can set the background color for HTML elements.
You can set the color of text.
You can set the color of borders.
In HTML, colors can also be specified using RGB values, HEX values, HSL values, RGBA values, and HSLA values.
The following three <div> elements have their background color set with RGB, HEX, and HSL values:
rgb(255, 99, 71)
#ff6347
hsl(9, 100%, 64%)
The following two <div> elements have their background color set with RGBA and HSLA values, which adds an Alpha channel to the color (here we have 50% transparency):
rgba(255, 99, 71, 0.5)
hsla(9, 100%, 64%, 0.5)
HTML tables allow web developers to arrange data into rows and columns.
The <table> tag defines an HTML table.
Each table row is defined with a <tr> tag. Each table header is defined with a <th> tag. Each table data/cell is defined with a <td> tag.
By default, the text in <th> elements are bold and centered.
By default, the text in <td> elements are regular and left-aligned.
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
The HTML class attribute is used to specify a class for an HTML element. Multiple HTML elements can share the same class.
The class attribute is often used to point to a class name in a style sheet. It can also be used by a JavaScript to access and manipulate elements with the specific class name.
To create a class; write a period (.) character, followed by a class name. Then, define the CSS properties within curly braces {}.
A file path describes the location of a file in a web site's folder structure.
| Path | Description |
|---|---|
| <img src="picture.jpg"> | The "picture.jpg" file is located in the same folder as the current page |
| <img src="images/picture.jpg"> | The "picture.jpg" file is located in the images folder in the current folder |
| <img src="/images/picture.jpg"> | The "picture.jpg" file is located in the images folder at the root of the current web |
| <img src="../picture.jpg"> | The "picture.jpg" file is located in the folder one level up from the current folder |
An absolute file path is the full URL to a file:
<img src="https://www.google.com/img/picture.jpg" alt="Mountain">
A relative file path points to a file relative to the current page.
In the following example, the file path points to a file in the images folder located at the root of the current web:
<img src="/images/picture.jpg" alt="Mountain">
CSS saves a lot of work. It can control the layout of multiple web pages all at once.
Example 1:
Example 2:
Here we will show one HTML page displayed with four different stylesheets.
Cascading Style Sheets (CSS) is used to format the layout of a webpage.
With CSS, you can control the color, font, the size of text, the spacing between elements, how elements are positioned and laid out, what background images or background colors are to be used, different displays for different devices and screen sizes, and much more!
CSS can be added to HTML documents in 3 ways:
The most common way to add CSS, is to keep the styles in external CSS files. However, in this tutorial we will use inline and internal styles, because this is easier to demonstrate, and easier for you to try it yourself.
An inline CSS is used to apply a unique style to a single HTML element.
An inline CSS uses the style attribute of an HTML element.
The following example sets the text color of the <h1> element to blue, and the text color of the <p> element to red:
<h1 style="color:blue;">A Blue Heading</h1>
<p style="color:red;">A red paragraph.</p>
An internal CSS is used to define a style for a single CSS file with the correct class name.
.message {
color: green;
}
A CSS rule-set consists of a selector and a declaration block:
p {
color: red;
text-align: center;
}
The element selector selects HTML elements based on the element name.
Example: Here, all <p> elements on the page will be center-aligned, with a red text color:
p {
text-align: center;
color: red;
}
The class selector selects HTML elements with a specific class attribute.
To select elements with a specific class, write a period (.) character, followed by the class name.
Example 1: In this example all HTML elements with class="center" will be red and center-aligned:
<p class="center">This paragraph refers to two classes.</p>
.center {
text-align: center;
color: red;
}
Note: you can style multiple class
Example 2: 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>
The universal selector (*) selects all HTML elements on the page.
Example: The CSS rule below will affect every HTML element on the page:
* {
text-align: center;
color: blue;
}
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, h2, p {
text-align: center;
color: red;
}
Comments are used to explain the code, and may help when you edit the source code at a later date.
Comments are ignored by browsers. A CSS comment is placed inside the <style> element, and starts with /* and ends with */:
/* This is a single-line comment */
p {
color: red;
}
Example 2: You can add comments wherever you want in the code:
p {
color: red; /* Set text color to red */
}
Example 3: Comments can also span multiple lines:
/* This is
a multi-line
comment */
p {
color: red;
}
The background-color property specifies the background color of an element.
body {
background-color: lightblue;
}
With CSS, a color is most often specified by:
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:
.className {
background-color: green;
opacity: 0.3;
}
If you do not want to apply opacity to child elements, like in our example above, use RGBA color values. The following example sets the opacity for the background color and not the text:
.claseName {
background: rgba(0, 128, 0, 0.3) /* Green background with 30% opacity */
}
The background-image property specifies an image to use as the background of an element. By default, the image is repeated so it covers the entire element.
body {
background-image: url("paper.gif");
}
By default, the background-image property repeats an image both horizontally and vertically. Some images should be repeated only horizontally or vertically like this:
body {
background-image: url("gradient_bg.png");
background-repeat: repeat-x;
}
Showing the background image only once is also specified by the background-repeat property:
body {
background-image: url("img_tree.png");
background-repeat: no-repeat;
}
Note: In the example above, the background image is placed in the same place as the text. We want to change the position of the image, so that it does not disturb the text too much.
The background-position property is used to specify the position of the background image.
body {
background-image: url("img_tree.png");
background-repeat: no-repeat;
background-position: right top;
}
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:
body {
background: #ffffff url("img_tree.png") no-repeat right top;
}
The CSS border properties allow you to specify the style, width, and color of an element's border.
The border-style property specifies what kind of border to display. The following values are allowed:
The border-style property can have from one to four values (for the top border, right border, bottom border, and the left border).
The border property is a shorthand property for the following individual border properties:
Example 1:
p {
border: 5px solid red;
}
Example 2:
p {
border-left: 6px solid red;
background-color: lightgrey;
}
Example 3:
p {
border-bottom: 6px solid red;
background-color: lightgrey;
}
The border-radius property is used to add rounded borders to an element:
p {
border: 2px solid red;
border-radius: 5px;
}
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).
CSS has properties for specifying the margin for each side of an element:
All the margin properties can have the following values:
Tip: Negative values are allowed.
p {
margin-top: 100px;
margin-bottom: 100px;
margin-right: 150px;
margin-left: 80px;
}
To shorten the code, it is possible to specify all the margin properties in one property. The margin property is a shorthand property for: margin-top, margin-right, margin-bottom, margin-left.
If the margin property has four values: margin: 25px 50px 75px 100px;
p {
margin: 25px 50px 75px 100px;
}
If the margin property has three values: margin: 25px 50px 75px; (top 25px; right and left 50px; bottom 75px)
p {
margin: 25px 50px 75px;
}
If the margin property has two values: margin: 25px 50px; (top and bottom 25px; right and left 50px)
p {
margin: 25px 50px;
}
If the margin property has one value: margin: 25px; (all four margins are 25px)
p {
margin: 25px;
}
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 CSS padding properties are used to generate space around an element's content, inside of any defined borders.
With CSS, you have full control over the padding. There are properties for setting the padding for each side of an element (top, right, bottom, and left).
CSS has properties for specifying the padding for each side of an element:
All the padding properties can have the following values:
Note: Negative values are not allowed.
div {
padding-top: 50px;
padding-right: 30px;
padding-bottom: 50px;
padding-left: 80px;
}
To shorten the code, it is possible to specify all the padding properties in one property.
If the padding property has four values: padding: 25px 50px 75px 100px; (top 25px; right 50px; bottom 75px; left 100px)
div {
padding: 25px 50px 75px 100px;
}
If the padding property has three values: padding: 25px 50px 75px; (top 25px; right and left 50px; bottom 75px)
div {
padding: 25px 50px 75px;
}
If the padding property has two values: padding: 25px 50px; (top and bottom 25px; right and left 50px)
div {
padding: 25px 50px;
}
If the padding property has one value: padding: 25px; (all four paddings are 25px)
div {
padding: 25px;
}
The CSS width property specifies the width of the element's content area. The content area is the portion inside the padding, border, and margin of an element (the box model).
So, if an element has a specified width, the padding added to that element will be added to the total width of the element. This is often an undesirable result.
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.
div {
width: 300px;
padding: 25px;
box-sizing: border-box;
}
The height and width properties are used to set the height and width of an element.
The height and width properties do not include padding, borders, or margins. It sets the height/width of the area inside the padding, border, and margin of the element.
The height and width properties may have the following values:
Example 1:
div {
height: 200px;
width: 50%;
background-color: powderblue;
}
Example 2:
div {
height: 100px;
width: 500px;
background-color: powderblue;
}
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.
Note: The value of the max-width property overrides width.
div {
max-width: 500px;
height: 100px;
background-color: powderblue;
}
| Property | Description |
|---|---|
| height | Sets the height of an element |
| max-height | Sets the maximum height of an element |
| max-width | Sets the maximum width of an element |
| min-height | Sets the minimum height of an element |
| min-width | Sets the minimum width of an element |
| width | Sets the width of an element |
All HTML elements can be considered as boxes. In CSS, the term "box model" is used when talking about design and layout.
The CSS box model is essentially a box that wraps around every HTML element. It consists of: margins, borders, padding, and the actual content.
Explanation of the different parts:
The box model allows us to add a border around elements, and to define space between elements.
div {
width: 300px;
border: 15px solid green;
padding: 50px;
margin: 20px;
}
An outline is a line that is drawn around elements, OUTSIDE the borders, to make the element "stand out".
CSS has the following outline properties:
The outline-style property specifies the style of the outline, and can have one of the following values:
.classname {
border: 1px solid black;
outline-style: solid;
outline-color: red;
outline-width: thin;
}
The outline property is a shorthand property for setting the following individual outline properties:
classname {outline: dashed;}
classname {outline: dotted red;}
classname {outline: 5px solid yellow;}
classname {outline: thick ridge pink;}
I strongly recommend to use flexbox for text alignment.
Example for practical https://flexboxfroggy.com/
The justify-content property, which aligns items horizontally and accepts the following values:
The align-items property aligns items vertically and accepts the following values:
The flex-direction property defines the direction items are placed in the container, and accepts the following values:
Another property you can apply to individual items is align-self. This property accepts the same values as align-items and its value for the specific item.
The flex-wrap property, which accepts the following values:
The two properties flex-direction and flex-wrap are used so often together that the shorthand property flex-flow was created to combine them. This shorthand property accepts the value of one of the two properties separated by a space. For example, you can use flex-flow: row wrap to set rows and wrap them.
The align-content to set how multiple lines are spaced apart from each other. This property takes the following values:
Choosing the right font for your website is important!
Choosing the right font has a huge impact on how the readers experience a website. The right font can create a strong identity for your brand.
Using a font that is easy to read are important. The font adds value to your text. It is also important to choose the correct color and text size for the font.
| Generic Font Family | Examples of Font Names |
|---|---|
| Serif | Times New Roman, Georgia, Garamond |
| Sans-serif | Arial, Verdana, Helvetica |
| Monospace | Courier New, Lucida Console, Monaco |
| Cursive | Brush Script MT, Lucida Handwriting |
| Fantasy | COPPERPLATE, Papyrus |
In CSS, we use the font-family property to specify the font of a text.
.classname {
font-family: "Lucida Console", "Courier New", monospace;
}
The font-style property is mostly used to specify italic text. This property has three values:
.classname1 {
font-style: normal;
}
.classname2 {
font-style: italic;
}
.classname3 {
font-style: oblique;
}
The font-weight property specifies the weight of a font:
.classname1 {
font-weight: normal;
}
.classname2 {
font-weight: bold;
}
The font-size property sets the size of the text.
Being able to manage the text size is important in web design. However, you should not use font size adjustments to make paragraphs look like headings, or headings look like paragraphs.
Always use the proper HTML tags, like <h1> - <h6> for headings and <p> for paragraphs.
The font-size value can be an absolute, or relative size.
Absolute size:
Relative size:
Setting the text size with pixels gives you full control over the text size:
h1 {
font-size: 40px;
}
h2 {
font-size: 30px;
}
p {
font-size: 14px;
}
To allow users to resize the text (in the browser menu), many developers use em instead of pixels.
1em is equal to the current font size. The default text size in browsers is 16px. So, the default size of 1em is 16px.
The size can be calculated from pixels to em using this formula: pixels/16=em
h1 {
font-size: 2.5em; /* 40px/16=2.5em */
}
h2 {
font-size: 1.875em; /* 30px/16=1.875em */
}
p {
font-size: 0.875em; /* 14px/16=0.875em */
}
The text size can be set with a vw unit, which means the "viewport width". That way the text size will follow the size of the browser window:
<h1 style="font-size:10vw">Hello World</h1>
<h2>Hello World</h2>
With CSS, links can be styled in different ways.
Links can be styled with any CSS property (e.g. color, font-family, background, etc.).
In addition, links can be styled differently depending on what state they are in.
The four links states are:
a:link - a normal, unvisited linka:visited - a link the user has visiteda:hover - a link when the user mouses over ita:active - a link the moment it is clicked/* unvisited link */
a:link {
color: red;
}
/* visited link */
a:visited {
color: green;
}
/* mouse over link */
a:hover {
color: hotpink;
}
/* selected link */
a:active {
color: blue;
}
Note: When setting the style for several link states, there are some order rules:
• a:hover MUST come after a:link and a:visited
• a:active MUST come after a:hover
The text-decoration property is mostly used to remove underlines from links:
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:active {
text-decoration: underline;
}
The position property specifies the type of positioning method used for an element (static, relative, fixed, absolute or sticky).
There are five different position values:
Elements are then positioned using the top, bottom, left, and right properties. However, these properties will not work unless the position property is set first. They also work differently depending on the position value.
HTML elements are positioned static by default. Static positioned elements are not affected by the top, bottom, left, and right properties.
.static {
position: static;
border: 3px solid #73AD21;
}
An element with position: relative; is positioned relative to its normal position. Setting the top, right, bottom, and left properties of a relatively-positioned element will cause it to be adjusted away from its normal position.
.relative {
position: relative;
left: 30px;
border: 3px solid #73AD21;
}
An element with position: fixed; is positioned relative to the viewport, which means it always stays in the same place even if the page is scrolled. A fixed element does not leave a gap in the page where it would normally have been located.
.fixed {
position: fixed;
bottom: 0;
right: 0;
width: 300px;
border: 3px solid #73AD21;
}
An element with position: absolute; is positioned relative to the nearest positioned ancestor (instead of positioned relative to the viewport, like fixed).
However; if an absolute positioned element has no positioned ancestors, it uses the document body, and moves along with page scrolling.
Note: A "positioned" element is one whose position is anything except static.
.relative {
position: relative;
width: 400px;
height: 200px;
border: 3px solid #73AD21;
}
.absolute {
position: absolute;
top: 80px;
right: 0;
width: 200px;
height: 100px;
border: 3px solid #73AD21;
}
An element with position: sticky; is positioned based on the user's scroll position.
A sticky element toggles between relative and fixed, depending on the scroll position. It is positioned relative until a given offset position is met in the viewport - then it "sticks" in place (like position:fixed).
.sticky {
position: -webkit-sticky; /* Safari */
position: sticky;
top: 0;
background-color: green;
border: 2px solid #4CAF50;
}
When elements are positioned, they can overlap other elements.
The z-index property specifies the stack order of an element (which element should be placed in front of, or behind, the others). An element can have a positive or negative stack order:
.overlap {
position: absolute;
left: 0px;
top: 0px;
z-index: -1;
}
The CSS overflow property controls what happens to content that is too big to fit into an area.
The overflow property specifies whether to clip the content or to add scrollbars when the content of an element is too big to fit in the specified area. The overflow property has the following values:
By default, the overflow is visible, meaning that it is not clipped and it renders outside the element's box:
.classname {
width: 200px;
height: 50px;
background-color: #eee;
overflow: visible;
}
With the hidden value, the overflow is clipped, and the rest of the content is hidden:
.classname {
width: 200px;
height: 50px;
background-color: #eee;
overflow: hidden;
}
Setting the value to scroll, the overflow is clipped and a scrollbar is added to scroll inside the box. Note that this will add a scrollbar both horizontally and vertically (even if you do not need it):
.classname {
width: 200px;
height: 50px;
background-color: #eee;
overflow: scroll;
}
The auto value is similar to scroll, but it adds scrollbars only when necessary.
The overflow-x and overflow-y properties specifies whether to change the overflow of content just horizontally or vertically (or both):
overflow-x specifies what to do with the left/right edges of the content.
overflow-y specifies what to do with the top/bottom edges of the content.
.classname {
width: 200px;
height: 50px;
background-color: #eee;
overflow-x: scroll;
overflow-y: scroll;
}
A CSS selector can contain more than one simple selector. Between the simple selectors, we can include a combinator.
There are four different combinators in CSS:
The descendant selector matches all elements that are descendants of a specified element.
The following example selects all <p> elements inside <div> elements:
CSS
div p {
background-color: yellow;
}
HTML
<h2>Descendant Selector</h2>
<p>The descendant selector matches all elements that are descendants of a specified element.</p>
<div>
<p>Paragraph 1 in the div.</p>
<p>Paragraph 2 in the div.</p>
<section><p>Paragraph 3 in the div.</p></section>
</div>
<p>Paragraph 4. Not in a div.</p>
<p>Paragraph 5. Not in a div.</p>
The child selector selects all elements that are the children of a specified element.
The following example selects all <p> elements that are children of a <div> element:
CSS
div > p {
background-color: yellow;
}
HTML
<h2>Child Selector</h2>
<p>The child selector (>) selects all elements that are the children of a specified element.</p>
<div>
<p>Paragraph 1 in the div.</p>
<p>Paragraph 2 in the div.</p>
<section><p>Paragraph 3 in the div.</p></section> <!-- not Child but Descendant -->
<p>Paragraph 4 in the div.</p>
</div>
The opacity property specifies the opacity/transparency of an element.
The opacity property can take a value from 0.0 - 1.0. The lower value, the more transparent.
The opacity property is often used together with the :hover selector to change the opacity on mouse-over:
CSS
img {
opacity: 0.5;
}
img:hover {
opacity: 1.0;
}
HTML
<h1>Image Transparency</h1>
<p>The opacity property is often used together with the :hover selector to change the opacity on mouse-over:</p>
<img src="img_forest.jpg" alt="Forest" width="170" height="100">
<img src="img_mountains.jpg" alt="Mountains" width="170" height="100">
<img src="img_5terre.jpg" alt="Italy" width="170" height="100">
CSS
.background {
background: url(klematis.jpg) repeat;
border: 2px solid black;
}
.transbox {
margin: 30px;
background-color: #ffffff;
border: 1px solid black;
opacity: 0.6;
}
.transbox p {
margin: 5%;
font-weight: bold;
color: #000000;
}
HTML
<div className="background">
<div className="transbox">
<p>This is some text that is placed in the transparent box.</p>
</div>
</div>
To specify table borders in CSS, use the border property.
To specifies a black border for <table>, <th>, <tr> and <td> elements.
Forms can be styled with CSS to control inputs, selects, text areas, and submit buttons (e.g. First Name, Last Name, Country, Subject, Submit).
A website is often divided into headers, menus, content and a footer:
CSS has several different units for expressing a length.
Many CSS properties take "length" values, such as width, margin, padding, font-size, etc.
Length is a number followed by a length unit, such as 10px, 2em, etc.
There are two types of length units: absolute and relative.
The absolute length units are fixed and a length expressed in any of these will appear as exactly that size.
Absolute length units are not recommended for use on screen, because screen sizes vary so much. However, they can be used if the output medium is known, such as for print layout.
| Unit | Description |
|---|---|
| cm | centimeters |
| mm | millimeters |
| in | inches (1in = 96px = 2.54cm) |
| px * | pixels (1px = 1/96th of 1in) |
| pt | points (1pt = 1/72 of 1in) |
| pc | picas (1pc = 12 pt) |
Relative length units specify a length relative to another length property. Relative length units scales better between different rendering mediums.
| Unit | Description |
|---|---|
| em | Relative to the font-size of the element (2em means 2 times the size of the current font) |
| ex | Relative to the x-height of the current font (rarely used) |
| ch | Relative to width of the "0" (zero) |
| rem | Relative to font-size of the root element |
| vw | Relative to 1% of the width of the viewport* |
| vh | Relative to 1% of the height of the viewport* |
| vmin | Relative to 1% of viewport's* smaller dimension |
| vmax | Relative to 1% of viewport's* larger dimension |
| % | Relative to the parent element |
With the CSS border-radius property, you can give any element "rounded corners".