CSS Box Sizing

CSS Box Sizing

The CSS box-sizing property allows us to include the padding and border in an element’s total width and height.

Without the CSS box-sizing Property

By default, the width and height of an element is calculated like this:

width + padding + border = actual width of an element
height + padding + border = actual height of an element

This means: When you set the width/height of an element, the element often appears bigger than you have set (because the element’s border and padding are added to the element’s specified width/height).

Continue reading CSS Box Sizing

CSS – @property Rule

CSS @property Rule

The @property rule is used to define custom CSS properties directly in the stylesheet without having to run any JavaScript.

The @property rule has data type checking and constraining, sets default values, and defines whether the property can inherit values or not.

Example of defining a custom property:

@property --myColor {
  syntax: "";
  inherits: true;
  initial-value: lightgray;
}

The definition above says that –myColor is a color property, it can inherit values from parent elements, and its default value is lightgray.

To use the custom property in CSS, we use the var() function:

body {
  backgound-color: var(--myColor);
}

The benefits of using @property:

  • Type checking: You must specify the data type of the custom property, such as <number>, <color>, <length>, etc. This prevents errors and ensures that custom properties are used correctly
  • Set default value: You set a default value for the custom property. This ensures that if an invalid value is assigned later, the browser uses the defined fallback value
  • Set inheritance behavior: You must specify whether the custom property can inherit values from its parent elements or not

Continue reading CSS – @property Rule

CSS Variables

CSS Variables

The var() function is used to insert the value of a CSS variable.

CSS variables have access to the DOM, which means that you can create variables with local or global scope, change the variables with JavaScript, and change the variables based on media queries.

A good way to use CSS variables is when it comes to the colors of your design. Instead of copy and paste the same colors over and over again, you can place them in variables.

Continue reading CSS Variables

CSS User Interface

CSS User Interface

In this chapter you will learn about the following CSS user interface properties:

  • resize
  • outline-offset

CSS Resizing

The resize property specifies if (and how) an element should be resizable by the user.

Continue reading CSS User Interface

CSS Multiple Columns

CSS Multi-column Properties

In this chapter you will learn about the following multi-column properties:

  • column-count
  • column-gap
  • column-rule-style
  • column-rule-width
  • column-rule-color
  • column-rule
  • column-span
  • column-width

Continue reading CSS Multiple Columns

CSS Buttons

Learn how to style buttons using CSS.

Basic Button Styling

Example

.button {
  background-color: #04AA6D; /* Green */
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
}

Continue reading CSS Buttons

CSS Pagination Examples

Learn how to create a responsive pagination using CSS.

Simple Pagination

If you have a website with lots of pages, you may wish to add some sort of pagination to each page.

Example

.pagination {
display: inline-block;
}

.pagination a {
color: black;
float: left;
padding: 8px 16px;
text-decoration: none;
}

Continue reading CSS Pagination Examples

CSS Masking

With CSS masking you create a mask layer to place over an element to partially or fully hide portions of the element.

The CSS mask-image Property

The CSS mask-image property specifies a mask layer image.

The mask layer image can be a PNG image, an SVG image, a CSS gradient, or an SVG <mask> element. Continue reading CSS Masking

CSS The object-position Property

The CSS object-position property is used to specify how an <img> or <video> should be positioned within its container.

Example

img {
width: 200px;
height: 300px;
object-fit: cover;
}

Continue reading CSS The object-position Property

CSS The object-fit Property

The CSS object-fit property is used to specify how an <img> or <video> should be resized to fit its container.

The CSS object-fit Property

The CSS object-fit property is used to specify how an <img> or <video> should be resized to fit its container.

This property tells the content to fill the container in a variety of ways; such as “preserve that aspect ratio” or “stretch up and take up as much space as possible”. Continue reading CSS The object-fit Property