ライブデモ Live Demo

リンクにホバーすると、下線が中央から左右に伸びます。速度と色をカスタムプロパティで調整できます。

On hover, the underline grows from the center. Adjust speed and color via custom properties.

0.3s

AI向け説明 AI Description

`M-007` はリンクの `::after` 擬似要素で下線を描画し、`left: 50%` と `width: 0` から `left: 0` と `width: 100%` へ `transition` で変化させます。中央から左右に伸びる表現は Hover.css などでよく使われるパターンです。

`M-007` draws the underline with a `::after` pseudo-element. A `transition` animates from `left: 50%` and `width: 0` to `left: 0` and `width: 100%`, creating a center-to-sides grow effect common in Hover.css-style patterns.

調整可能パラメータ Adjustable Parameters

実装 Implementation

HTML + CSS

<a href="#" class="underline-link">Link Text</a>

<style>
:root {
  --underline-duration: 0.3s;
  --underline-color: #5c6ac4;
  --underline-height: 2px;
}

.underline-link {
  position: relative;
  text-decoration: none;
  color: inherit;
}

.underline-link::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -4px;
  width: 0;
  height: var(--underline-height);
  background: var(--underline-color);
  transition: width var(--underline-duration) ease, left var(--underline-duration) ease;
}

.underline-link:hover::after,
.underline-link:focus-visible::after {
  left: 0;
  width: 100%;
}
</style>

React (JSX + CSS)

// react/M-007.jsx
import "./M-007.css";

export default function UnderlineGrowLink({ href, children }) {
  return (
    <a href={href} className="underline-link">
      {children}
    </a>
  );
}
/* react/M-007.css */
.underline-link {
  position: relative;
  text-decoration: none;
  color: inherit;
}

.underline-link::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -4px;
  width: 0;
  height: 2px;
  background: #5c6ac4;
  transition: width 0.3s ease, left 0.3s ease;
}

.underline-link:hover::after,
.underline-link:focus-visible::after {
  left: 0;
  width: 100%;
}

AIへの指示テンプレート AI Prompt Template

以下のテンプレートをコピーしてAIアシスタントに貼り付けると、このパターンの実装を依頼できます。 Copy the template below and paste it into your AI assistant to request an implementation of this pattern.

注意とバリエーション Notes & Variations

左から右に伸ばす場合は `left: 0` のまま `width` のみ 0→100% に変更します。参考: Hover.css (ianlunn.github.io/Hover/)。

For left-to-right only growth, keep `left: 0` and animate only `width` from 0 to 100%. Reference: Hover.css.