Javascript-форум (https://javascript.ru/forum/)
-   (X)HTML/CSS (https://javascript.ru/forum/xhtml-html-css/)
-   -   Вёрсточный кретинизм: Как растянуть <div> на весь родительский <td> ? (https://javascript.ru/forum/xhtml-html-css/37454-vjorstochnyjj-kretinizm-kak-rastyanut-div-na-ves-roditelskijj-td.html)

xintrea 20.04.2013 15:43

Вёрсточный кретинизм: Как растянуть <div> на весь родительский <td> ?
 
Есть примитивный код:

Код:

...
    <td width="5%" style="background-color: #AFBFF0">
      <a href="<? echo $backUrl ?>">
      <div style="margin: 0px; padding: 0px; height: 100%;">Взад</div>
      </a>
    </td>
...

Вопрос. Как вот этот вложенный <DIV> с надписью "Взад" растянуть на весь размер ячейки <TD>?

danik.js 20.04.2013 19:10

Во-первых лучше <a> засунуть внутрь <div>, во-вторых что растянуть - высоту или ширину? ли все вместе?
Чтоб сработало height:100% надо чтоб у родителя была задана высота.
<style>
    td{
        height: 100px;
    }
    div{
        background: red;
    }
</style>
<table>
    <tr>
    <td width="5%" style="background-color: #AFBFF0">
        <div style="margin: 0px; padding: 0px; height: 100%;"><a href="<? echo $backUrl ?>">Взад</a></div>
    </td>
    </tr>
</table>

Octane 20.04.2013 19:49

Цитата:

Сообщение от danik.js
Во-первых лучше <a> засунуть внутрь <div>

Смотря для чего верстка
http://www.w3.org/TR/html-markup/a.html#a
Цитата:

Сообщение от HTML: The Markup Language (an HTML language reference)
Changes in HTML5

Although previous versions of HTML restricted the a element to only containing phrasing content (essentially, what was in previous versions referred to as “inline” content), the a element is now transparent; that is, an instance of the a element is now allowed to also contain flow content (essentially, what was in previous versions referred to as “block” content)—if the parent element of that instance of the a element is an element that is allowed to contain flow content.

The following example is valid: A hyperlink that contains a paragraph.
<a href="javascript:void(0);"
  onmouseover="return anno('Note: This paragraph is informative only.')
  onmouseout="return anno_bye();">
<p>The following is introductory information…</p>
</a>


danik.js 20.04.2013 20:19

Octane, я вкурсе. Вот только если я не ошибаюсь, старые парсеры могут залупиться.

Deff 20.04.2013 20:51

<table>
    <tr>
    <td width="5%" style="height: 100px;position:relative;background-color:blue">
<a href="http://...">
        <div style="display:inline-block;margin: 0px; padding: 0px; height: 100%;width:100%;background-color:red">Взад</div>
</a>
    </td>
    </tr>
</table>


Часовой пояс GMT +3, время: 04:41.