简体   繁体   English

设置首页图像布局的样式-目标div还是img?

[英]Styling a home page image layout - target div or img?

I am styling a homepage using image content only, no text. 我仅使用图像内容而不是文本来设置主页样式。

When I am styling the image layout, should this be done in the div class only (eg. ceiling> or do I need to style each img class (.ceiling > a > img) 当我设置图像布局的样式时,应该仅在div类中完成此操作(例如,ceiling>还是我需要为每个img类设置样式(.ceiling> a> img)

Just consicious I am going to deep with the styling here, when it could just be set in the top level div. 只是有意识的,我将深入探讨这里的样式,何时可以将其设置在顶级div中。

http://jsfiddle.net/515r0zw4/ http://jsfiddle.net/515r0zw4/

<div class="category4block">
<div class="ceiling"><a href="http://example.com/ceiling"><img  src="http://example.com/image/data/Home Page /Ceiling.jpg" /></a></div>
<div class="wall"><a href="http://example.com/wall"><img  src="http://example.com/image/data/Home Page /Wall.jpg" /></a></div>
<div class="island"><a href="http://example.com/island"><img  src="http://example.com/image/data/Home Page /Island.jpg" /></a></div>
<div class="downwall"><a href="http://example.com/downwall"><img   src="http://example.com/image/data/Home Page /Downwall.jpg" /></a></div>
</div>

.category4block {
width: 100%;
margin-left: -10px;
clear:both;
}

.ceiling {
float: left;
width: 23%;
margin-left: 5px;
margin-bottom: 20px;
}

.ceiling > a > img {
border-style: solid;
border-width: 10px;
max-height: 240px;
max-width: 100%;
width: 100%;
}

.wall {
float: left;
width: 23%;
margin-left: 22px;
margin-bottom: 20px;
}

.wall > a > img{
border-style: solid;
border-width: 10px;
max-height: 240px;
max-width: 100%;
width: 100%;
}

.island {
float: left;
width: 23%;
margin-left: 22px;
margin-bottom: 20px;
}

.island > a > img{
border-style: solid;
border-width: 10px;
max-height: 240px;
max-width: 100%;
width: 100%;
}

.downwall {
float: left;
width: 23%;
margin-left: 22px;
margin-bottom: 20px;
}

.downwall > a > img{
border-style: solid;
border-width: 10px;
max-height: 240px;
max-width: 100%;
width: 100%;
 }

You can just style the 'wrappers', ie: .ceiling, .wall, .island, .downwall 您可以仅设置“包装器”的样式,即:.ceiling,.wall,.island,.downwall

.ceiling{float: left; width: 23%; margin-left: 5px; margin-bottom: 20px;}

.wall, .island, .downwall{float: left; width: 23%; margin-left: 22px; margin-bottom: 20px;}

then you can give the images a particular class which will have the style, eg: image 那么您可以为图像指定一个具有样式的特定类,例如:image

<img class="image" src="YOUR_IMAGE_SOURCE" />
<img class="image" src="YOUR_IMAGE_SOURCE" />
<img class="image" src="YOUR_IMAGE_SOURCE" />
<img class="image" src="YOUR_IMAGE_SOURCE" />

.image{border-style: solid; border-width: 10px; max-height: 240px; width: 100%;}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM