ul居右的问题

用ul制作的横向列表在对齐方面很麻烦,靠ul本身的CSS属性没办法让其居右,只有再外面加一个div或是span才能用float做到.而外层的text-align对其也没有用.
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <style type="text/css">
  6. #header {
  7.     margin: 0;
  8.     vertical-align: bottom;
  9.     height: 20px;
  10.     line-height: 20px;
  11. }
  12. #header #span1 {
  13.     float: right;
  14. }
  15. #header ul {
  16.     margin: 0;
  17.     list-style-type: none;
  18.     height: auto;
  19.     width: auto;
  20. }

  21. #header li {
  22.     float: left;
  23.     text-align: center;
  24.     margin-left: 6px;
  25. }
  26. </style>
  27. </head>
  28. <body>
  29.     <div id="header">
  30.         <span id="span1">
  31.             <ul>
  32.                 <li>aaaaaa</li>
  33.                 <li>222222</li>
  34.                 <li>ffffff</li>
  35.                 <li>4f4f4d</li>
  36.             </ul>
  37.         </span>
  38.     </div>
  39. </body>
  40. </html>
div要设置行高,如果设成auto的话下面的内容会占用它的地方.
要想让ul居中只有让div居中.
一定要设置div的宽度,然后margin-left,margin-right都是auto.div就自动居中了.
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值