New Contrast Pro UI Kit and template with 5 admin dashboards, 23 pages and 10000+ components for $49 ($50 off)🎉
postImage

CSS Text and Layout

blogImage

By Emmanuel Chinonso

Web Developer

CSS Text and Layout max-width

CSS has many properties used to format text.

Contrast Bootstrap UI Kit

Text Color: The color property is used to set the color of the text. The color is specified by:

  • A color name - like "red"

  • A HEX value - like "#ff0000"

  • An RGB value - like "rgb(255,0,0).

The default text color for a page is defined in the body selector.

CSS Code:

body {
color: blue;
}
h1 {
color: green;
}

Text Alignment: The text-align property is used to set the horizontal alignment of a text.A text can be left or right aligned, centered, or justified.

CSS Code:

h1 {
text-align: center;
}
h2 {
text-align: left;
}
h3 {
text-align: right;
}
div {
text-align: justify;
}

When the text-align property is set to "justify", each line is stretched so that every line has equal width, and the left and right margins are straight (like in magazines and newspapers).

Text Direction: The direction and unicode-bidi properties can be used to change the text direction of an element

CSS Code:

p {
direction: rtl;
unicode-bidi: bidi-override;
}

Vertical Alignment: The vertical-align property sets the vertical alignment of an element.

CSS Code:

img.top {
vertical-align: top;
}
img.middle {
vertical-align: middle;
}
img.bottom {
vertical-align: bottom;
}

Text Decoration: The text-decoration property is used to set or remove decorations from text. The value text-decoration: none; is often used to remove underlines from links:

CSS Code:

a {
text-decoration: none;
}
h1 {
text-decoration: overline;
}
h2 {
text-decoration: line-through;
}
h3 {
text-decoration: underline;
}

Text Transformation: The text-transform property is used to specify uppercase and lowercase letters in a text.It can be used to turn everything into uppercase or lowercase letters, or capitalize the first letter of each word

CSS Code:

p.uppercase {
text-transform: uppercase;
}
p.lowercase {
text-transform: lowercase;
}
p.capitalize {
text-transform: capitalize;
}

Text Indentation: The text-indent property is used to specify the indentation of the first line of a text

CSS Code:

p {
text-indent: 50px;
}

Letter Spacing: The letter-spacing property is used to specify the space between the characters in a text.

CSS Code:

h1 {
letter-spacing: 3px;
}
h2 {
letter-spacing: -3px;
}

Line Height: The line-height property is used to specify the space between lines

CSS Code:

p.small {
line-height: 0.8;
}
p.big {
line-height: 1.8;
}

Word Spacing: The word-spacing property is used to specify the space between the words in a text.

CSS Code:

h1 {
word-spacing: 10px;
}
h2 {
word-spacing: -5px;
}

White Space: The white-space property specifies how white-space inside an element is handled.

CSS Code:

p {
white-space: nowrap;
}

This shows how disable text wrapping inside an element.

Text Shadow: The text-shadow property adds shadow to text.

CSS Code:

h1 {
text-shadow: 2px 2px 5px red;
}

In this code, you add shadow, color and a blur effect(5px). Using width, max-width and margin: auto; As mentioned in the previous chapter; a block-level element always takes up the full width available (stretches out to the left and right as far as it can).

Setting the width of a block-level element will prevent it from stretching out to the edges of its container. Then, you can set the margins to auto, to horizontally center the element within its container. The element will take up the specified width, and the remaining space will be split equally between the two margins Using max-width will improve the browser's handling of small windows. This is important when making a site usable on small devices:

Here is a code for two different divs that's shows the function of the max-width.

CSS Code:

div.ex1 {
width: 500px;
margin: auto;
border: 3px solid #73AD21;
}
div.ex2 {
max-width: 500px;
margin: auto;
border: 3px solid #73AD21;
}

Contrast Bootstrap UI Kit

Create Stunning websites and web apps

Building different custom components in react for your web apps or websites can get very stressful. Thats why we decided to build contrast. We have put together a UI kit with over 10000+ components, 5 admin dashboards and 23 additional different pages template for building almost any type of web app or webpage into a single product called Contrast Pro.Try contrast pro

ad-banner

Contrast React Bootstrap PRO is a Multipurpose pro template, UI kit to build your next landing, admin, SAAS, prelaunch, etc project with a clean, well documented, well crafted template and UI components.Learn more about Contrast Pro

Share Post:

Comments

...