2012-09-12 28 views
1

我遇到了问题,我只想在图像旁边的蓝色div中间显示2个链接按钮。aligning div中的按钮

我想是这样的

link1 {space} link2 
{space} 
link3 {space} link 4 

目前就是这个样子

link1 
link2 
link3 
link4 

这里是我的代码 HTML

<div class="list-wrapper"> 
<div class="my-background"> 
    <div class="div1" style="float:left;"> </div> 

     <span class="buttons"> 
     <a class="buttonStyling" href="test.com"><b>Link 1</b></a> 
     <a class="buttonStyling" href="test.com"><b>Link 2</b> </a> 
     <a class="buttonStyling" href="test.com"><b>Link 3</b> </a> 
     <a class="buttonStyling" href="test.com"><b>Link 4</b> </a> 
     </span> 
</div>​ 

CSS

.my-background{ 
    background-color: #8af0fc; 
    height: 204px; 
} 
.div1 { 
    height: 205px; 
    background: url(http://www.dynamicdrive.com/dynamicindex4/lightbox2/horses.jpg) no-repeat; 
    background-size: 435px; 
    font-weight: normal; 
    font-family: futura, arial, sans-serif; 
    text-align: center; 
    width:256px; 
    margin-bottom: -20%; 
} 
.buttons .buttonStyling{ 

    display: block; 
    height: 40px; 
    text-align: center; 
    line-height: 40px; 
    width: 35%; 
    float:right; 

} 

.buttonStyling { 

    background: rgb(255, 255, 255); /* Old browsers */ 
    background: -moz-linear-gradient(top, rgba(255, 255, 255, 1) 33%, rgba(225, 225, 225, 1) 100%); 
    background: -webkit-gradient(linear, left top, left bottom, color-stop(33%, rgba(255, 255, 255, 1)), color-stop(100%, rgba(225, 225, 225, 1))); 
    background: -webkit-linear-gradient(top, rgba(255, 255, 255, 1) 33%, rgba(225, 225, 225, 1) 100%); 
    background: linear-gradient(top, rgba(255, 255, 255, 1) 33%, rgba(225, 225, 225, 1) 100%);  color: #333; 
} 

这里的jsfiddle

http://jsfiddle.net/cUWn8/4/

+0

你想在四个角上的按钮?你想让它们之间的特定间距居中在div区中间吗? –

+0

你对div1的计划是什么?现在它只是创建一个毫无意义的边际,是否应该包含按钮?你有足够的额外样式,不清楚你的实际意图是什么。 –

+0

我仍然困惑于你想要的东西,左边的图像,右边的蓝色方块和蓝色的2个图像,图像上有2个按钮?对于你想要最终的布局做一些更具体的描述 –

回答

2
  1. 摆脱彩车
  2. 添加显示:inline-block的
  3. 添加利润率为您需要

使用此间距css

.buttons .buttonStyling{ 

    display: inline-block; 
    height: 40px; 
    text-align: center; 
    line-height: 40px; 
    width: 35%; 
    margin: 0 50px 50px 0; //or however much space you want 
} 

这里的fiddle上述变化

0

试试这个:http://jsfiddle.net/cUWn8/5/

基本上,没有地毯炸弹一切与float,而仅将它应用到甚至按钮,将产生定位你描述。要获得(1和2)和(3和4)之间的垂直空间,请在#2后面添加margin-top到按钮。此外,所有按钮都需要为display: inline-block

的关键CSS变化是:

.buttons .buttonStyling { display: inline-block; } 
.buttonStyling:nth-of-type(even) { float: right; } 
.buttonStyling:nth-of-type(2) ~ .buttonStyling{ margin-top: 50px; } 

加上取消对div1.buttons .buttonStyling和内嵌现有float财产。您.buttons