Skip to main content

Content

Images

Documentation and examples for opting images into responsive behavior (so they never become wider than their parent) and add lightweight styles to them—all via classes.

View page source on GitHub

Responsive images#

Images in felt-css are made responsive with .img-fluid. This applies max-width: 100%; and height: auto; to the image so that it scales with the parent width.

Sample photo
<img src="../../../docs/sample-photo.webp" class="img-fluid" alt="Sample photo" width="600" height="400">

felt-css's Reboot already gives every <img> and <svg> max-width: 100%, but no height: auto: like in Bootstrap, the width and height attributes size the box, so use .img-fluid for images that should shrink with their parent.

Image thumbnails#

In addition to the border-radius utilities, you can use .img-thumbnail to give an image a rounded 1px border appearance.

Sample photo
<img src="../../../docs/sample-photo.webp" class="img-thumbnail" alt="Sample photo" width="300" height="200">

In the felt look, thumbnails, figure images and img.rounded lie on the felt like photos on a pin board: a hairline edge and a small shadow underneath.

Icons#

A felt-css extra: .icon puts an image of any shape into a square box, 2.25rem by default, contained and never squeezed in a flex row. .icon-sm and .icon-lg make it 1.75rem and 3.5rem; for any other size set --felt-icon-size on the icon or a parent.

<img src="../../assets/plush/co2_good.webp" class="icon icon-sm" alt="">
<img src="../../assets/plush/co2_good.webp" class="icon" alt="">
<img src="../../assets/plush/co2_good.webp" class="icon icon-lg" alt="">
<img src="../../assets/plush/co2_good.webp" class="icon" style="--felt-icon-size: 5rem" alt="">

Aligning images#

Align images with the helper float classes or text alignment classes. block-level images can be centered using the .mx-auto margin utility class.

Sample photo Sample photo
<img src="../../../docs/sample-photo.webp" class="rounded float-start" alt="Sample photo" width="200" height="133">
<img src="../../../docs/sample-photo.webp" class="rounded float-end" alt="Sample photo" width="200" height="133">
Sample photo
<img src="../../../docs/sample-photo.webp" class="rounded mx-auto d-block" alt="Sample photo" width="200" height="133">
Sample photo
<div class="text-center">
  <img src="../../../docs/sample-photo.webp" class="rounded" alt="Sample photo" width="200" height="133">
</div>

Picture#

If you are using the <picture> element to specify multiple <source> elements for a specific <img>, make sure to add the .img-* classes to the <img> and not to the <picture> tag.

<picture>
  <source srcset="..." type="image/svg+xml">
  <img src="..." class="img-fluid img-thumbnail" alt="...">
</picture>