如何使用html5在水平线上获取Legend

时间:2014-03-17 18:03:39

标签: javascript html css html5

这是我的传说的代码,但这些传说是垂直的,但我希望它在水平线上,例如:传说颜色,按照标题。

html代码:

<div class='my-legend'>
<div class='legend-scale'>
  <ul class='legend-labels'>

    <li><span style='background:#BEBADA;'>Three</span></li>
    <li></li>
    <li><span style='background:#FB8072;'></span></li>
    <li>Four</li>
    <li><span style='background:#80B1D3;'></span></li>
    <li>Five</li>
  </ul>
</div>
</div>

Css代码:

.my-legend .legend-title {
    text-align: left;
    margin-bottom: 5px;
    font-weight: bold;
    font-size: 90%;
    }
  .my-legend .legend-scale ul {
    margin: 0;
    margin-bottom: 5px;
    padding: 0;
    float: left;
    list-style: none;
    }
  .my-legend .legend-scale ul li {
    display: inline;
    font-size: 80%;
    list-style: none;
    margin-left: 0;
    line-height: 18px;
    margin-bottom: 2px;
    }
  .my-legend ul.legend-labels li span {
    display: block;
    float: left;
    height: 16px;
    width: 20px;
    margin-right: 5px;
    margin-left: 0;
    border: 1px solid #999;
    }

  .my-legend a {
    color: #777;
    }

这是我的css代码,我给出了传说的对齐方式。非常感谢。

my Demo

2 个答案:

答案 0 :(得分:1)

this您要找的是什么?

HTML:

<li><span style='background:#BEBADA;'></span></li>
<li>Three</li>
<li><span style='background:#FB8072;'></span></li>
<li>Four</li>
<li><span style='background:#80B1D3;'></span></li>
<li>Five</li>

的CSS:

.my-legend .legend-scale ul li {
  display: inline-block;
  font-size: 80%;
  list-style: none;
  line-height: 18px;
  vertical-align: text-top;
}
.my-legend ul.legend-labels li span {
  display: inline-block;
  height: 16px;
  width: 20px;
  margin-right: 5px;
  margin-left: 10px;
  border: 1px solid #999;
}

答案 1 :(得分:1)

工作小提琴:http://jsfiddle.net/jw2Sd/20/

<div class='my-legend'>
<div class='legend-scale'>
  <ul class='legend-labels'>
    <li>
        <span class="color" style='background:#BEBADA;'></span>
        <span class="legend">Three</span>
        <span class="color" style='background:#FB8072;'></span>
        <span class="legend">Four</span>
        <span class="color" style='background:#80B1D3;'></span>
        <span class="legend">Five</span>
    </li>
  </ul>
</div>
</div>

    .my-legend .legend-title {
    text-align: left;
    margin-bottom: 5px;
    font-weight: bold;
    font-size: 90%;
    }
  .my-legend .legend-scale ul {
    margin: 0;
    margin-bottom: 5px;
    padding: 0;
    float: left;
    list-style: none;
    }
  .my-legend .legend-scale ul li {
    display:inline;
    font-size: 80%;
    list-style: none;
    margin-left: 0;
    line-height: 18px;
    margin-bottom: 2px;
    }
  .my-legend ul.legend-labels li .color {
    display: block;
    float: left;
    height: 16px;
    width: 20px;
    margin-right: 5px;
    margin-left: 0;
    border: 1px solid #999;
    }
   .my-legend ul.legend-labels li  .legend {
    display: block;
    float: left;
    height: 16px;
    width: 40px;
    margin-right: 5px;
    margin-left: 0;
    }

  .my-legend a {
    color: #777;
    }

刚刚更改了CSS的HTML和位