zoukankan      html  css  js  c++  java
  • 浮动居中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;
    }

    效果:

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

  • 相关阅读:
    性能测试常用业务模型分析
    性能常见模式
    C# 2第一个程序
    C# 1安装编译器
    eclipse安装maven错误总结
    Idea创建Maven项目
    Idea导入Eclipse项目
    软件需求与分析
    软件构造:完善口算题卡
    软件需求与分析
  • 原文地址:https://www.cnblogs.com/joe235/p/1291463.html
Copyright © 2011-2022 走看看