Выровнять 3 деления горизонтально по центру и связать?

Я провел несколько часов с этим, и я думаю, что это гораздо проще сделать.. Я пытаюсь центрировать 3 деления по горизонтали, сохраняя их полностью связанными, и я наконец отказался от этого и попробовал таблицы (:-o)

Первый показывает мою неудачную попытку связать div.

 <center><table>
    <tr>

    <td>
    <a href="http://google.com" style="display:block;height:100%;width:100%">
    <div>
    a
    </div>
    </a>
    </td>
    <td>b</td>
    <td>c</td>
    </tr>
    </table>

С CSS

tbody tr td{
width: 300px;
height: 200px;
border: 2px solid #000;
background-color: #000;
opacity: 0.7;
color: #fff;
font-size: 30px;
font-family: 'calibri'; //temporary
padding: 30px;
}
body center table
{
border-spacing: 20px;
margin-top: -90px;
}
tr td a{
height:150%;
width:150%;
}

Если кто-нибудь знает, как сделать это с помощью div или таблиц, ваши ответы будут очень благодарны!

Спасибо!

3 ответа

Решение

Не нужно использовать tableS на всех. Ключ здесь display: inline-block;, Смотрите это в действии здесь: маленькая ссылка. HTML:

<div class = "onediv"><a href = "#">Glee is awesome!</a></div>
<div class = "onediv"><a href = "#">Glee is awesome!</a></div>
<div class = "onediv"><a href = "#">Glee is awesome!</a></div>​

CSS:

body { /*this should be whatever is containing your three divs*/
    text-align: center; /*center them*/
    white-space: nowrap; /*make sure they're all on the same line*/
}
.onediv {
    display: inline-block; /*magic*/
    height: 200px; /*or whatever you want*/
    width: 150px;
    /*make it look pretty*/
    background: rgb(0, 162, 232);
    color: white;
}
a {
    color: white;
    height: 100%; /*spans the whole div vertically*/
    width: 100%; /*and horizontally (not necessary, but can't hurt!)*/
    display: block; /*otherwise the height and width definitions won't work*/
}​

Вы имеете в виду что-то подобное?

демонстрация

HTML:

<div id="wrapper">
<div><a href="#">a</a></div>
<div><a href="#">b</a></div>
<div><a href="#">c</a></div>
</div>

CSS:

#wrapper, #wrapper * {
    -webkit-box-sizing:border-box;
    -moz-box-sizing:border-box;
    box-sizing:border-box;
}
#wrapper {
    margin:0 auto;
    width:1020px; /* width of divs + margin */
}
#wrapper > div {
    float:left;
    width:300px;
    height: 200px;
    text-align:center;
    margin:20px;
    border: 2px solid #000;
    line-height:140px; /* optional, will center the text vertically */
    background-color: #000;
    opacity: 0.7;
    font-size: 30px;
    font-family: 'calibri';
    padding: 30px;
}
#wrapper > div a {
    display:block;
    color: #fff;
}

Изменить: обновлено с вашим стилем

<td>
<a href="http://google.com" style="display:block;height:100%;width:100%">
<div>
a
</div>
</a>
</td>

Вы делаете все tds div подкладка.

Другие вопросы по тегам