Skip to content

Commit 992f1d4

Browse files
authored
fix: article image alignment and sizing (#1050)
## Overview > [!IMPORTANT] > **To Do** > - [x] Extract ee9838c and b7d7df7 to separate PR. > - [ ] Update image thumbnail opts of all sites that have News. > - [ ] Prepare to [offset small main image](https://github.com/user-attachments/assets/a97471ce-209a-4691-bdcc-5da827207c49) instead of [just align](https://github.com/user-attachments/assets/51ef1107-1bb5-40a7-8e07-79b5947a3380). Fix alignment and size of: 1. main image (on news article page): - narrow image, narrow screen - full-width image[^1], narrow screen - narrow image, wide screen - full-width image[^1], wide screen 2. thumbnail image (on news feed page and embed): - narrow image, narrow screen - full-width image[^1], narrow screen - narrow image, wide screen - full-width image[^1], wide screen [^1]: I.e. use a Thumbnail Option with `width` of `0`. ## Related - [RT #37827](https://tickets.tacc.utexas.edu/Ticket/Display.html?id=37827) ## Changes - **renamed** mixins to express what its styles do - `news-article-page__media--slim-context` → `…--layout-center` - `news-article-page__media--wide-context` → `…--layout-float` - **changed** mixin `…--layout-center` to be used **only** if main image thumb. opt. has `0` width - **fixed** unaligned blog content images - **deleted** unnecessary code - **fixed** large article list image from overflowing list - **fixed** small article list image from not filling item - **changed** overwritten code to be reminder comment instead - **moved** mixins `news-article-page__media--…` - from `x-news.css` - to `django.cms.blog.app.page.css` - **changed** markup of form to choose news list layout - **added** thumb. opt. values into HTML (for CSS) - `data-width` - `data-height` ## Testing Given an article main image of thumbnail size with **width = 0**: - On news **article page**, that image should be: - as wide as content - On news **feed page** (and **feed embed**): - In **list view**: - On a wide screen (1 wide column), that image should be **no wider than 50%**. - On a narrow screen (1 narrow column), that image should **shrink** to fit item. - In **grid layout**[^2]: - On a wide screen (N narrow columns), that image should **shrink** to fit item. - On a narrow screen (1 narrow column), that image should **shrink** to fit item. Given an article main image of thumbnail size with **width > 0**: - On news **article page**, that image should be: - no wider than 50% of content - right-aligned - On news **feed page** (and **feed fembed**): - In list view: - On a wide screen (1 wide column), that image width should **define media grid cell width**. - On a narrow screen (1 narrow column), that image should **grow** to fit item. - In grid view: - On a wide screen (N narrow columns), that image should **grow** to fit item. - On a narrow screen (1 narrow column), that image should **grow** to fit item. [^2]: This is a secret layout. Unhide the `#layout-choice-form` element to reveal the layout options. ## UI Skipped.
1 parent 5590821 commit 992f1d4

File tree

3 files changed

+40
-15
lines changed

3 files changed

+40
-15
lines changed

taccsite_cms/static/site_cms/css/src/_imports/components/django.cms.blog.app.page.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,20 @@ Styleguide Components.DjangoCMS.Blog.App.Page
8181
/* To support vertical layouts at narrow viewports */
8282
:--news-article-page .blog-visual {
8383
@mixin news-article-page__media;
84+
85+
@media (--medium-and-below) {
86+
& {
87+
@mixin news-article-page__media--layout-center;
88+
}
89+
}
90+
@media (--medium-and-above) {
91+
&:has([data-width="0"]) {
92+
@mixin news-article-page__media--layout-center;
93+
}
94+
&:not(:has([data-width="0"])) {
95+
@mixin news-article-page__media--layout-float;
96+
}
97+
}
8498
}
8599

86100
/* To prevent footer on left side of page */
@@ -175,6 +189,15 @@ Styleguide Components.DjangoCMS.Blog.App.Page
175189
:--news-article-page .blog-content .align-right,
176190
:--news-article-page .blog-content .align-left {
177191
max-width: 100%;
192+
193+
/* So figure or linked image will center if not aligned */
194+
&:is(a, figure) {
195+
margin-inline: auto;
196+
}
197+
&:is(a) {
198+
display: block;
199+
width: fit-content;
200+
}
178201
}
179202
:--news-article-page .blog-content .align-right,
180203
:--news-article-page .blog-content .align-left {

taccsite_cms/static/site_cms/css/src/_imports/tools/x-news.css

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@
104104
}
105105
@define-mixin news-feed--as-grid {
106106
display: grid;
107-
grid-template-columns: repeat( auto-fit, minmax(300px, 1fr) );
107+
/* IMPORTANT: Define column widths per instance/usage e.g.
108+
grid-template-columns: repeat( N, 1fr );
109+
grid-auto-columns: fit-content( NN% );
110+
*/
108111

109112
gap: var(--global-space--pattern-pad);
110113
}
@@ -146,8 +149,6 @@
146149
'media'
147150
'head'
148151
'lead';
149-
/* To prevent content from overflowing cell */
150-
grid-template-columns: minmax(0, 1fr);
151152
/* To prevent vertical stretch of rows */
152153
grid-auto-rows: min-content;
153154

@@ -158,7 +159,7 @@
158159
'media head'
159160
'media lead';
160161
/* To limit media width */
161-
grid-template-columns: minmax(0, 300px) 1fr;
162+
grid-template-columns: fit-content(50%) 1fr;
162163
/* To give 'lead' remaining vert. space (removes gap between head and lead) */
163164
grid-template-rows: min-content 1fr;
164165

@@ -248,7 +249,9 @@
248249
/* To limit media width to size of media grid area */
249250
@define-mixin news-feed-article__media--constrain-content {
250251
& img {
251-
/* to prevent overflow if column is narrower than image */
252+
/* to prevent narrow image if column is wider than image */
253+
width: 100%;
254+
/* to prevent image overflow if column is narrower than image */
252255
max-width: 100%;
253256
/* to preserve ratio if width is reduced (by max-width: 100%) */
254257
height: auto;
@@ -366,24 +369,23 @@
366369
/* Media */
367370

368371
@define-mixin news-article-page__media {
369-
@media (--medium-and-below) {
370-
@mixin news-article-page__media--slim-context;
371-
}
372-
@media (--medium-and-above) {
373-
@mixin news-article-page__media--wide-context;
374-
}
375-
376372
/* To not show empty block (which might have margin) */
377373
&:empty {
378374
display: none;
379375
}
380376
}
381-
@define-mixin news-article-page__media--slim-context {
377+
@define-mixin news-article-page__media--layout-center {
382378
margin-inline: auto;
383379
width: fit-content;
384380
}
385-
@define-mixin news-article-page__media--wide-context {
381+
@define-mixin news-article-page__media--layout-float {
386382
float: right;
387383
max-width: 50%;
388384
margin-left: 45px;
385+
386+
/* TODO: Ask designer whether to offset a floated main image */
387+
/* WARNING: Requires Core-Styles @define-mixin offset-content(--…) */
388+
/*
389+
@extend .o-offset-content--right;
390+
*/
389391
}

taccsite_cms/templates/djangocms_blog/post_detail.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ <h3>{% render_model post "subtitle" %}</h3>
4747
{% else %}
4848
<div class="blog-visual">
4949
{% thumbnail post.main_image post.full_image_options.size crop=post.full_image_options.crop upscale=post.full_image_options.upscale subject_location=post.main_image.subject_location as thumb %}
50-
<img src="{{ thumb.url }}" alt="{{ post.main_image.default_alt_text }}" width="{{ thumb.width }}" height="{{ thumb.height }}" />
50+
<img src="{{ thumb.url }}" alt="{{ post.main_image.default_alt_text }}" width="{{ thumb.width }}" height="{{ thumb.height }}" data-width="{{ post.full_image_options.width }}" data-height="{{ post.full_image_options.height }}" />
5151
</div>
5252
{% endif %}
5353
{# TACC (do not let source end spaceless-ness prematurely): #}

0 commit comments

Comments
 (0)