简体   繁体   English

垂直对齐/间距列表项

[英]Vertically aligning/spacing list items

Are you able to space a navigation list to have vertical spaces between certain <li> tags using CSS and not JavaScript & JQuery? 您是否可以使用CSS而不是JavaScript&JQuery在导航列表中的某些<li>标签之间设置垂直间距?

Example: http://jsfiddle.net/ssqnY/ 示例: http//jsfiddle.net/ssqnY/

It needs to be responsive with the height of the containing div or window height. 它需要响应包含div的高度或窗口高度。 The structure of the navigation list is below: 导航列表的结构如下:

<ul>
    <li><a href="#">Link</a></li>
    <li class="spacer"></li>
    <li><a href="#">Link</a></li>
    <li><a href="#">Link</a></li>
    <li class="spacer"></li>
    <li><a href="#">Link</a></li>
    <li><a href="#">Link</a></li>
</ul>

Check this: http://jsfiddle.net/ssqnY/1/ 检查此: http : //jsfiddle.net/ssqnY/1/

li.spacer {
  margin: 0 0 30% 0;
}

Works for responsive too. 也适用于响应式。

You can set vertical spacing to certain li 's using CSS this way: Set your desired li with a spacer class and then: 您可以通过以下方式使用CSS设置某些li的垂直间距:使用spacer类设置所需的li ,然后:

li.spacer {
  margin: 15% 0;
}

You can too, set the first li to have a space: 您也可以将第一个li设置为具有空格:

li:first {
  margin: 15% 0;
}

Or all the li 's to have space: 或所有li都有空间:

li {
  margin: 15% 0;
}

Ps: the 15% value is just an example, you can set what you want to it, you can use maybe a percentage, to become more responsive like 10px . Ps: 15%值只是一个例子,您可以设置所需的值,也可以使用一个百分比,以提高响应速度,例如10px

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM