【发布时间】:2012-05-23 10:35:25
【问题描述】:
我正在开发 Ruby-on-Rails 3.2.1。我遵循 DOM 结构。
更新: 删除了 Gaby 提到的 </img> 标记。问题依然存在。
<div class="frame">
<img src='SOME_PATH' class="frame-image">
</div>
并遵循 CSS
.frame { position:relative;border:1px solid #CCC;border-radius:2px;-moz-border-radius:2px; }
.frame:before
{
position:absolute;
content:'';
border:2px solid #F2F2F2;
height:100%;width:100%;
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
}
img.frame-image /* IT WON't BE APPLIED?! */
{
min-width:30px;min-height:30px;
max-width:200px;max-height:200px;
}
我面临的问题是,应用于img.frame-image 的 CSS 不起作用/未得到应用。我在 Chrome 18 和 FireFox 12 上试过。我在 Chrome 的元素检查器或 FireBug 中看不到样式。它也不会被任何其他 CSS 覆盖。
为了演示,我尝试为此创建jsfiddle。它在那里工作!
但令人惊讶的是,当我在.frame:before CSS 之上编写img.frame-image CSS 时,它起作用了!!
.frame { position:relative;border:1px solid #CCC;border-radius:2px;-moz-border-radius:2px; }
img.frame-image /* NOW IT WILL BE APPLIED */
{
min-width:30px;min-height:30px;
max-width:200px;max-height:200px;
}
.frame:before
{
position:absolute;
content:'';
border:2px solid #F2F2F2;
height:100%;width:100%;
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
}
知道为什么会这样吗?是框架 (RoR) 相关问题还是 CSS 语义?
【问题讨论】:
标签: css pseudo-element