Menu

Log in

Sign up

From beginner to master of web design, coding, infrastructure operation, business development and marketing

  • COURSES
  • HTML & CSS Introduction
  • HTML & CSS Coding with AI
  • Linux Introduction
  • Docker Basics
  • Git & GitHub Introduction
  • JavaScript Coding with AI
  • Django Introduction
  • AWS Basics
  • Figma Introduction
  • SEO Tutorial for Beginners
  • SEO with AI
  • OTHERS
  • About
  • Terms of Service
  • Privacy Policy

© 2024 D-Libro. All Rights Reserved

HTML & CSS IntroductionChapter 11. CSS: Styling Text and Images

vertical-align

vertical-align

Adjusting Vertical Alignment with vertical-align in CSS

The vertical-align property is mainly used for the vertical position of text or images in each line. It is usually used for vertical position adjustment for

  1. Additional small text in the paragraph.
  2. Inline icons
  3. Text or images in a table cell

Additional small text position in paragraph

The default value is the baseline, which aligns small text with the text baseline. When you use super or sub, the small text will be aligned with the baseline of superscript or subscript text baseline. You can also specify the top, middle, or bottom. Those positions are defined depending on the line height. You can also use a specific size (e.g., 10px or -10px) to manually adjust the position.

The vertical-align property should be written in the small text element (not in the parent element) like in the example below.

chapter11.html
<p> ABC
  <span style="vertical-align: top"> small text </span>
<p>

Inline icon position in paragraph

The vertical-align property is useful when you want to adjust the position of icons in a paragraph. You can use the same keywords as the ones we explained for the small text vertical alignment. To set the position, you can add the vertical-align property in the <img> tag of the icon you want to adjust the position of.

chapter11.html
<p> ABC
  <img src="img/xxx" style="vertical-align: top;">
<p>

Text or image position in table cells

The vertical-align property can also be used for vertical position adjustment for the text or images in table cells. In this case, you can use one of the keywords from the top, middle, or bottom. The middle is the default in the table format.

For the table format, you can set the vertical-align property for the <td> tag like in the example below.

practice.css
td{
  vertical-align: top;
}

Ideavertical-alignment vs. display

vertical-alignment is used only in special cases. It cannot be used for block elements to align their positions vertically. Usually, we use the display property to adjust the vertical positions of elements. The display property will be explained later in this course.

Practice 1

Objective:
Check how vertical-align works for small text in paragraphs

1. Update the body section of the HTML file

Add the code below at the end of the <body> section in the chapter11.html file. In this code, we set two new classes (vertical-align-check and small-text) to adjust formats to show the results clearly.

chapter11.html
<h2>Vertical Align</h2>
<h3>Vertical Align (Small Text)</h3>
<p class="vertical-align-check">Vertical Align: Original <span class="small-text">Original</span></p>
<p class="vertical-align-check">
  Vertical Align: Baseline
  <span class="small-text" style="vertical-align: baseline;">Baseline</span>
</p>
<p class="vertical-align-check">
  Vertical Align: Top
  <span class="small-text" style="vertical-align: top;">Top</span>
</p>
<p class="vertical-align-check">
  Vertical Align: Bottom
  <span class="small-text" style="vertical-align: bottom;">Bottom</span>
</p>
<p class="vertical-align-check">
  Vertical Align: Middle
  <span class="small-text" style="vertical-align: middle;">Middle</span>
</p>
<p class="vertical-align-check">
  Vertical Align: Super
  <span class="small-text" style="vertical-align: super;">Super</span>
</p>
<p class="vertical-align-check">
  Vertical Align: Sub
  <span class="small-text" style="vertical-align: sub;">Sub</span>
</p>
<p class="vertical-align-check">
  Vertical Align: 10px
  <span class="small-text" style="vertical-align: 10px;">10px</span>
</p>
<p class="vertical-align-check">
  Vertical Align: -10px
  <span class="small-text" style="vertical-align: -10px;">-10px</span>
</p>

2. Update the CSS file

Open the practice.css file and add new code for adding styles to the vertical-align-check and small-text classes.

practice.css
.vertical-align-check{
  border:1px dotted #26BCCE;
  line-height: 3;
  width:300px;
}

.small-text{
  font-size:0.5em;
  line-height: 1;
}

3. Check the result with a browser

  • Open chapter11.html with a browser.
  • You can see how the vertical-align property works in a paragraph.

You can also check the sample result here (Demo Site).

link

Practice 2

Objective:
Check how vertical-align works for icons in paragraphs

1. Update the body section of the HTML file

Add the code below at the end of the <body> section in the chapter11.html file. In this code, we are using the same classes set in the previous practice.
For the icon image, we are using a smile.png file. As we want to use a transparent background for the icon, we are using a PNG file. You can use your own icon but make sure you set a proper file path in the code.

chapter11.html
<h3>Vertical Align (Icons)</h3>
<p class="vertical-align-check">
  Vertical Align : Original
  <img src="img/smile.png" width="15px">
</p>
<p class="vertical-align-check">
  Vertical Align : Baseline
  <img src="img/smile.png" width="15px" style="vertical-align: baseline;">
</p>
<p class="vertical-align-check">
  Vertical Align : Top
  <img src="img/smile.png" width="15px" style="vertical-align: top;">
</p>
<p class="vertical-align-check">
  Vertical Align : Bottom
  <img src="img/smile.png" width="15px" style="vertical-align: bottom;">
</p>
<p class="vertical-align-check">
  Vertical Align : Middle
  <img src="img/smile.png" width="15px" style="vertical-align: middle;">
</p>
<p class="vertical-align-check">
  Vertical Align : Super
  <img src="img/smile.png" width="15px" style="vertical-align: super;">
</p>
<p class="vertical-align-check">
  Vertical Align : Sub
  <img src="img/smile.png" width="15px" style="vertical-align: sub;">
</p>
<p class="vertical-align-check">
  Vertical Align : 10px
  <img src="img/smile.png" width="15px" style="vertical-align: 10px;">
</p>
<p class="vertical-align-check">
  Vertical Align : -10px
  <img src="img/smile.png" width="15px" style="vertical-align: -10px;">
</p>

2. Check the result with a browser

  • Open chapter11.html with a browser.
  • You can see how the vertical-align property works for icons in a paragraph.

You can also check the sample result here (Demo Site).

link

Practice 3

Objective:
Check how vertical-align works in the table format

1. Update the body section of the HTML file

Add the code below at the end of the <body> section in the chapter11.html file. In this code, we are not using any classes as we directly add styles using type selectors.

chapter11.html
<h3>Vertical Align in Table Cells</h3>
<table>
  <tr>
    <th>header</th>
    <th>header</th>
    <th>header</th>
  </tr>
  <tr>
    <td style="vertical-align: top;">
      <img src="img/smile.png" width="30px">
    </td>
    <td style="vertical-align: middle;">
      <img src="img/smile.png" width="30px">
    </td>
    <td style="vertical-align: bottom;">
      <img src="img/smile.png" width="30px">
    </td>
  </tr>
  <tr>
    <td style="vertical-align: top;">vertical-align: top</td>
    <td style="vertical-align: middle;">vertical-align: middle</td>
    <td style="vertical-align: bottom;">vertical-align: bottom</td>
  </tr>
</table>
<hr>

2. Update the CSS file

Open the practice.css file and add styles to the table, th, and td elements.

practice.css
table{
  background-color: white;
}

th{
  background-color: #1E838A;
  color: white;
}

td{
  background-color: #B3EBEF;
  height: 100px;
  width: 100px;
  text-align: center;
  padding: 10px;
}

3. Check the result with a browser

  • Open chapter11.html with a browser.
  • You can see how the vertical-align property works in the table format.

You can also check the sample result here (Demo Site).

link


You can also learn this topic offline. Click AmazonKindle.

More Topics to Explore

Transition Property in CSS

Transition Property in CSS

How HTML and CSS Differ from Drawing Software in Designing Elements

Design Element Representation in HTML and CSS

What is CSS? A Beginner's Guide to Styling Websites

What Is CSS?

Transition Property in CSS

Transition Property in CSS

How HTML and CSS Differ from Drawing Software in Designing Elements

Design Element Representation in HTML and CSS

What is CSS? A Beginner's Guide to Styling Websites

What Is CSS?

Tags:

Alignment

Text Styling

HTML & CSS Introduction
Course Content

Chapter 1. Overview of Website Development

How Websites Work?

Designing, Building and Publishing Websites

Designing Websites

Building Websites – Frontend and Backend Coding

Web App vs. Website

Frontend Coding

Web Framework and CMS

Publishing Websites (Hosting Services)

Chapter 2. Preparing for Website Coding

Two Key Tools to Start Coding Websites

How Browsers Display Web Pages

File Name Rules

Website Directory Structure

Absolute Path vs. Relative Path

Chapter 3. HTML Basics

What Is HTML?

HTML Element

Attribute

HTML Document Structure

Layout Semantics

Heading and Paragraph Tag

Text-Level Semantics

Space, Line-break and Tag in Content

Comments in HTML Document

Chapter 4. HTML: Add Links and Images

Overview of Adding Links and Images

Embed Images – <img>

Image File Format

Add Hyperlinks – <a>

Add Hyperlinks to Images

Add Hyperlinks to Specific Location on Web Page

Link Tag – <link>

Script Tag – <script>

Chapter 5. HTML: Create Lists and Tables

Create Lists

Create Tables

Combine Table Cells

Chapter 6. HTML: Create Forms

Create Forms

Create Text Input Forms and Submit Button

Radio Button and Checkbox

Select Box

Labels

Auto Complete and Disabled

Chapter 7. Bridging HTML and CSS

Block Element vs. Inline Element

Nesting Elements – Parent Elements and Child Elements

Div vs. Span

Global Attribute – Class, ID and Style

Accordion – <Details> and <Summary>

Chapter 8. CSS Basics

What Is CSS?

CSS Syntax

Where To Type CSS?

CSS Basic Selectors

Descendant Selector

Inheritance

Specificity

Reset CSS

Browser Developer Tools for CSS

Comments in CSS Document

Chapter 9. Web Design Basics

Design Element Representation in HTML and CSS

Key Design Points by CSS

Length

Color Code – HEX and RGB

Color Theme

Chapter 10. CSS: Sizing and Spacing

CSS Box Model

width and height

padding

margin

Margin and Padding for Specific Side

margin: auto

box-sizing

Chapter 11. CSS: Styling Text and Images

Text Styling Properties

font-size

color

font-family

Web Font and Google Font

font-weight and font-style

text-decoration

line-height and letter-spacing

text-align

vertical-align

Styling Images

float: left and right

Chapter 12. CSS: Styling Backgrounds

background-color

background-image

background-size

background-repeat

background-position

background-attachment

background (Multiple Properties)

Chapter 13. CSS: Styling Borders and Drawing Lines

border-style

border-color

border-width

border-radius

Border (Multiple Properties)

Borders on Specific Side

Border Radius on Specific Side

Chapter 14. CSS: Layout – Key Concepts and Display Property

Layout Before and After

Layout Key Design Points

Display Property

inline, block and inline-block

display: none

Chapter 15. CSS: Layout – Flex Box

Flex Box – display: flex

flex-direction

Main Axis and Cross Axis

flex-wrap

justify-content

align-items

align-content

align-self

flex-grow

flex-shrink

flex-basis

margin: auto with Flex Box

Inline Flex Box

Nested Flex Box

Chapter 16. CSS: Styling Lists

List Styling Properties

list-style-type

list-style-image

list-style-position

Chapter 17. Creating and Styling Components

Components and Layout

Buttons

Cards

Top Bar

Footer and Bottom Bar

Chapter 18. Completing Website Development

Website Structure Design

Live Server

Home (Landing) Page Development

Main (List) Page Development

Content (Detail) Page Development

Chapter 19. Publishing Websites

Key Steps to Publish Websites

Domain and DNS Server

Favicon

GitHub Pages

Chapter 20. Supplemental Topics

Horizontal Rule – <hr>

Line Break – <br>

Reserved Characters and HTML Entities

Non-breaking Space – &nbsp;

Chapter 1. Overview of Website Development

How Websites Work?

Designing, Building and Publishing Websites

Designing Websites

Building Websites – Frontend and Backend Coding

Web App vs. Website

Frontend Coding

Web Framework and CMS

Publishing Websites (Hosting Services)

Chapter 2. Preparing for Website Coding

Two Key Tools to Start Coding Websites

How Browsers Display Web Pages

File Name Rules

Website Directory Structure

Absolute Path vs. Relative Path

Chapter 3. HTML Basics

What Is HTML?

HTML Element

Attribute

HTML Document Structure

Layout Semantics

Heading and Paragraph Tag

Text-Level Semantics

Space, Line-break and Tag in Content

Comments in HTML Document

Chapter 4. HTML: Add Links and Images

Overview of Adding Links and Images

Embed Images – <img>

Image File Format

Add Hyperlinks – <a>

Add Hyperlinks to Images

Add Hyperlinks to Specific Location on Web Page

Link Tag – <link>

Script Tag – <script>

Chapter 5. HTML: Create Lists and Tables

Create Lists

Create Tables

Combine Table Cells

Chapter 6. HTML: Create Forms

Create Forms

Create Text Input Forms and Submit Button

Radio Button and Checkbox

Select Box

Labels

Auto Complete and Disabled

Chapter 7. Bridging HTML and CSS

Block Element vs. Inline Element

Nesting Elements – Parent Elements and Child Elements

Div vs. Span

Global Attribute – Class, ID and Style

Accordion – <Details> and <Summary>

Chapter 8. CSS Basics

What Is CSS?

CSS Syntax

Where To Type CSS?

CSS Basic Selectors

Descendant Selector

Inheritance

Specificity

Reset CSS

Browser Developer Tools for CSS

Comments in CSS Document

Chapter 9. Web Design Basics

Design Element Representation in HTML and CSS

Key Design Points by CSS

Length

Color Code – HEX and RGB

Color Theme

Chapter 10. CSS: Sizing and Spacing

CSS Box Model

width and height

padding

margin

Margin and Padding for Specific Side

margin: auto

box-sizing

Chapter 11. CSS: Styling Text and Images

Text Styling Properties

font-size

color

font-family

Web Font and Google Font

font-weight and font-style

text-decoration

line-height and letter-spacing

text-align

vertical-align

Styling Images

float: left and right

Chapter 12. CSS: Styling Backgrounds

background-color

background-image

background-size

background-repeat

background-position

background-attachment

background (Multiple Properties)

Chapter 13. CSS: Styling Borders and Drawing Lines

border-style

border-color

border-width

border-radius

Border (Multiple Properties)

Borders on Specific Side

Border Radius on Specific Side

Chapter 14. CSS: Layout – Key Concepts and Display Property

Layout Before and After

Layout Key Design Points

Display Property

inline, block and inline-block

display: none

Chapter 15. CSS: Layout – Flex Box

Flex Box – display: flex

flex-direction

Main Axis and Cross Axis

flex-wrap

justify-content

align-items

align-content

align-self

flex-grow

flex-shrink

flex-basis

margin: auto with Flex Box

Inline Flex Box

Nested Flex Box

Chapter 16. CSS: Styling Lists

List Styling Properties

list-style-type

list-style-image

list-style-position

Chapter 17. Creating and Styling Components

Components and Layout

Buttons

Cards

Top Bar

Footer and Bottom Bar

Chapter 18. Completing Website Development

Website Structure Design

Live Server

Home (Landing) Page Development

Main (List) Page Development

Content (Detail) Page Development

Chapter 19. Publishing Websites

Key Steps to Publish Websites

Domain and DNS Server

Favicon

GitHub Pages

Chapter 20. Supplemental Topics

Horizontal Rule – <hr>

Line Break – <br>

Reserved Characters and HTML Entities

Non-breaking Space – &nbsp;