LoginSignup
kakimoto5
@kakimoto5 (剛 柿本)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

リストの中にaタグを入れる

解決したいこと

ヘッダーメニューです。
リストがありその中に文字が書いてあり、そのにリンクを入れたいのでaタグを入れたいのですが、aタグは空白にしたくてどうすればうまくいくか教えて欲しいです。

最初は文字が書いてない円4つがあり
ホバーするとメニューが縦にビヨンと展開され、
文字が出てきます。

しかしaタグを入れると、どうしてもホバー後の文字がズレるのでそれを解決したいです。

よろしくお願いします。

HTML

<ul>
  <li><a href="#firstPage" class="nav_btn"></a>Top</li>
  <li><a href="#secondPage" class="nav_btn"></a>Product</li>
  <li><a href="#3rdPage" class="nav_btn"></a>Price</li>
  <li><a href="#4thpage" class="nav_btn"></a>Contact</li>
</ul>

css

$size: 50px; 
$offsetAmount: 1.1; 
$transitionTime: 0.12s; 

ul{
  display: block;
  margin-right: 10px; 
  width: $size; 
  height: $size; 
  padding-top: 90px; 
  // position: relative;
  float: right;
  z-index: 1;
}

li {
  display: block; 
  width: $size;
  height: $size; 
  background-color: $blue; 
  border-radius: 50%; 
  opacity: 0.6; 
  mix-blend-mode: screen;
  position: absolute; 
  top: -73; 
  right: 1; 
  // float: right;
  transition: transform $transitionTime ease-out, opacity $transitionTime ease-out, color $transitionTime ease-out; 
  cursor: pointer; 
  text-align: center; 
  line-height: $size; 
  color: $blue; 
  color: transparent; 
}

/*
li:after{
  content: "";
  display: block; 
  bottom: 100%; 
  left: 50%; 
  height: ($offsetAmount*100%)-100; 
  margin-left: -1px; 
  position: absolute; 
  width: 4px; 
  background-color: inherit; 
  opacity: 0; 
  transition: opacity $transitionTime ease-out; 
}
*/
li:first-child:after{
  display: none; 
}
$offset:20%; 
$colors: $blue, $blue, $blue, $blue;
$transforms:  translate(0,-$offset), 
              translate($offset,0), 
              translate(0,$offset),
              translate(-$offset,0);

@for $i from 1 through 4{
  li:nth-child(#{$i}){ 
    background-color: nth($colors, $i); 
    transform: nth($transforms, $i);
    z-index: 4 - $i; 
    transition-duration: $transitionTime * $i; 
  }

} 


ul:hover{
  height: (4*$offsetAmount) * $size; 

  li {
    color: white; 
  }


  @for $i from 1 through 4{
    li:nth-child(#{$i}){ 
      transform: translate(0, ($i - 1)*($offsetAmount*100%));

     &:hover{
      opacity: 1; 
      transition-timing-function: cubic-bezier(.5,0,.5,1);
      transform: translate(0, ($i - 1)*($offsetAmount*100%))  scale(1.15, 1.15); 
       transition-duration: $transitionTime*2; 
     }

    }

    li:nth-child(#{$i}):after{
      opacity: 1; 
      transition-delay: ($transitionTime/1.5) * $i; 
    }
  } 
}
0

2Answer

返信ではコードブロックが使えないので、別の回答にします。

単純に、テキストも a タグに入れればよいのではないでしょうか?

  <ul>
    <li><a href="#firstPage" class="nav_btn">Top</a></li>
    <li><a href="#secondPage" class="nav_btn">Product</a></li>
    <li><a href="#3rdPage" class="nav_btn">Price</a></li>
    <li><a href="#4thpage" class="nav_btn">Contact</a></li>
  </ul>
.nav_btn {
  display: inline-block;
  width: 50px;
  height: 50px;
  text-decoration: none;
  color: white;
  visibility: hidden;
}

ul:hover .nav_btn {
  visibility: visible;
}

スタイルシートは適当に当てたので、細かい修正は必要かもしれませんが。

1

Comments

  1. @kakimoto5

    Questioner
    できました!
    ありがとうございます!

    visibility:
    勉強させて頂きました!

    ありがとうございます。

手元の環境で動かしたところ、ホバー後にズレているようには見えませんでした。
(多分、スタイルシートが足りていないのだと思いますが、文字がはみ出していたりしました)

もしかしたら a タグ、あるいは nav_btn クラスに指定しているスタイルシートの影響ということはないでしょうか?

0

Comments

  1. @kakimoto5

    Questioner
    なぬつ!
    class="nav_btn" は試行錯誤してる時につけてたものでして。
    何もしてない状態なら文字はずれないのですが、その丸の中にaタグのリンクを入れたいんです。
     aタグを入れると文字がずれてしまってどうしたものかと困っている状態です。
    丸の要素が50x50なのですが、リンクも50x50にしたいのです。
  2. @kakimoto5

    Questioner
    なんか説明不足ですいません。。。

Your answer might help someone💌