これ何て呼びますか

下記CSSでキャプション付き画像を横向きに並べて配置したのですが
横に並んだ画像の固まりをセンターにもっていくCSSがわかりません
どなたか知りませんか?

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />


<style type="text/css">
<!--

div.imagebox {
border: 1px dashed #0000cc; /* 1.枠線 */
background-color: #eeeeff; /* 2.背景色 */
}
p.image, p.caption {
text-align: center; /* 3.中央寄せ */
margin: 0px; /* 4.余白・間隔 */
}
p.caption {
font-size: 80%; /* 5.文字サイズ */
color: darkblue; /* 6.文字色 */
}
div.imagebox {
border: 1px dashed #0000cc; /* 枠線 */
background-color: #eeeeff; /* 背景色 */
width: 140px; /* 横幅 */
float: left; /* 左に配置 */
margin: 5px; /* 周囲の余白 */

}

.imagebox_a {
display: block;
margin-left: auto;
margin-right: auto;

}


-->
</style>


</head>
<body>

<div class="imagebox_a">
<div class="imagebox">
<p class="image"><img src="./photo.jpg" width="140" height="95" alt="海の写真"></p>
<p class="caption">キャプションですよ</p>
</div>
<div class="imagebox">
<p class="image"><img src="./photo.jpg" width="140" height="95" alt="海の写真"></p>
<p class="caption">キャプションですよ</p>
</div>
<div class="imagebox">
<p class="image"><img src="./photo.jpg" width="140" height="95" alt="海の写真"></p>
<p class="caption">キャプションですよ</p>
</div>
<div class="imagebox">
<p class="image"><img src="./photo.jpg" width="140" height="95" alt="海の写真"></p>
<p class="caption">キャプションですよ</p>
</div>
</div>

</body>
</html>

「横に並んだ画像の固まりをセンター」の質問画像

A 回答 (2件)

クラス「.imagebox_a 」に横幅指定がないので


width:●●px;というのを追加すれば真ん中に寄ります


(例)

.imagebox_a {
width:800px;
display: block;
margin-left: auto;
margin-right: auto;

}


.imagebox_aが適用されている<div>はブロックレベル要素なので
横何pxなのか指定がなければ自動的に
右端~左端一杯にその枠が設置されてしまいますので。
800pxというのは適当に入れたので適宜変えて下さい。
    • good
    • 0

もっと簡潔に書かなきゃメンテナンスに困りますよ。

class名は文書構造を示す物にしておくと、先で他のデザイン・・ボックスじゃなくリスト・・・にしたいときなど混乱しなくてすむ。
★darkblueは値として使えません。
 aqua、black、blue、fuchsia、gray、green、lime、maroon、navy、olive、orange、purple、red、silver、teal、white、yellow( http://momdo.s35.xrea.com/web-html-test/spec/CSS … )の17色です。
★タブは_に置換してあるので戻す。

<div class="photoAlbum">
_<div class="figure">
__<img src="./photo.jpg" width="140" height="95" alt="海の写真">
__<div class="figcaption">キャプションですよ</div>
_</div>
_<div class="figure">
__<img src="./photo.jpg" width="140" height="95" alt="海の写真">
__<div class="figcaption">キャプションですよ</div>
_</div>
_<div class="figure">
__<img src="./photo.jpg" width="140" height="95" alt="海の写真">
__<div class="figcaption">キャプションですよ</div>
_</div>
_<div class="figure">
__<img src="./photo.jpg" width="140" height="95" alt="海の写真">
__<div class="figcaption">キャプションですよ</div>
_</div>
_<div class="figure">
__<img src="./photo.jpg" width="140" height="95" alt="海の写真">
__<div class="figcaption">キャプションですよ</div>
_</div>
</div>
div.photoAlbum{
width:486px;margin:0 auto;
fontt-size:0.8em;
color:navy;
text-align:center;
background-color:yellow;
}
div.photoAlbum div.figure{/* アルバム中の挿絵 */
width:140px;height:140px;
margin:5px;padding:5px;
border:navy 1px dashed;
float:left;
background-color:rgb(238,238,255);
}
div.photoAlbum div.figure div.figcaption{/* 挿絵のキャプション */
text-indent:1em;text-align:left;
}
div.photoAlbum:after{
content:"";
display:block;
clear:left;
}

[HTML5]の場合。
<div class="photoAlbum">
_<figure>
__<img src="./photo.jpg" width="140" height="95" alt="海の写真">
__<figcaption>キャプションですよ</figcaption>
_</figure>
_<figure>
__<img src="./photo.jpg" width="140" height="95" alt="海の写真">
__<figcaption>キャプションですよ</figcaption>
_</figure>
_<figure>
__<img src="./photo.jpg" width="140" height="95" alt="海の写真">
__<figcaption>キャプションですよ</figcaption>
_</figure>
_<figure>
__<img src="./photo.jpg" width="140" height="95" alt="海の写真">
__<figcaption>キャプションですよ</figcaption>
_</figure>
_<figure>
__<img src="./photo.jpg" width="140" height="95" alt="海の写真">
__<figcaption>キャプションですよ</figcaption>
_</figure>
</div>
div.photoAlbum{
width:486px;margin:0 auto;
fontt-size:0.8em;
color:navy;
text-align:center;
background-color:yellow;
}
div.photoAlbum figure{
width:140px;height:140px;
margin:5px;padding:5px;
border:navy 1px dashed;
float:left;
background-color:rgb(238,238,255);
}
div.photoAlbum figure figcaption{
text-indent:1em;text-align:left;
}
div.photoAlbum:after{
content:"";
display:block;
clear:left;
}
    • good
    • 0

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