1

这是我的代码:

<head>
  <style type="text/css">
    #cssmenu > ul li {
        background-color: #F4F4F4;
        display: block;
        position: relative;
        text-decoration:none;
    }
    #cssmenu > ul li a {
      background-color: #F4F4F4;
      display: block;
      position: relative;
      margin: 0;
      border-bottom: 1px dotted #d9d9d9;
      border-left: 1px dotted #D9D9D9;
      border-right: 1px dotted #D9D9D9;
      padding: 15px 10px;
      width: 150px;
      font-size: 11px;
      text-decoration:none;
      color:#7C7C7C;
   }
    #cssmenu > ul li a:hover {
        background-color:#4285F4;
        color:white;
    }
    #header_content {
        height:25px;
        width:60%;
        color:White;
        background-color:#083061;
        margin-left:320px;
    }
  </style>
</head>

<body>
  <div style="width:100%">
    <div id='cssmenu' style="width:10%;margin-top:1px;">
      <ul style="margin-top:0px;margin-left:30px;">
        <li><a href='#'><span>DASHBOARD</span></a></li>
        <li><a href='#'><span>RESOURCES</span></a></li>
        <li><a href='#'><span>CALL ROUTING</span></a></li>
        <li><a href='#'><span>RECORDINGS & CALL LOGS</span></a></li>
      </ul>
    </div>
  <div id="header_content">
    <label>Dashboard</label>
  </div>
</body>

我想水平修复这两个div?

4

3 回答 3

3

如果要div水平对齐两个或多个 s,可以使用display其 css 样式的属性:

div#foo {
    display: inline-block;
}
div#bar {
    display: inline-block;
}

小提琴:这里

于 2013-09-14T05:30:21.210 回答
1

对 div id="cssmenu" 使用 float:left 样式

<style type="text/css">
#cssmenu > ul li {
    background-color: #F4F4F4;
    display: block;
    position: relative;
    text-decoration:none;
}
#cssmenu > ul li a {
    background-color: #F4F4F4;
    display: block;
    position: relative;
    margin: 0;
    border-bottom: 1px dotted #d9d9d9;
    border-left: 1px dotted #D9D9D9;
    border-right: 1px dotted #D9D9D9;
    padding: 15px 10px;
    width: 150px;
    font-size: 11px;
    float:left;
    text-decoration:none;
    color:#7C7C7C;
}
#cssmenu > ul li a:hover {
    background-color:#4285F4;
    color:white;
}
#header_content{
    height:25px;
    width:60%;
    color:White;
    background-color:#083061;
    margin-left:320px;
}
</style></head>
<body>
    <div style="width:100%">
        <div id='cssmenu' style="width:10%;margin-top:1px;">
            <ul style="margin-top:0px;margin-left:30px;">
                <li><a href='#'><span>DASHBOARD</span></a></li>
                <li><a href='#'><span>RESOURCES</span></a></li>
                <li><a href='#'><span>CALL ROUTING</span></a></li>
                <li><a href='#'><span>RECORDINGS & CALL LOGS</span></a></li>
            </ul>
        </div>
        <div id="header_content">
            <label>Dashboard</label>
        </div>
    </div>
</body>
于 2013-09-14T05:25:14.453 回答
0

这里的 CSS 是jsfiddle

    #cssmenu{
    margin-top:1px;
    display:inline-block;
} 
#cssmenu > ul li {
    background-color: #F4F4F4;
    display: block;
    position: relative;
    text-decoration:none;}
#cssmenu > ul li a {
    background-color: #F4F4F4;
    display: block;
    position: relative;
    margin: 0; 
    border-bottom: 1px dotted #d9d9d9;
    border-left: 1px dotted #D9D9D9;
    border-right: 1px dotted #D9D9D9;
    padding: 15px 10px;
    width: 150px;font-size: 11px;
    text-decoration:none;color:#7C7C7C;
}
#cssmenu > ul li a:hover {
    background-color:#4285F4;
    color:white;}
#header_content{
    height:25px;
    width:60%;
    color:White;
    background-color:#083061;
    display:inline-block;
    vertical-align:top;
}

HTML

<div style="width:100%">
    <div id="cssmenu">
    <ul style="margin-top:0px;">
    <li><a href='#'><span>DASHBOARD</span></a></li>
    <li><a href='#'><span>RESOURCES</span></a></li>
    <li><a href='#'><span>CALL ROUTING</span></a></li>
    <li><a href='#'><span>RECORDINGS & CALL LOGS</span></a></li>
    </ul>
    </div>
    <div id="header_content">
    <label>Dashboard</label>
    </div>
于 2013-09-14T05:29:47.470 回答