• 浮动居中float:center


    今天看到了一种浮动居中方法,用float:center实现li是浮动的,并且是居中的(li个数不固定,ul宽度未知)。平时一般设置ul的text-align:center,再设置li的display,可以实现居中。

    下面说一下float:center实现浮动居中的思路,采用的是相对定位:ul为position:relative;left:50%,然后再让li像左浮动,在让它position:relative;right:50%(或者left:-50%),那么li就像向中间浮动一样居中了。

    ul,li{
        margin
    :0;
        padding
    :0;
        list-style
    :none;
    }
    #area
    {
        width
    :100%;
        height
    :80px;
        background-color
    :#eee;
        text-align
    :center;
        overflow
    :hidden;
    }
    #area ul
    {
        float
    :left;
        position
    :relative;
        left
    :50%;
    }
    #area ul li
    {
        float
    :left;
        margin
    :10px;
        padding
    :0 10px;
        position
    :relative;
        right
    :50%;
        line-height
    :60px;
        border
    :solid 1px #000;
    }

    效果:

    提示:可以先在文本框内,根据需要修改代码后再运行

  • 相关阅读:
    mysqllog
    清理:db上面的过期的binlog,释放磁盘空间。 (转)
    linux下shell命令trap
    mvc
    uci随笔
    luci 随笔
    shell脚本 整数比较
    lua学习
    OPENWRT make menuconfig错误之一
    openwrt 中make的使用
  • 原文地址:https://www.cnblogs.com/joe235/p/1291463.html
Copyright © 2020-2023  润新知