6

1 行に 3 つのセルを含むテーブルに問題があります。これらのうちの 2 つ (左と右) は幅/高さが固定されており、画像を表示する必要があります (画像が存在しない場合は 0 に縮小します)。中央のセルは、テーブルの固定合計内の残りのスペースを取ります。

問題:「画像コンテナ」が(セルの下で)拡大しているように見える3pxの余分なスペースができてしまいます。たとえば、'starredunread' 要素を調べると、高さが 20px から 23px に大きくなります。また、マージン/パディングはデフォルトですでにオフになっており、border:0 と border-collapse: collapse が役に立たないため、何が起こっているのかわかりません。

CSSファイルは次のとおりです。

/*------------------------------------------

Reset (from the Yahoo UI Library)

------------------------------------------*/



body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td {margin:0;padding:0;}

table{border-collapse:collapse;}

fieldset,img{border:0;}

address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;}

ol,ul{list-style:none;}

caption,th{text-align:left;}

h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}

q:before,q:after{content:'';}

abbr,acronym{border:0}

a{outline: none;} 



/*------------------------------------------

Interface

------------------------------------------*/

body {

top: 0px;

left: 0px;

width: 320px;

height: 480px;

background-color: #f00;

color: #000;

font-family: helvetica, arial, sans-serif;

font-size: 12px;

}

.header {

display: table;

top: 0px;

left: 0px;

width: 320px;

height: 44px;

background-color: #738ba3;

color: #fff;

table-layout: fixed;

border: 0;

border-spacing: 0;

}

.headerrow {

display: table-row;

}


.text {

display: table-cell;

overflow: hidden;

text-overflow: ellipsis;

white-space: nowrap;

padding-left: 2px;

vertical-align: middle;

}

.text b {

font-weight: 700;

font-size: 11pt;

}

.date {

display: table-cell;

width: 50px;

vertical-align: middle;

text-align: right;

font-size: 8pt;

padding-top: 3px;

padding-right: 5px;

}

.date b {

font-weight: 700;

line-height: 11pt;

}


.starredunread {

display: table-cell;

top: 0px;

left: 0px;

width: 20px;

height: 44px;

vertical-align: middle;

}

.icon {

display: table-cell;

top: 0px;

right: 0px;

width: 44px;

height: 44px;

}


.content {

display: table;

width: 320px;

background-color: #fff;

color: #000;

font-size: 12pt;

text-align: left;

padding: 15px;

}

.sectionheader {

height: 20px;

}

.sectionheaderrow {

}

.sectionunread {

height: 20px;

}

.sectiontext {

font-weight: 700;

font-size: 9pt;

padding-top: 1px;

}

.smallicon {

width: 20px;

height: 20px;

}

HTMLコードは次のとおりです。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<meta http-equiv="Content-type" content="text/html; charset=utf-8" />

<title>testHTML</title>

<link rel="stylesheet" href="test.css" type="text/css" media="screen" />

</head>

<body>

<div class="header">

    <div class="headerrow">

        <div class="starredunread">
            <img src="images/testimg_small.png">
        </div><!-- end starredunread -->

        <div class="text">
                <b>Testheader</b><br>
                Text for testing - this should overflow with an ellipsis if the text exceeds the size of the container...
        </div><!-- end text -->

        <div class="date">
                <b>11.11.09</b><br>
                18:54
        </div><!-- end date -->

        <div class="icon">
            <img src="images/testimg_44x44.png">
        </div><!-- end icon -->

    </div><!-- end headerrow -->

</div> <!-- end header -->

<div class="content">
    More text for testing purposes.<br><br>Not really relevant.<br><br> So don't waste your time reading this. :o)
</div><!-- end content -->

<div class="header sectionheader">

    <div class="headerrow sectionheaderrow">

        <div class="starredunread sectionunread">
            <img src="images/testheader.png">
        </div><!-- end sectionunread -->

        <div class="text sectiontext">
            Another Header
        </div><!-- end sectiontext" -->

        <div class="icon smallicon">
            <img src="images/testimg_20x20.png">
        </div><!-- end smallicon -->

    </div><!-- end sectionheaderrow -->

</div><!-- end sectionheader -->

</body> 

</html>

...画像がないと見栄えがよくありませんが、とにかく私の問題を示しています。

私が間違っていることは何か分かりますか?ご意見をお寄せいただきありがとうございます。コードは Safari / Webkit でのみ機能する必要があります。

4

2 に答える 2

10

strict モードでは、イメージはデフォルトでインラインです。strict を使用しているdisplay:blockため、イメージに適用して手動で修正する必要があります。

「初期の厳密モードでの実験では、画像が突然、削除できない奇妙な下マージンを取得したというコメントが常に発生しました。原因は、厳密モードではインライン要素であるため、一部のスペースを予約する必要があることを意味します。 g、j、q などの可能なディセンダー文字もちろん、画像にはディセンダー文字がないため、スペースは使用されませんでしたが、それでも予約する必要がありました。

解決策は、画像ブロック レベル要素を明示的に宣言することでした: img {display: block}."

http://www.quirksmode.org/css/quirksmode.html

于 2009-11-11T18:33:25.000 に答える
0

同様の問題がありました。一般に、次のマークアップを使用して、すべての css 要素のマージンとパディングを禁止する必要があります (できれば、スタイル シートの先頭に): * { margins: 0; パディング: 0; }

先頭の「*」は重要です。これにより、数時間のフラストレーションが解消されます。その後、テキスト セルがある場合、上部に半分の em の余白があるように見えるかもしれませんが、これはほとんどのテキスト文字が em よりも短いためです。

于 2010-11-13T10:21:51.063 に答える