css - 接口(interface) <Div>

标签 css html

这是我的代码:

<div id="divCategoryMenu" name="divCategoryMenu" style="background-color:#BCD2E6;">
  <ul id="ulCategoryMenu" name="ulCategoryMenu">

  </ul>
</div>

列表是动态填充的。但有一个问题:

当列表填充在此 Div 内时,当我在上面的代码以及我用来动态填充它的代码中没有使用任何对齐属性时,默认情况下元素是居中对齐的。如何对齐以使元素看起来像这样:

alt text http://www.freeimagehosting.net/uploads/b0f0daf6a2.jpg

目前它以脏形式显示,如下所示:

alt text http://www.freeimagehosting.net/uploads/901540953d.jpg

**** 已编辑 ****

就我而言,这些元素实际上是标签而不是

  • 。其次,要包含哪些 CSS 才能使其看起来像第一个图像。

    **** 进一步编辑 ****

    第一个图像的硬编码 HTML 的 CSS 代码如下所示:

    <style type="text/css">
    
    .urbangreymenu{
    width: 200px; /*width of menu*/
    }
    
    .urbangreymenu .headerbar{
    font: bold 12px Verdana;
    color: white;
    background:#006699 url(media/arrowstop.gif) no-repeat 8px 6px; /*last 2 values are the x and y coordinates of bullet image*/
    margin-bottom: 0; /*bottom spacing between header and rest of content*/
    text-transform: uppercase;
    padding: 7px 0 7px 31px; /*31px is left indentation of header text*/
    }
    
    .urbangreymenu ul{
    list-style-type: none;
    margin: 0;
    padding: 0;
    margin-bottom: 0; /*bottom spacing between each UL and rest of content*/
    }
    
    .urbangreymenu ul li{
    padding-bottom: 2px; /*bottom spacing between menu items*/
    }
    
    .urbangreymenu ul li a{
    font: normal 12px Arial;
    color: black;
    background: #E4F0F5;
    display: block;
    padding: 5px 0;
    line-height: 12px;
    padding-left: 8px; /*link text is indented 8px*/
    text-decoration: none;
    }
    
    .urbangreymenu ul li a:visited{
    color: black;
    }
    
    .urbangreymenu ul li a:hover{ /*hover state CSS*/
    color: white;
    background: black;
    }
    
    
    .style14 {font-family: Verdana, Arial, Helvetica, sans-serif}
    .style15 {font-family: Verdana, Arial, Helvetica, sans-serif; color: #006699; font-size: 11px;}
    </style>
    
  • 最佳答案

    就像 RegDwight 所说,这是关于边距/填充而不是对齐。您必须添加the following style items到您的 UL 元素,以及您列表中的实际 LI 元素。
    更新:实际上还需要做更多工作才能获得列表项之间的空白。请参阅下面的代码。

    由于 LI 元素是生成的并且不存在于您的初始 HTML 代码中,因此您必须在 CSS 中将它们的样式定义为 UL 元素的子项。

    更新:我必须对代码进行一些编辑,使其看起来与您的示例中完全相同。我已经粘贴了完整的新 HTML 和 CSS,现在应该没问题了。

    <html><head>
    <style type="text/css">
    .urbanbluemenu{
        width: 200px; /*width of menu*/
    }
    
    ul#ulCategoryMenu {
        background-color: white;
        margin: 0;
        padding: 0;
        list-style-type: none;
    }
    ul#ulCategoryMenu li {
        background-color: #BCD2E6;
        margin: 2px 0 2px 0;
        padding: 0 0 0 10px;
    }
    
    </style>
    </head>
    <body>
    
    <div class="urbanbluemenu" id="divCategoryMenu" name="divCategoryMenu">
      <ul id="ulCategoryMenu" name="ulCategoryMenu">
         <li><label>John</label></li>
         <li><label>Bill</label></li>
      </ul>
    </div>
    
    </body>
    </html>
    

    关于css - 接口(interface) <Div>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2101770/

    相关文章:

    html - CSS:如何向上绘制白色(主)框架?

    css - 将 html 选择添加到对话框导致不需要的 css 空白

    jquery - 从 iPhone 主屏幕重新打开时,如何在 jQuery Mobile 应用程序上缓存和保留上次访问的页面?

    jquery - 更改类中每个 html 选择元素的选定选项

    javascript - 按 Enter 键时从具有相同名称和 ID 的各种文本输入中选定的文本输入检索数据

    css - IE9边框颜色错误?

    html - 为什么 HTML 电子邮件的样式在 Outlook 中不断变化?

    html - 文本比最大宽度表列宽

    html - 以响应居中div位置

    html - 列之间的距离如何更小?BOOTSTRAP