Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is CSS content image not displaying?

Tags:

html

css

Consider this html:

<div class="logo-b"></div>

And this CSS:

div.logo-b {
    content: url(http://placehold.it/350x150);
    height: 150px;
    border: 1px solid darkred;
}

I am trying to display an image using CSS. The image is not being displayed. Please see this jsfiddle to see what I mean. What am I missing please?

EDIT: It appears that Chrome renders the fiddle as I provided it above fine, but Firefox (which I use) does not. If I add :before or :after to the class name in my CSS the image displays in Firefox. Could someone shed some light on why this would be please?

EDIT: I am using the wrong construct to place the image on my page. In the context of what I am doing I should use the <img> html tag. The CSS content construct uses :before and/or after to place content, including images, but I understand these are used in specific contexts. I simply want to display a logo.

like image 616
Steve Cooke Avatar asked Oct 31 '22 22:10

Steve Cooke


1 Answers

This property content is used with the :before and :after pseudo-elements to generate content in a document. -W3C

I think the behavior in Firefox is correct.

like image 135
Stickers Avatar answered Nov 15 '22 07:11

Stickers