1
1

More than 3 years have passed since last update.

a Tip for HTML / liタグ内のaタグの領域が広がらない時の対応

Posted at

問題: liタグ内のaタグの領域が広がらない

image.png

<body style="margin: 2rem;">
    <ul style="position: relative; display: flex; text-align: center; justify-content: space-around; list-style: none;">
        <li style="flex: 1 1 30%;"><a style="background: chartreuse; width: 100%" href="#">a</a></li>
        <li style="flex: 1 1 30%;"><a style="background: chartreuse;  width: 100%" href="#">a</a></li>
    </ul>
</body>

対応: li に position:relative を追加、top: 0;left:0;width: 90%;height: 100%;display: block;をaに追加

<body style="margin: 2rem;">
        <ul style="position: relative; display: flex; text-align: center; justify-content: space-around; list-style: none;">
            <li style="flex: 1 1 30%;position: relative;"><a style="background: chartreuse; top: 0;left:0;width: 90%;height: 100%;display: block; " href="#">a</a></li>
            <li style="flex: 1 1 30%;position: relative;"><a style="background: chartreuse; top: 0;left:0;width: 90%;height: 100%;display: block;" href="#">a</a></li>
            <!--width:100%だと描画されない <li style="flex: 1 1 30%;position: relative;"><a style="background: chartreuse; top: 0;left:0;width: 100%;height: 100%;display: block;" href="#">a</a></li> -->
            <!--width:100%だと描画されない <li style="flex: 1 1 30%;position: relative;"><a style="background: chartreuse; top: 0;left:0;width: 100%;height: 100%;display: block;" href="#">a</a></li> -->

        </ul>
</body>

この時aタグのwidth:100%だと描画されないので、90%にしました。

image.png

これでliタグ内のaタグの領域が広がりました。
以上です。

1
1
0

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
1
1