Making images bigger on my website


Many of my Advent of Patterns blog posts contain visuals that accompany the text. This is different from much of my previous writing which was text-focused; technical guides, poetry, musings.

When looking through my posts, I noticed that some of the details of the images were hard to grasp because they were too small. I was trying to fit the images in a container designed for text: a container whose maximum width was set to be most readable for text, without particular consideration for images.

This got me thinking: how can I make my blog images bigger so they are easier to read?

I decided to follow in the footsteps of the BBC and create a design that lets images be wider than the main content container, but only on the right side.

A BBC article with an image that grows outside the text container

Letting the content grow only on the right side is important because I have a sidebar on the left side of the page. If the image was wider on both sides, the image may overlap with the sidebar. I love the pattern of making an image wider on both sides, but it works best on center-aligned text with plenty of space on either side. My website, on the other hand, uses two columns that are close together.

I had two requirements:

  1. The image should be wider on the right side, and;
  2. The minimum size for the image should be equal to the width of the text column.

I implemented this using the following CSS rule to img tags in my blog posts:

width: clamp(100%, 130%, 65vw);

The CSS clamp attribute lets you specify a minimum, preferred, and maximum value. The browser will then compute which value to use that matches those specifications. In this case, I say that I want images to :

  • Have a minimum width of 100%. This means the maximum size of the content container, which is around 35rem.
  • Have a preferred width of 130%. This allows the image to grow outside the container without getting too big.
  • Have a maximum width of 65vw.

With this one rule, I can have images that are bigger than the parent container that scale at different resolutions.

The following video shows an image scaling as the browser is resized:

This change makes it much easier to see the details in images on bigger screens that were previously confined to a much smaller space.

If you have any suggestions on how to make this feature better, please let me know!



Source link

Visited 2 times, 1 visit(s) today

Related Article

Donald Trump addressing a joint session of Congress during his State of the Union speech.

Think President Donald Trump’s Tariffs Are Wall Street’s Biggest Concern? Then You’re Completely Overlooking This Colossal Problem.

While tariffs are a tangible worry for investors, something far more nefarious (and important) can weigh on the stock market. When examined with a wide lens, no asset class has come particularly close to matching or surpassing the annualized return of stocks. But generating life-changing long-term returns in the stock market often means enduring periods

A couple watching TV.

2 Stocks to Buy With $5,000 and Hold for a Decade

Streaming giants Netflix (NFLX 0.92%) and Roku (ROKU 2.05%) have a lot in common. The former was an early investor in the latter. They both dominate their respective niches in the streaming industry and have produced market-beating returns over the long term. Here’s one more thing Netflix and Roku have in common: excellent long-term prospects

Warren Buffett smiling at an event.

Is Berkshire Hathaway the Smartest Investment You Can Make Today?

If you spend any time around Wall Street, from just reading market news to actually working in finance, you know the names Warren Buffett and Berkshire Hathaway (BRK.A 0.98%) (BRK.B 0.98%), which is the company he runs. Despite the stock’s incredible track record, however, there are reasons it may not be the smartest investment you

Rangers head coach Russell Martin and James Tavernier

What did Martin’s first game as Rangers boss tell us?

Image source, SNSImage caption, Russell Martin brought James Tavernier on as a second-half substitute Kheredine Idessane BBC Sport Scotland Senior Reporter at Ibrox A crowd of nearly 30,000 braved the Scottish July drizzle to cheer on Rangers in Russell Martin’s first game as head coach at Ibrox. Goals from Hugo Vetlesen and Ludovit Reis gave

Article image:Report: Arsenal’s new pivot tipped to transform Arteta’s tactical setup

Report: Arsenal’s new pivot tipped to transform Arteta’s tactical setup

Strategic move to land Zubimendi over Real Madrid Arsenal have secured a key addition to their midfield with the £50 million capture of Martin Zubimendi from Real Sociedad, seeing off competition from Real Madrid in the process. It is a signing rooted in detailed planning, long-term vision and a manager’s persuasive influence. Mikel Arteta first

Fire erupts after Israeli strikes in Gaza

Gaza ceasefire talks set to resume in Doha as Israeli airstrikes continue in the Strip

Indirect negotiations between Israel and Hamas for a possible ceasefire in Gaza are set to resume Sunday in Doha amid the backdrop of continued deadly Israeli attacks in the Strip. Israeli airstrikes killed at least 38 Palestinians in Gaza, hospital officials told the Associated Press on Sunday, as Israel’s military said it has struck over

0
Would love your thoughts, please comment.x
()
x