简体   繁体   English

我需要一种方法来填充链接左侧和右侧的空白区域

[英]I need a way to fill up empty spaces on the left and right of links

I need to auto fill spaces next to menu links. 我需要自动填充菜单链接旁边的空间。 I have a unknown number of links that make up a menu bar. 我的菜单栏链接数量未知。

I need a way to fill in the empty space next to the links in a way that it looks exactly like the link. 我需要一种看起来与链接完全一样的方式来填充链接旁边的空白区域。

If you have a look at my fiddle you will see there are green and black links classed: a.menu(green) and a.menu_filler(black). 如果您看一下我的小提琴,您会看到有绿色和黑色链接分类:a.menu(绿色)和a.menu_filler(黑色)。 I set them Green and Black to make it obvious which links I am talking about in the end they will have the same background. 我将它们设置为“绿色”和“黑色”以使其清晰可见,最后我要谈论的链接将具有相同的背景。

I need the a.menu_filler(black) links to self adjust to 100% of the remaining width of the navbar div called div.navbar (silver). 我需要a.menu_filler(black)链接进行自我调整,以适应称为div.navbar(银)的导航条div的剩余宽度的100%。

http://jsfiddle.net/RFZees/Gt4SG/6/ http://jsfiddle.net/RFZees/Gt4SG/6/

I hope my explanation is understandable. 我希望我的解释是可以理解的。

HTML: HTML:

<div class='navbar'> 
 <a class='menu_filler'></a>
 <a class='menu' href='#'>LINK</a>
 <a class='menu' href='#'>BIGGER LINK</a>
 <a class='menu' href='#'>BIGGEST LINK</a>
 <a class='menu_filler'></a>
</div>

CSS: CSS:

div.navbar {
    background:silver;
    height:50px;
    width:600px;
    margin:auto;
    text-align: center;
}
a.menu_filler {
    background:black;
    height:30px;
    width:auto;
    padding:10px;
    margin:5px;
}
a.menu {
    background:green;
    height:30px;
    padding:10px;
    margin:5px;
    color:blue;
}
a.menu:hover {
    background:blue;
    color:green;
}

You can use display: table; 您可以使用display: table; and border-spacing: 10px; border-spacing: 10px; in .navbar, and then declare every <a/> element as display:table-cell; 在.navbar中,然后将每个<a/>元素声明为display:table-cell; ;。 .

This way the fillers will be automatically calculated, the space between divs will be auto-adjusted, and they will be transparent. 这样,填充物将被自动计算,div之间的间距将被自动调整,并且它们将是透明的。

Code

div.navbar {
    /* all your stuff */
    display: table;
    border-spacing: 10px;
}

div.navbar > a{
  display: table-cell;  
}

DEMO: http://jsfiddle.net/nWzqc/ 演示: http : //jsfiddle.net/nWzqc/

Add display: table-cell; 添加display: table-cell; to a and remove height from div.navbar . a并从div.navbar删除高度。

Demo 演示

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

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