Skip to content

Commit

Permalink
Fix oversized images
Browse files Browse the repository at this point in the history
- 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?)
  • Loading branch information
andysellick committed Jul 8, 2024
1 parent 3d26544 commit 5938dd4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@ $govuk-include-default-font-face: false;
text-align: start;
}
}

.constrained-image {
max-width: 100%;
}
8 changes: 4 additions & 4 deletions app/views/content_items/how_government_works.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@
</p>

<% 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 %>
</section>

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

<%= 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: '' %>
</section>
</section>
</div>
Expand Down Expand Up @@ -517,7 +517,7 @@
<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>
<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>

<%= 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: '' %>
</section>
</div>
</div>
Expand Down

0 comments on commit 5938dd4

Please sign in to comment.