1

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

我想要这样的东西

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/

4

3 回答 3

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
}

这是上述更改的小提琴

于 2012-09-12T20:24:15.970 回答
0

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

基本上,不要用地毯轰炸所有东西,float而是只将其应用于偶数按钮,这将产生您描述的定位。要获得 (1 和 2) 和 (3 和 4) 之间的垂直空间,margin-top请在 #2 之后添加按钮。此外,所有按钮都必须是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; }

加上删除现有float属性 on.buttons .buttonStyling和 inline on div1

于 2012-09-12T20:33:06.847 回答
0

清理它并在 .buttons 跨度上设置最大宽度,试试这个:jsFiddle

于 2012-09-12T20:33:54.817 回答