简体   繁体   English

如何使div的图像带有向左浮动的白色背景?

[英]How can I have a div with an image with a white background floated left?

my code in css is: 我在css中的代码是:

.logo{
content:url(http://www.dylionsrugby.com.au/wp-content/uploads/2012/04/lion.png/600x600);
background-color: White;
float: right;
}

and in html I have: 在HTML中,我有:

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

Am I missing something, nothing appears?` 我是否缺少任何东西,什么也没出现?

Your question is somewhat general. 您的问题有些笼统。 You could also simulate the right positioning using positioning property on the image and not on the div. 您还可以使用图像而不是div上的position属性来模拟正确的定位。

 .logo{ width: 250px; height: 75px; background-image: url("http://www.slate.com/content/dam/slate/articles/health_and_science/science/2015/07/150730_SCI_Cecil_lion.jpg.CROP.promo-xlarge2.jpg"); background-color: white; background-repeat: no-repeat; background-size: 100% 100%; float: right; } 
 <div class="logo"></div> 

First of all, the "content" property is used for :before and :after pseudo-elements. 首先,“ content”属性用于:before和:after伪元素。 Second, the link to the image is incorrect. 其次,指向图像的链接不正确。 I assume that you want the picture inside the div .logo with a white background so here is a jsfiddle: https://jsfiddle.net/Iulius90/njne5sy5/ 我假设您想要在div .logo中使用白色背景的图片,所以这是一个jsfiddle: https ://jsfiddle.net/Iulius90/njne5sy5/

code: 码:

.logo {
background: white url(http://www.dylionsrugby.com.au/wp-content/uploads/2012/04/lion.png) no-repeat center;
background-size: cover;
float: right;
width: 200px;
height: 200px;
}

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

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