From 5938dd472f8beba0d9f06765554963c6d9da6117 Mon Sep 17 00:00:00 2001
From: Andy Sellick
Date: Mon, 8 Jul 2024 15:56:57 +0100
Subject: [PATCH] Fix oversized images
- fix oversized images on the 'how government works' page https://www.gov.uk/government/how-government-works
- remove hard coded image dimensions and add a class that sets `max-width: 100%`
- was causing the images to overlap the width of the screen at small screen sizes, causing a horizontal scroll bar and a broken layout
- only adding the class or only removing the width/height don't fix the problem, because width/height as inline attributes override CSS
- was hoping to be able to leave the width/height to reduce cumulative layout shift when loading, but this is a small loss compared to fixing the general appearance
- surprised we don't have a general class to have all `img` tags with `max-width: 100%` but since there isn't one I don't want to try introducing one here as proving it's fine on every page is a much bigger task (although logically it should be... right?)
---
app/assets/stylesheets/application.scss | 4 ++++
app/views/content_items/how_government_works.html.erb | 8 ++++----
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss
index 69b162440..5f3f96f13 100644
--- a/app/assets/stylesheets/application.scss
+++ b/app/assets/stylesheets/application.scss
@@ -54,3 +54,7 @@ $govuk-include-default-font-face: false;
text-align: start;
}
}
+
+.constrained-image {
+ max-width: 100%;
+}
diff --git a/app/views/content_items/how_government_works.html.erb b/app/views/content_items/how_government_works.html.erb
index 313c10dc4..2089a6159 100644
--- a/app/views/content_items/how_government_works.html.erb
+++ b/app/views/content_items/how_government_works.html.erb
@@ -103,9 +103,9 @@
<% if @content_item.prime_minister.present? && @content_item.prime_minister_image_url.present? %>
- <%= image_tag @content_item.prime_minister_image_url, { alt: @content_item.prime_minister_image_alt_text, width: '465', height: '310' } %>
+ <%= image_tag @content_item.prime_minister_image_url, { class: 'constrained-image', alt: @content_item.prime_minister_image_alt_text } %>
<% else %>
- <%= image_tag 'how-gov-works/10_downing_street.jpg', alt: '10 Downing Street', width: '465', height: '310' %>
+ <%= image_tag 'how-gov-works/10_downing_street.jpg', class: 'constrained-image', alt: '10 Downing Street' %>
<% end %>
@@ -120,7 +120,7 @@
The Cabinet is made up of the senior members of government. Every week during Parliament, members of the Cabinet (Secretaries of State from all departments and some other ministers) meet to discuss the most important issues for the government.
<%= link_to("See who is in the Cabinet", "/government/ministers", class: "govuk-link") %>
- <%= image_tag 'how-gov-works/cabinet_01.jpg', alt: '', width: '465', height: '310' %>
+ <%= image_tag 'how-gov-works/cabinet_01.jpg', class: 'constrained-image', alt: '' %>
@@ -517,7 +517,7 @@
Read about past Prime Ministers, Chancellors and Foreign Secretaries in <%= link_to "notable people", "/government/history#notable-people", class: "govuk-link" %>. Learn more about historic <%= link_to "government buildings", "/government/history#government-buildings", class: "govuk-link" %> on Whitehall and around the UK.
You can also find links to <%= link_to "historical research", "/government/history#historical-research", class: "govuk-link" %>, documents and records.
- <%= image_tag 'how-gov-works/churchill_01.jpg', alt: '', width: '465', height: '310' %>
+ <%= image_tag 'how-gov-works/churchill_01.jpg', class: 'constrained-image', alt: '' %>