css 等间距,可变宽度导航链接

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了css 等间距,可变宽度导航链接相关的知识,希望对你有一定的参考价值。

#nav {
  text-align: justify;
  min-width: 500px;
}

#nav:after {
  content: '';
  display: inline-block;
  width: 100%;
}

#nav li {
  display: inline-block;
}
(function($) {
	$.fn.justifyNav = function() {
		return this.each(function() {
			var $this = $(this),
				$children = $this.children(),
				containerWidth = $this.width(),
				linksWidth = 0,
				count = $children.length;
			$children.each(function() {
				linksWidth += $(this).outerWidth();
			});

			// Don't give the last item or the 2nd to last item any right margin, then float the last item right. 
			// This will account for small errors in JQuery's calculation of the item widths. 
			// Otherwise the list can overflow the container!
			var linkSpacing = Math.floor((containerWidth - linksWidth) / (count - 1));
			$children
				.css('margin-right', linkSpacing + "px")
				.filter(":last")
					.css({"margin-right":0,"float":"right"})
					.prev()
						.css({"margin-right":0});
		});
	};
})(jQuery);
ul {
  display: box;
}

li {
  box-flex: 1;
}
ul {
    display: table;
    width: 100%;
}

li {
    display: table-cell;
}

a {
    display: block;
}

以上是关于css 等间距,可变宽度导航链接的主要内容,如果未能解决你的问题,请参考以下文章

css水平导航间距

使用 CSS 表格显示的不均匀间距

css实现三列等宽等间距排列(九宫格)

css实现三列等宽等间距排列(九宫格)

css实现三列等宽等间距排列(九宫格)

Bootstrap 导航栏链接宽度意外扩展