Div与背景不会显示 [英] Div with background won't show

查看:73
本文介绍了Div与背景不会显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,这就是我正在打印的内容:

Okay so this is what I'm printing:

<a href=\"portfoliodetail.php?id=$id\" class=\"noHover\" title=\"$title\">
     <div class=\"thumbnailHome\" style=\"background: url('images/portfolio/thumbnails/$bgthumbnail'); background-position: center center;\">f</div>
</a>

这就是CSS:

.thumbnailHome {
    max-width: 28%;
    height: 100%;
    margin-right: 7%;
    opacity: 0.4;
    filter: alpha(opacity=40);
    float: left;
    margin-bottom: 40px;
}

.thumbnailHome a:last-child {
    margin-right: 0%;
}

但是,打印的div不会显示。当我检查元素时,它的高度和宽度均为0.当我在其中放入一些文本时,div和背景显示,但只与文本一样大。

However, the divs printed won't show. When I inspect the element it says the height and width are both 0. When I put a bit of text in it, the div and the background display but only as big as the text.

我给它的最大宽度为28,所以我可以有三个div彼此相邻(如果屏幕变小,它们会缩放)。我想保持这个未来,但我不知道如何解决这个问题,以便divs显示出来?我不明白为什么宽度和高度是0?

I gave it a max-width of 28 so I could have three divs next to each other (and they would scale if the screen gets smaller). I would like to keep this future but I've got no clue on how to fix this so that the divs would show up? I don't understand why the width and height are 0?

link to fiddle http://jsfiddle.net/R4mGY/

link to fiddle http://jsfiddle.net/R4mGY/

推荐答案

也许这会有帮助。

您的css没有放置正确。

your css isn't placed right.

看看jsFiddle。

Take a look at the jsFiddle.

a:last-child div {
    margin-right: 0%;
}

http://jsfiddle.net/4fuzm/

更新后的代码

下面的代码在没有文字时有效。

Updated Code
The below code works when there is no text.

http://jsfiddle.net/4fuzm/2/

这篇关于Div与背景不会显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆