javascript - 为li标签添加class并修改CSS样式,为什么会无效?

 mobiledu2502883785 发布于 2022-11-18 18:40

HTML写了一个普通的列表

                    

因为最后一个按钮多一个字的原因,要修改使最后一个按钮的padding有别于其他的padding,我的解决方法是给他们分别添加不同的class(请问有什么其他更好的解决方法吗?),3字的是.3t,4字的是.4t

 .major {
        padding-top: 30px;
    }

    .buttons {
        height: 350px;
        padding-top: 20px;
        /*display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;*/
    }

    .buttonsss {
        /*display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;*/
        margin-left: auto;
        margin-right: auto;
    }

    .buttonsss li {
        background-color: transparent;
        border: 1px #939393 solid;
        border-radius: 4px;
        font-size: 20px;
        color: #939393;
        width: 150px;
        height: 146px;
        line-height: 40px;
        text-align: center;
        list-style-type: none;
        text-decoration: none;
        cursor: pointer;
        margin-right: 30px;
        display: inline;
    }

    .buttonsss a:link {
        text-decoration: none;
        border-bottom-width: 0;
    }

    .buttonsss li:hover {
        color: #a8d970;
        cursor: pointer;
        border: 1px #a8d970 solid;
    }

    .container p {
        padding-bottom: 70px;
    }

    .4t {
        
        padding: 10px 10px;
    }

    .3t {
        padding: 10px 20px;
    }

但是....无效...没有padding效果
如果padding写在.buttonsss li里就没问题
请问是为什么?

7 个回答
  • ul 下面 怎么直接是 a 标签

    2022-11-18 19:46 回答
  • Class Name不能是数字开头啊,把3t和4t换个英文名就行了

    2022-11-18 19:46 回答
  • ...问题很多,建议先学好基本...
    可以去W3C学习下 http://www.w3school.com.cn/

    2022-11-18 19:46 回答
  • 各种毛病啊…

    2022-11-18 19:46 回答
  • 话说为什么把<li>嵌套在里面?

    2022-11-18 19:46 回答
  • 注意命名规范,不要用数字开头,以字母,$,_打头

    2022-11-18 19:46 回答
  • 是的我会告诉你css明明不能以数字开头吗?
    改成_3t _4t试试吧。

    2022-11-18 19:46 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有