我怎么能有一个带有白色背景的图像的div向左浮动



我在css中的代码是:

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

在html中我有:

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

我是不是错过了什么,什么也没出现?"

您的问题有些笼统。您也可以在图像上而不是在div上使用定位属性来模拟正确的定位

.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>

首先,"content"属性用于:before和:after伪元素。其次,图片链接不正确。我假设您希望图片位于div.徽标内,背景为白色,因此这里有一个jsfiddle:https://jsfiddle.net/Iulius90/njne5sy5/

代码:

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

最新更新