LoginSignup
29

More than 5 years have passed since last update.

CSSだけでaタグのリンク先プレビューを表示する

Last updated at Posted at 2016-06-25

解説

cssのafter擬似要素にcontentプロパティで値attr(href)を指定し、hover時に表示する感じです。

必要に応じて見た目の装飾をしてあげて下さい。

なお、aタグにはposition: relativeを指定したほうが良いかもしれません。

デモ

コード

html
<a href="http://io.tedokon.com">ここ!</a>
css
a:after {
  position: absolute;
  content: attr(href);
  display: none;
}

a:hover:after {
  display: block;
}

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
29