Friday, October 20, 2023

HTML class Attribute

                      HTML class Attribute

The HTML class attribute is used to specify a class for an HTML element.

Multiple HTML elements can share the same class.

Using The class Attribute

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.

In the following example we have three <div> elements with a class attribute with the value of "Animal". All of the three <div> elements will be styled equally according to the .Animal style definition in the head section:

Example

<!DOCTYPE html>
<html>
<head>
<style>
.Animal{
background-color: hsl(198, 87%, 50%);
color: white;
border: 2px solid black;
margin: 20px;
padding: 20px;
}
</style>
</head>
<body>

<div class="Animal">
<h2>Dog</h2>
<p>The dog is a domesticated descendant of the wolf.</p>
</div>

<div class="Animal">
<h2>Donkey</h2>
<p>The donkey has been used as a working animal for at least 5000 years.</p>
</div>

<div class="Animal">
<h2>Monkey</h2>
<p>It is thought the New World monkeys started as a drifted "Old World monkey" group</p>
</div>

</body>
</html>

In the following example we have two <span> elements with a class attribute with the value of "text". Both <span> elements will be styled equally according to the .text style definition in the head section:

Example

<!DOCTYPE html>
<html>
<head>
<style>
.text {
font-size: 120%;
color: hsl(129, 92%, 46%);
}
</style>
</head>
<body>

<h1>My <span class="text">name</span>is XXX</h1>
<p>This is some <span class="text">notes</span></p>

</body>
</html>

The Syntax For Class

To create a class; write a period (.) character, followed by a class name. Then, define the CSS properties within curly braces {}:

Example

Create a class named “Animal”:

<!DOCTYPE html>
<html>
<head>
<style>
.city {
background-color: hsl(148, 88%, 44%);
color: white;
padding: 10px;
}
</style>
</head>
<body>

<h2>The class Attribute</h2>
<p>Use CSS to style elements with the class name "Animal":</p>

<h2 class="city">Dog</h2>
<p>Dog is a animal.</p>

<h2 class="city">Cat</h2>
<p>This cat eyes are too good.</p>

<h2 class="city">Horse</h2>
<p>Horse is used for riding.</p>

</body>
</html>

Thursday, October 19, 2023

HTML Block and Inline Elements

HTML Block and Inline Elements


Every HTML element has a default display value, depending on what type of element it is.

There are two display values: block and inline.

Block-level Elements

A block-level element always starts on a new line, and the browsers automatically add some space (a margin) before and after the element.

A block-level element always takes up the full width available (stretches out to the left and right as far as it can).

Two commonly used block elements are: <p> and <div>.

The <p> element defines a paragraph in an HTML document.

The <div> element defines a division or a section in an HTML document.

The <p> element is a block-level element.

The <div> element is a block-level element.

Example

<!DOCTYPE html>
<html>
<body>

<p style="border: 5px solid black">Hello World</p>
<div style="border: 5px solid black">Hello World</div>

<p>The P and the DIV elements are both block elements, and they will always start on a new line and take up the full width available (stretches out to the left and right as far as it can).</p>

</body>
</html>

Inline Elements

An inline element does not start on a new line.

An inline element only takes up as much width as necessary.

This is a <span> element inside a paragraph.

Example

<!DOCTYPE html>
<html>
<body>

<p>This is an inline span <span style="border: 5px solid hsl(0, 48%, 76%)">Hello World</span> element inside a paragraph.</p>

<p>The SPAN element is an inline element, and will not start on a new line and only takes up as much width as necessary.</p>

</body>
</html>

The <div> Element

The <div> element is often used as a container for other HTML elements.

The <div> element has no required attributes, but style, class and id are common.

When used together with CSS, the <div> element can be used to style blocks of content:

Example

<!DOCTYPE html>
<html lang="en">
<head>
<title>This is my first webpage</title>
</head>
<body>
<div style="background-color:black; padding:20px;">
<!--inline, Internal, External-->

<h1 style="color:white">This is my website</h1>

<p style="color:white">Lorem ipsum dolor sit amet consectetur adipisicing elit. Nesciunt corporis suscipit cupiditate iusto! Accusamus facilis similique repudiandae voluptatibus maxime molestiae nam doloremque. Perspiciatis accusamus neque cum. Id quia illo natus.</p>
<p style="color:white">Lorem ipsum dolor sit amet consectetur, adipisicing elit. Autem natus magnam excepturi beatae, repellendus facilis architecto sunt laboriosam nisi a eum nostrum dolor nemo omnis dolores, nobis animi quia? Culpa?</p>
<p style="color:white">Lorem ipsum dolor sit amet consectetur adipisicing elit. Obcaecati tempore aliquam vel magni fuga pariatur vitae iste! Fugit modi explicabo veritatis nihil laborum autem, distinctio similique sed ut laboriosam dignissimos?</p>
</div>

</body>
</html>

The <span> Element

The <span> element is an inline container used to mark up a part of a text, or a part of a document.

The <span> element has no required attributes, but style, class and id are common.

When used together with CSS, the <span> element can be used to style parts of the text:

Example

<!DOCTYPE html>
<html>
<body>

<h1>The span element</h1>

<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Officiis illum inventore ipsam libero, facilis suscipit quod atque eveniet quas! Fuga tempore libero recusandae dolore voluptates. Rem expedita ipsum distinctio pariatur?<span style="color:hsl(15, 88%, 44%);font-weight:bold;">Lorem</span>Lorem ipsum dolor sit amet consectetur adipisicing elit. Et molestiae suscipit molestias excepturi in sint nam natus enim officiis sequi sit, ipsam quae ad unde earum obcaecati facere cum perspiciatis?<span style="color:hsl(119, 89%, 45%);font-weight:bold;">ipsam</span> eyes.</p>

</body>
</html>

Wednesday, October 18, 2023

HTML Lists

                                             HTML Lists

HTML lists allow web developers to group a set of related items in lists.

Unordered HTML List

An unordered list starts with the <ul> tag. Each list item starts with the <li> tag.

The list items will be marked with bullets (small black circles) by default:

Example

<!DOCTYPE html>
<html>
<body>

<h2>An unordered HTML list</h2>

<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>

</body>
</html>

Ordered HTML List

An ordered list starts with the <ol> tag. Each list item starts with the <li> tag.

The list items will be marked with numbers by default:

Example

<!DOCTYPE html>
<html>
<body>

<h2>An unordered HTML list</h2>

<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>

</body>
</html>

HTML Description Lists

HTML also supports description lists.

A description list is a list of terms, with a description of each term.

The <dl> tag defines the description list, the <dt> tag defines the term (name), and the <dd> tag describes each term:

Example

<!DOCTYPE html>
<html>
<head>
<title>lists</title>
</head>
<body>
<h4>mythical creatures</h4>
<dl>
<dt>dragon</dt>
<dd>a mythical monster resembling a giant reptile, sometimes shown as having wings. In European tradition the dragon is typically fire-breathing and tends to symbolize chaos or evil, whereas in East Asia it is usually a beneficent symbol of fertility, associated with water and the heavens.</dd>
<dt>vampire</dt>
<dd>a small bat that feeds on the blood of mammals or birds using its two sharp incisor teeth and anticoagulant saliva, found mainly in tropical America.</dd>
</dl>
</body>
</html>

Building Static Website(part6) HTML Lists

  Building Static Website (part6) HTML Lists Today, let us add some lists to our detailed view section by using html lists. Lists: List is a...