Skip to content

Commit 5938dd4

Browse files
committed
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?)
1 parent 3d26544 commit 5938dd4

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

app/assets/stylesheets/application.scss

+4
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,7 @@ $govuk-include-default-font-face: false;
5454
text-align: start;
5555
}
5656
}
57+
58+
.constrained-image {
59+
max-width: 100%;
60+
}

app/views/content_items/how_government_works.html.erb

+4-4
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@
103103
</p>
104104

105105
<% if @content_item.prime_minister.present? && @content_item.prime_minister_image_url.present? %>
106-
<%= image_tag @content_item.prime_minister_image_url, { alt: @content_item.prime_minister_image_alt_text, width: '465', height: '310' } %>
106+
<%= image_tag @content_item.prime_minister_image_url, { class: 'constrained-image', alt: @content_item.prime_minister_image_alt_text } %>
107107
<% else %>
108-
<%= image_tag 'how-gov-works/10_downing_street.jpg', alt: '10 Downing Street', width: '465', height: '310' %>
108+
<%= image_tag 'how-gov-works/10_downing_street.jpg', class: 'constrained-image', alt: '10 Downing Street' %>
109109
<% end %>
110110
</section>
111111

@@ -120,7 +120,7 @@
120120
<p class="govuk-body">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.</p>
121121
<p class="govuk-body govuk-!-margin-bottom-8"><%= link_to("See who is in the Cabinet", "/government/ministers", class: "govuk-link") %></p>
122122

123-
<%= image_tag 'how-gov-works/cabinet_01.jpg', alt: '', width: '465', height: '310' %>
123+
<%= image_tag 'how-gov-works/cabinet_01.jpg', class: 'constrained-image', alt: '' %>
124124
</section>
125125
</section>
126126
</div>
@@ -517,7 +517,7 @@
517517
<p class="govuk-body">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.</p>
518518
<p class="govuk-body govuk-!-margin-bottom-8">You can also find links to <%= link_to "historical research", "/government/history#historical-research", class: "govuk-link" %>, documents and records.</p>
519519

520-
<%= image_tag 'how-gov-works/churchill_01.jpg', alt: '', width: '465', height: '310' %>
520+
<%= image_tag 'how-gov-works/churchill_01.jpg', class: 'constrained-image', alt: '' %>
521521
</section>
522522
</div>
523523
</div>

0 commit comments

Comments
 (0)