Every topic starts at New. Sign in and your practice counts.
In the development of HTML webpage the scheme, arrangement and presentation of the whole webpage along with the components are handled by a stylesheet language. There are various stylesheet languages available like Cascading Style Sheets (CSS), Document Style Semantics and Specification Language (DSSSL), Extensible Stylesheet Language (XSL), etc. The most common and frequently used with HTML is CSS. So, this way the contents of the webpage are defined through HTML while the look of different components is handled via CSS. This way, it is easier to manage and troubleshoot your web designing code for extension and digging out the errors.
By using CSS, you can provide borders in table as well. For this purpose, we initially need to state the 'style' tag-pair just before the start of table and later inside the block, we need to set which style to opt for and where to apply it. As shown in fig 15 we are defining border for table, table header cells and every other cell in the table.
<style>
table, th, td {
border: 1px solid #black;
}
</style>
Fig-15: Applying Borders to Table
Table 3.2 List of frequently used color names
| Color | Color Name 毛olor | Solor
We may add background color of the table as well, by adding the following code, as shown in fig-16 in 'style' tag-pair.
<style>
th, td {
background-color: 口aqua;
}
</style>
Fig-16: Provide table with a background color
As a first step to decor the webpage, we define 'style' tag-pair in the body in line 4 to 25 and add line 29 which results in changing the color of 3rd level headings in the body to green as shown in fig-17. Further we define general decor like background image and centrally aligned text in the body in lines 5-10. However we further distinguish h3 level heading to be displayed in green color while the normal text will be styled as 'underlined in wavy fashion', as mentioned on line 17 and 21 respectively..
Do You Know
Background-Attachment
fixed: Background image remains fixed.
scroll: Background image scrolls along
with the page.
local: Background image moves with the
content of the element.
Do You Know
Display
block: used to span element to full width
and starts on a new line.
inline: width of element is based on the
content only.
flex: flexbox is to arrange items in a row or
column such that items expand (flex) to fill
up the additional space.
Do You Know
flex-start: Aligns items to the start of the
container (default).
center: Items are centered within the
container.
space-between: Distributes items evenly,
l.e. first item at the start and last item at
the end.
Do You Know
center: items are set along the center.
stretch: Stretches items to fill the
container (default behavior).
<div>
<h3>Welcome to My Website</h3> <
<p>This is a sample paragraph with a wavy underline.</p>
</div>
</body>
</html>
To add a video clip in a website, <video> tag is used where you can define the clip size and how the clip should be available at the time when website loads up. Line 6 of the code in fig-18 uses a video tag and specifies width and height of the clip in terms of pixels to adjust the size of the video clip. Additionally, the controls parameter defines that play/pause and volume controls are enabled when the video loads up as shown in fig-19 (a). In the next line, the source and type of the video are specified. Though, Html supports many formats but among different browsers the most commonly supported video type is Mp4.
<html>
<body style="text-align: center">
<h2 style="color: -Green">Pakistan's First Ever Win in
International Football</h2>
<p>Congratulations !!!</p>
<video width="500px" height="500px" controls>
<source src="fifa-win.mp4" type="video/mp4" />
</video>
</body>
</html>
Fig-18: Sample code to load a video clip in a website
Alternatively, autoplay parameter can be used instead of controls. Autoplay automatically loads the video clip as the webpage loads but does not provide any controls for volume or play/pause. Autoplay can be used by specifying additional features like muted, looped, etc. When muted is
A good programming practice is the provision of additional video formats like Ogg in video tag-pair too, like: <source src="fifa-win.mp4" type="video/mp4" /> used, the clip loads but volume is muted and needs to be unmuted manually while looped will keep the clip running, again and again in a loop, unless it is interrupted manually. Options for manual intervention are accessible by right-clicking the mouse. Fig. 19 (b) is the output of following code:
<video width="500px" height="500px" autoplay muted>
3.3.4 Ways to Use CSS in HTML
There are three ways, via which we can use CSS styles in our HTML webpage. Inline CSS: Any CSS attribute that we want to incorporate can be added using a HTML tag (like the ones, we have covered in the last section) and incorporated in the body section, as shown in fig-12.
This figure is being prepared.
Fig-17: Code for Applying CSS Style to headings and body
<html lang="en">
<head>
<title>Inline CSS Example</title>
</head>
<body>
<!-- This is a paragraph with inline CSS for styling -->
<p style="color: Dred; font-size:40px; font-style:italic;
text-align:center;">
My Teaching Academy
</p>
</body>
</html>
Embedded (Internal) CSS
Instead of assigning styles for every heading and other component at the time of its first occurrence in the code, a better approach is to outline all the styles in the header under the tag-pair of 'style' as shown in fig-21. This way, all the presentation related CSS code is separated and do not indulge with the already written HTML code. Additionally, change in one line in the CSS section will be reflected throughout the respective components.
<html lang="en">
<head>
<title>Embedded CSS Example</title>
<style>
body {
color: blue;
}
h2 {
color: 0red;
font-size:30px;
font-style:italic;
text-align:center;
}
</style>
</head>
<body>
<h2>My Teaching Academy</h2>
<p>My Teaching Academy</p>
QUTPUT
</body>
</html>
My Teaching Academy
My Tenching Academy
Fig-21: Embedded CSS sample
External CSS
Alternatively, a file with extension '.css' can be made and all relevant CSS code according to your schema can be present there. Once, the contents of HTML are finalized, just attach the CSS file in the head portion of HTML by passing the link. External CSS are used with large projects, like in commercial purposes.
<link rel="mystylesheet" href="my_own_SS.css" />
NOTE: The priority of Inline is highest, followed by embedded styles and lastly the attributes of external are considered; if all three are present in a webpage.