为什么我的背景图片没有显示出来

时间:2016-04-07 08:15:22

标签: html css html5 css3

我决定建立一个关于当前选举的网站,我在介绍页面上遇到了麻烦。

#wrapper {
  height: 900px;
  width:  900px;
  border: solid;black;
  margin-left: auto;
  margin-right: auto;
}
#repicon {
  background-image: url(http://i.imgur.com/Ow7TR.png);
  background-size: 140px 140px;
}
<div id="Wrapper">
  <div id="repicon"></div>
</div>

6 个答案:

答案 0 :(得分:2)

<强> HTML

<div id="Wrapper">
<div id="repicon">sdsdfsdsds</div>

<强> CSS:

#wrapper {
    height: 900px;
    width:  900px;
    border: solid;black;
    margin-left: auto;
    margin-right: auto;
}

#repicon {
background-image: url(http://i.imgur.com/Ow7TR.png);
//background-size: 140px 140px;
height: 500px;
width: 500px;
}

DEMO LINK

答案 1 :(得分:2)

你有一些拼写错误(id="Wrapper"与CSS中的#wrapper不匹配)加上background-image需要工作height

作为评论,您希望background-image居中,只需在center简写中应用background

#wrapper {
  height: 900px;
  width: 900px;
  border: solid  black;
  margin-left: auto;
  margin-right: auto;
}
#repicon {
  background: url(http://i.imgur.com/Ow7TR.png) no-repeat center  / 140px 140px;
  height:140px;
}
<div id="wrapper">
  <div id="repicon"></div>
</div>

答案 2 :(得分:1)

它不起作用,因为您的div没有内容,导致它没有height。要查看您的图片,您必须向div或min-height

添加内容
#repicon {
min-height: 140px;
background-image: url(http://i.imgur.com/Ow7TR.png);
background-size: 140px 140px;
}

查看此工作Fiddle

答案 3 :(得分:0)

如果您希望显示“背景图片”,则需要在div中包含内容。

答案 4 :(得分:0)

您需要为#repicon

定义高度和宽度

#wrapper {
  height: 900px;
  width:  900px;
  border: solid;black;
  margin-left: auto;
  margin-right: auto;
}
#repicon {
  background-image: url(http://i.imgur.com/Ow7TR.png);
  background-size: 140px 140px;
  width: 140px;
  height: 140px;
}
<DOCTYPE html>
  <html>
    <head>
      <title>2016 Election</title>
      <meta name="keywords" content="Donald Trump, Bernie Sanders, Ted Cruz, Hillary Clinton, 2016 Elections, 2016 Primaries, Republican, Democrat"> 
      <meta name="description" content="2016 Presidential Election, Primary Nominations">
      <link rel="stylesheet" href="style.css">
    </head>
    <body>
      <div id="Wrapper">
        <div id="repicon"></div>
      </div>
    </body>
  </html>

答案 5 :(得分:-1)

只需在您的div中添加“&amp; nbsp”并更新您的CSS以获得最佳效果。

git merge master
git status --porcelain | awk '{if ($1=="DU") print $2}' | xargs git rm
git commit
MimeMessage newmsg = new MimeMessage((MimeMessage) message);

newmsg.setSubject(new_subj);
newmsg.setFlag(Flags.Flag.SEEN, false);

MimeBodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.attachFile("test.txt");

Multipart multipart = (Multipart)message.getContent();
multipart.addBodyPart(messageBodyPart);
newmsg.setContent(multipart);

newmsg.saveChanges();

Folder folder_dest = folder.getFolder("test");
folder_dest.appendMessages(new Message[]{newmsg});