[英]Map legend with CSS
How would you style a legend map with css only (no images)? 你如何用css设置一个传奇地图(没有图像)?
Do I use div element for little squares of color or a span element? 我是否将div元素用于小方块颜色或span元素?
Something like this: http://golondrinas.cornell.edu/Maps/Map%20legend.png 像这样: http : //golondrinas.cornell.edu/Maps/Map%20legend.png
I'd personally use a definition list: 我个人使用定义列表:
dt {
width: 40px;
height: 40px;
display: inline-block;
overflow: hidden;
border: 1px solid #000;
}
.aqua {background-color: aqua; color: aqua; }
.orange {background-color: #f90; color: #f90; }
.black {background-color: #000; color: #000; }
dd {
display: inline-block;
width: 15em;
margin: 0 0 0 1em;
}
<dl>
<dt class="aqua">Aqua</dt>
<dd>T. bicolor range</dd>
<dt class="black">Black</dt>
<dd>T. thalassina range</dd>
<dt class="orange">Orange</dt>
<dd>T. euchrysea range</dd>
</dl>
I'm not sure it's any more semantic than @Tor Valamo 's answer, but it feels like it makes more sense to me. 我不确定它是否比@Tor Valamo的答案更具语义性,但感觉它对我来说更有意义。
You can use whatever you want. 你可以使用你想要的任何东西。 There's no best practice for this rather rare example.
这个相当罕见的例子没有最佳实践。
The description "a coloured box" fits a div
best I think. 我认为描述“彩色盒子”最符合
div
。 span
would usually mean something inline, but could work as well, seeing as there is one per line, so to speak. span
通常意味着内联,但也可以工作,看到每行有一个,可以这么说。 You would have to make it inline-block
, which isn't supported in all browsers, or block
, but a div
is block by default, so no hassle with that. 您必须使其成为
inline-block
,这在所有浏览器中都不受支持或block
,但默认情况下div
是块,所以没有麻烦。 With a div
however you would need to possibly float
it, i'm not quite sure. 随着
div
但你需要可能float
它,我不太清楚。 With both you'd have to set the width
. 你必须设置
width
。
So to summarize, there's none that is better than the other, but div
would be more semantically correct, since span
should usually contain something that it "spans". 总而言之,没有一个比另一个更好,但
div
在语义上会更正确,因为span
通常应该包含“跨越”的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.