Skip to content

Commit

Permalink
Update header to use new link styles
Browse files Browse the repository at this point in the history
Avoid using the `govuk-link-common` mixin because the links in the header get a special treatment:

- underlines are only visible on hover
- all links get a 3px underline regardless of text size, as there are multiple grouped elements close to one another and having slightly different underline widths looks unbalanced.

There’s a bit of duplication here between the `govuk-header__link` and `govuk-header__menu-button` classes, but there are other issues with the menu button that will need addressing soon so we’ll live with that for now rather than trying to refactor.
  • Loading branch information
36degrees committed Apr 30, 2021
1 parent 8187b57 commit 6f90027
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions src/govuk/components/header/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
$govuk-header-border-color: $govuk-brand-colour;
$govuk-header-border-width: govuk-spacing(2);
$govuk-header-text: govuk-colour("white");
$govuk-header-link: govuk-colour("white");
$govuk-header-link-hover: govuk-colour("white");
$govuk-header-link-active: #1d8feb;
$govuk-header-nav-item-border-color: #2e3133;
$govuk-header-link-underline-thickness: 3px;

.govuk-header {
@include govuk-font($size: 16);
Expand Down Expand Up @@ -40,6 +39,10 @@
// Add a gap between logo and any product name
margin-right: govuk-spacing(1);

// Prevent readability backplate from obscuring underline in Windows
// High Contrast Mode
forced-color-adjust: none;

// But remove it if there's nothing after the logo to keep hover and focus
// states neat
&:last-child {
Expand Down Expand Up @@ -68,29 +71,30 @@
}

.govuk-header__link {
text-decoration: none;
// Avoid using the `govuk-link-common` mixin because the links in the header
// get a special treatment, because:
//
// - underlines are only visible on hover
// - all links get a 3px underline regardless of text size, as there are
// multiple grouped elements close to one another and having slightly
// different underline widths looks unbalanced
@include govuk-typography-common;
@include govuk-link-style-inverse;

&:link,
&:visited {
color: $govuk-header-link;
}
text-decoration: none;

&:hover {
text-decoration: underline;
text-decoration-thickness: $govuk-header-link-underline-thickness;

@if ($govuk-link-underline-offset) {
text-underline-offset: $govuk-link-underline-offset;
}
}

&:focus {
@include govuk-focused-text;
}

// alphagov/govuk_template includes a specific a:link:focus selector
// designed to make unvisited links a slightly darker blue when focussed, so
// we need to override the text colour for that combination of selectors.
@include govuk-compatibility(govuk_template) {
&:link:focus {
@include govuk-text-colour;
}
}
}

.govuk-header__link--homepage {
Expand All @@ -111,10 +115,10 @@
&:hover,
&:active {
// Negate the added border
margin-bottom: -1px;
margin-bottom: $govuk-header-link-underline-thickness * -1;
// Omitting colour will use default value of currentColor – if we
// specified currentColor explicitly IE8 would ignore this rule.
border-bottom: 1px solid;
border-bottom: $govuk-header-link-underline-thickness solid;
}

// Remove any borders that show when focused and hovered.
Expand Down Expand Up @@ -164,12 +168,16 @@
margin: 0;
padding: 0;
border: 0;
color: $govuk-header-link;
color: govuk-colour("white");
background: none;
cursor: pointer;

&:hover {
text-decoration: underline;
text-decoration: solid underline $govuk-header-link-underline-thickness;

@if ($govuk-link-underline-offset) {
text-underline-offset: $govuk-link-underline-offset;
}
}

&:focus {
Expand Down

0 comments on commit 6f90027

Please sign in to comment.