首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >为何在css中无法添加背景图像?

为何在css中无法添加背景图像?
EN

Stack Overflow用户
提问于 2018-07-23 05:50:35
回答 2查看 0关注 0票数 0

我目前正在编写一个小的登陆页面。我试图在CSS中添加一个背景图像,但它只是不起作用。

我的CSS:

代码语言:txt
复制
@import url('https://fonts.googleapis.com/css?family=Oswald');
@import url('https://fonts.googleapis.com/css?family=Robo+Condensed');

html, body {
margin: 0;
padding: 0;
height: 100%
width: 100%
}
.intro {
height: 100%;
width: 100%;
margin: auto;
background: url(pexelsphoto.jpg) no-repeat 50% 50%;
}

我的HTML:

代码语言:txt
复制
<html>
<head>
<title>First Server</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<section class="intro">
    <div class="inner">
        <div class="content">
            <h1>JORDAN'S SERVER</h1></div>
            <a class="button" href="#">Click Me</a>
            <div>
                <img src="pexelsphoto.jpg">
            </div>
    </div>
</section>
<p>First full web server design made in July of 2018. This all holds my 
random stuff while I learn to code.</p>
</body>
</html>
EN

回答 2

Stack Overflow用户

发布于 2018-07-23 14:38:16

把你的背景像这样放进body里:

代码语言:txt
复制
body {
     background: url("pexelsphoto.jpg") no-repeat 50% 50%;
}

html, body {
     margin: 0;
     padding: 0;
     height: 100%
     width: 100%
}
.intro {
     height: 100%;
     width: 100%;
     margin: auto;
}
票数 0
EN

Stack Overflow用户

发布于 2018-07-23 15:10:42

代码语言:txt
复制
. Intro {
             height:100%;
             width: 100%;
             margin auto;
             background: url("pexelsphoto.jpg") no-repeat 50% 50%;
 } 

将双引号添加到图像名称中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100005629

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档