CSS Text and Layout max-width
CSS has many properties used to format text.
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;
}
Create Stunning Websites and Web Apps
Trying to build out all user interfaces and components for your website or web app from scratch can become a very tedious task. A huge reason why we created Contrast Bootstrap to help reduce the amount of time we spend doing that, so we can focus on building some other aspects of the project. Contrast Bootstrap PRO consists of a UI Kit featuring over 10000+ component variants. Together with a template of 5 admin dashboards and 23+ additional multipurpose pages template for building almost any type of website or web app. You can view a demo and learn more about Contrast by clicking here.
Contrast Bootstrap PRO was built using the most popular CSS framework Bootstrap to help build your next landing, admin SAAS, prelaunch etc. project with a clean, prebuilt and well documented template and UI components. Learn more about contrast.
Resources
- Contrast Design Bootstrap
- Accordion
- Alert
- Animation
- Autocomplete
- Badges
- Box
- Breadcrumb
- ButtonGroup
- Button
- ButtonToolbar
- Card
- Carousel
- Checkbox
- Collapse
- DataTable
- DatePicker
- DropDown
- Footer
- Forms
- Icon
- Iframe
- Input
- InputGroup
- ListGroup
- Mask
- Modal
- Multiselect
- Notification
- Pane
- Panel
- Pop Over
- Progress
- Radio
- Rating
- Select
- Select 2
- Slider
- Spinner
- Stepper
- Switch
- Table
- Forms
- Navbar
- Pagination
- Tab
- Sidebar
- Time Picker
- Data Table
- Fixed Data Table
- Table
- Widgets
Top comments (0)