Arial Swploit 2020-04-17 07:49 采纳率: 87.5%
浏览 846
已采纳

Html+CSS中设置class left中的a标签text-align:center无效,什么原因?

<!DOCTYPE html>
<html style="background-image: url(./img/bg.png);">
    <head>
        <meta charset="utf-8" />
        <title>This is my first</title>
        <style>
            * {
                margin: 0;
                font-family: "微软雅黑";
                transition:0.5s;
                -webkit-font-smoothing: antialiased;
            }
            .header {
                width: 100%;
                height: 70px;
                background-color: white;
                position: fixed;
                top: 0;
                box-shadow:3px 1px 2px darkgrey;
            }
            .header:hover {
                box-shadow:3px 1px 2px #000;
            }
            .header a {
                line-height: 70px;
                margin: 85px;
                color: black;
                text-decoration: none;
                padding: 15px;
                font-size: 16px;
                text-shadow: 0 1px 1px #fff;
            }
            .header a:hover {
                background-color: black;
                color: white;
            }
            .left {
                width: 5px;
                height: 700px;
                background-color: white;
                position: fixed;
                left: 0;
                overflow: auto;
            }
            .left:hover {
                width: 200px;
                box-shadow:3px 1px 2px darkgrey;
            }
            .left a {
                text-align: center;
            }
            .main_left {
                margin: 80px;
                background-color: white;
                width: 70%;
                height: 700px;
                border-top: aqua;
            }
            .main_right {
                margin: 50px;
                background-color: white;
            }
        </style>
    </head>
    <body>
        <div class="header">
            <a href="#">点击链接</a>
            <a href="#">点击链接</a>
            <a href="#">点击链接</a>
            <a href="#">点击链接</a>
            <a href="#">点击链接</a>
        </div>
        <div class="left">
            <a> Hello </a>
        </div>
        <div class="main_left">

        </div>
    </body>
</html>

之前试过了margin:auto;
也试过
display:inline-block;
text-align: center;
都无效,有没有解决办法?

  • 写回答

2条回答 默认 最新

  • 哇,女前端哎! 2020-04-17 09:21
    关注

    如果想要上下居中,在.left添加:

    line-height: 700px;
    

    如果想要左右居中,在.left添加:

    text-align: center;
    

    如果想要上下左右居中:在.left添加:

    text-align: center;
    line-height: 700px;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 matlab实现基于主成分变换的图像融合。
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊