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

CSS Image Shapes

With CSS it is easy to shape (clip) images to circles, ellipses and polygons.

The CSS clip-path Property

The clip-path property lets you clip an element to a basic shape.

The CSS circle() Function

The circle() function defines a circle with a radius and a position.

The circle() function is used within the clip-path property.

Continue reading CSS Image Shapes

CSS Image Filter Effects

The CSS filter property is used to add visual effects to elements.

CSS Filters

The CSS filter property is used to add visual effects (like blur and saturation) to elements.

Within the filter property, you can use the following CSS functions:

  • blur()
  • brightness()
  • contrast()
  • drop-shadow()
  • grayscale()
  • hue-rotate()
  • invert()
  • opacity()
  • saturate()
  • sepia()

Continue reading CSS Image Filter Effects

CSS Centering Images

Center an Image Horizontally in Two Ways

1. Using margin: auto

One way to center an image horizontally on a page is to use margin: auto.

Since the <img> element is an inline element (and
margin: auto
does not have any effect on inline elements) we also must convert the image to a block element, with display: block.

In addition, we have to define a width. The width of the image must be smaller than the width of the page.

Here is a horizontally centered image using margin: auto.

Continue reading CSS Centering Images

CSS Tooltip

Create tooltips with CSS.

Basic Tooltip

Create a tooltip that appears when the user moves the mouse over an element:

Example

<style>
/* Tooltip container */
.tooltip {
  position: relative;
  display: inline-block;
  border-bottom: 1px dotted black; /* If you want dots under the hoverable text */
}

/* Tooltip text */
.tooltip .tooltiptext {
  visibility: hidden;
  width: 120px;
  background-color: black;
  color: #fff;
  text-align: center;
  padding: 5px 0;
  border-radius: 6px;
 
  /* Position the tooltip text - see examples below! */
  position: absolute;
  z-index: 1;
}

/* Show the tooltip text when you mouse over the tooltip container */
.tooltip:hover .tooltiptext {
  visibility: visible;
}
</style>

<div class="tooltip">Hover over me
  <span class="tooltiptext">Tooltip text</span>
</div>
Hover over me Tooltip text

Continue reading CSS Tooltip