Skip to content

Commit

Permalink
Fix alignment of deep link icon
Browse files Browse the repository at this point in the history
Setting manual margins is fragile. Remove them to fix bad alignment in
about pages, since the icon is vertically aligned already.

It looks good to me as is, but if we want to change the alignment, we
should change the SVG instead.
  • Loading branch information
rakyi committed Dec 19, 2024
1 parent c8a7958 commit 897c586
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 62 deletions.
2 changes: 1 addition & 1 deletion site/gdocs/components/AllCharts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function AllCharts(props: AllChartsProps) {
className="article-block__heading h1-semibold"
id={ALL_CHARTS_ID}
>
{heading}
<span>{heading}</span>
<a
className="deep-link"
aria-labelledby={ALL_CHARTS_ID}
Expand Down
2 changes: 1 addition & 1 deletion site/gdocs/components/KeyInsights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ export const KeyInsights = ({
className="article-block__heading h1-semibold"
id={KEY_INSIGHTS_ID}
>
{heading}
<span>{heading}</span>
<a
className="deep-link"
aria-labelledby={KEY_INSIGHTS_ID}
Expand Down
4 changes: 0 additions & 4 deletions site/gdocs/components/ResearchAndWriting.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ $rw-margin-bottom-grid-cell: 4px;
@include sm-up {
margin: 32px 0 24px;
}

a.deep-link {
margin-top: 11px;
}
}

.research-and-writing-row__heading {
Expand Down
2 changes: 1 addition & 1 deletion site/gdocs/components/ResearchAndWriting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export function ResearchAndWriting(props: ResearchAndWritingProps) {
className="article-block__heading span-cols-12 h1-semibold"
id={slug}
>
{heading || RESEARCH_AND_WRITING_DEFAULT_HEADING}
<span>{heading || RESEARCH_AND_WRITING_DEFAULT_HEADING}</span>
<a
className="deep-link"
aria-labelledby={slug}
Expand Down
24 changes: 0 additions & 24 deletions site/gdocs/components/centered-article.scss
Original file line number Diff line number Diff line change
Expand Up @@ -288,46 +288,22 @@ $banner-height: 200px;
}
}

.article-block__heading {
a.deep-link {
position: absolute;
}

&:hover {
a.deep-link {
opacity: 1;
}
}
}

h1.article-block__heading {
a.deep-link {
margin-top: 16px;
height: 16px;
width: 16px;
@include sm-only {
margin-top: 10px;
}
}
}
h2.article-block__heading {
a.deep-link {
margin-top: 11px;
height: 14px;
width: 14px;
@include sm-only {
margin-top: 10px;
}
}
}
h3.article-block__heading {
a.deep-link {
margin-top: 8px;
height: 12px;
width: 12px;
@include sm-only {
margin-top: 10px;
}
}
}

Expand Down
21 changes: 3 additions & 18 deletions site/gdocs/components/topic-page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -203,38 +203,23 @@
}
h1.article-block__heading.h1-semibold {
font-size: 2.25rem;
a.deep-link {
margin-top: 19px;
}

@include sm-up {
font-size: 2.625rem;
a.deep-link {
margin-top: 23px;
}
}
}
h2.article-block__heading.h2-bold {
font-size: 1.5rem;
a.deep-link {
margin-top: 13px;
}

@include sm-up {
font-size: 2rem;
a.deep-link {
margin-top: 19px;
}
}
}
h3.article-block__heading.h3-bold {
font-size: 1.25rem;
a.deep-link {
margin-top: 10px;
}

@include sm-up {
font-size: 1.5rem;
a.deep-link {
margin-top: 12px;
}
}
}
}
52 changes: 39 additions & 13 deletions site/owid.scss
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ main {
display: inline-block;
width: 28px;
height: 20px;
margin-left: 0.5rem;
font-size: 16px;
background: url("data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTgiIGhlaWdodD0iMTgiIHZpZXdCb3g9IjAgMCAxOCAxOCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNMTEuNDgyIDYuNTE3MThDMTMuNTgyNSA4LjYxOTg0IDEzLjU1MzYgMTEuOTkwOSAxMS40OTQ2IDE0LjA2MTRDMTEuNDkwOCAxNC4wNjU2IDExLjQ4NjIgMTQuMDcwMi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kzNEMxOC41MjA0IDcuMDM2MDIgMTguNTIwNCAzLjY0NTU1IDE2LjQzNjcgMS41NjIxOVYxLjU2MjE5WiIgZmlsbD0iY3VycmVudENvbG9yIiBmaWxsLW9wYWNpdHk9IjAuMjUiLz48L3N2Zz4=")
no-repeat left;
Expand All @@ -227,21 +226,48 @@ main {
&:focus {
opacity: 1;
}
}

@include touch-device {
// It's not visible because of the opacity anyway, but if it's the
// only reason the whole heading wraps to the next line, it adds
// vertical space, which shouldn't be there.
display: none;
h1,
h2,
h3,
h4,
h5,
h6 {
// Avoid wrapping the deep-link to the next line as an orphan. Using &nbsp;
// doesn't work and programmatically wrapping the last word and the
// deep-link in a span with text-wrap: nowrap would be an even bigger hack.
&:has(.deep-link) {
> *:first-child {
padding-right: 2rem;

// On touch devices, the deep-link is hidden, so we don't need the
// padding to make space for it.
@include touch-device {
padding-right: 0;
}
}
}

.deep-link {
// Margin is a bit smaller than the padding on the preceding element to
// add a bit of space between them.
margin-left: -1.5rem;

@include touch-device {
// It's not visible because of the opacity anyway, but it can add
// enough vertical space to cause the heading to wrap to the next
// line. Hide it instead, so the heading can use as much space as
// possible.
display: none;
}
}
}

h2:hover .deep-link,
h3:hover .deep-link,
h4:hover .deep-link,
h5:hover .deep-link,
h6:hover .deep-link {
opacity: 1;
&:hover {
.deep-link {
opacity: 1;
}
}
}

.heading-latest {
Expand Down

0 comments on commit 897c586

Please sign in to comment.