【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集

.line {
background-image: url(../img/line.gif);
background-repeat: no-repeat;
background-position: left bottom;
display: block;
padding: 0px;
clear: both;
width: 600px;
height:auto;
margin: 0px; }

.left{
width:210px;
height:90px;
float:left;
text-align:center;
padding:10px 5px 10px 0px;}

.right{
width:360px;
height:90px;
float:left;
padding:10px;}

<div class="line">
<div class="left">あああ</div>
<div class="right">いいい</div>
</div>

上記のようにlineでleftとrightを内包したいのですが、IEでは表示されるのですが、fox・safariで確認すると画像が消えてしまいます。

どうもdivで括っているせいかline内に文字が入っていないと認識されているようで、ためしに適当な数字を入れてやると認識されました。

また、lineのheightをpx指定してやると表示されるのですが、lineは使いまわしたいクラスなので、縦を固定することができません。

どうしたら解決しますか?

A 回答 (3件)

ここで言うclearとは、.lineの中に入っている.leftと.rightがclearされていないということです。


.rightの次の要素、または.lineの次の要素に指定しないとclearされません。


<div class="line">
<div class="left">あああ</div>
<div class="right">いいい</div>
<div style="clear:both;">おおおお</div> ←この位置です
</div>
<div style="clear:both;">おおおお</div> ←または、この位置です
    • good
    • 0
この回答へのお礼

ありがとうございました。
この位置でクリアを指定したら無事表示されました。

お礼日時:2009/02/03 05:10

私はこのようなトラブルを避けるため、floatは極力使わないのです。

[relative]+[absolute]+[min-height]をつかう。

 floatで行うと<hr>をつかってclearし、hr自体はvisibilityで隠す。(IEはhrのマージンを消せないバグがある)

★下記は境界が分かるようにポーター,背景が指定してある。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="ja">
<head>
<meta http-equiv="content-type" content="text/html; charset=Shift_JIS">
<title>配置</title>
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css">
<!--
body>div.Body{
background: url(../img/line.gif) no-repeat left bottom;
padding: 0px;width: 600px;height:auto;margin: 0px;
border: 1px solid red;/* position:relative;*/
background-color: rgb(200,200,255);
}
div.Note{
height:90px;margin:0px;
}
div.Head{
float:left;
width:210px;
text-align:center;padding:10px 5px 10px 0px;
background-color: rgb(255,200,200);
}
div.Foot{
float:right;
width:360px;padding:10px;
background-color: rgb(200,255,200);
}
hr{clear:both;height:0px;margin:0px;visibility:hidden;}
-->
</style>
</head>
<body>
<h1>配置</h1>
<h2>ブロックの長さ</h2>
<div class="Body Text">
<div class="Head Note">頭注</div>
<div class="Foot Note">脚注</div>
<hr>
</div>
</body>
</html>
    • good
    • 0

floatをclearしていないからではないでしょうか。

この回答への補足

lineにclear: both;ではダメでしょうか?


<div class="line">
 <div class="left">あああ</div>
 <div class="right">いいい</div>
</div>
<br class="clear">

試しに上記をやってみましたが、変わりませんでした。
ちなみにやりたいのは、上記が繰り返されるデザインです。

<div class="line">
 <div class="left">あああ</div>
 <div class="right">いいい</div>
</div>
<div class="line">
 <div class="left">ううう</div>
 <div class="right">えええ</div>
</div>

このような感じです。

補足日時:2009/01/17 08:56
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!


おすすめ情報