html - 设置主页图像布局的样式 - 目标 div 或 img?

标签 html css

我只使用图像内容设计主页,不使用文本。

当我设置图像布局的样式时,是否应该只在 div 类中完成(例如 ceiling> 还是我需要设置每个 img 类的样式(.ceiling > a > img)

只是有意识的,我将深入了解这里的样式,因为它可以设置在顶级 div 中。

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%;
 }

最佳答案

您可以只设置“包装器”的样式,即:.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;}

然后你可以给图像一个特定的类,它将有风格,例如:图像

<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%;}

关于html - 设置主页图像布局的样式 - 目标 div 或 img?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33997599/

相关文章:

javascript - 如何使用javascript使图像上下移动

javascript - 列的跨度文本长度(或 li)

javascript - 创建动态 slider jQuery

javascript - 保存前预览图像

javascript - 使用 JavaScript 更改 Less 文件

javascript - 我正在用 HTML 编写类似 PDF 的页面格式。超出页面高度时如何将文本移动到下一页

javascript - Bootstrap 响应式 iframe,具有自动高度计算

html - CSS:Div 环绕图像

javascript - 获取多个单选值

css - 正确对齐的 div 内的 Angular Material 卡必须具有相同的高度