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;
    }

    效果:

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

  • 相关阅读:
    OE_ORDER_PUB.PROCESS_ORDER to Apply hold on a sales order
    父母
    更新价目表价格
    Netbeans6.8 主题美化及去掉红线
    IIS宿主wcf时的错误解决
    ubuntu安装deb,rpm安装包方法
    高效程序员的45个习惯
    数据库无法保存中文的解决
    1366*768 play game full screen
    项目管理部分随笔索引
  • 原文地址:https://www.cnblogs.com/joe235/p/1291463.html
Copyright © 2011-2022 走看看