Html 背景图像宽度不起作用
我有一个html文件,我将背景url设置为一个图像,但该图像无法填充浏览器的宽度: 我还尝试设置Html 背景图像宽度不起作用,html,css,Html,Css,我有一个html文件,我将背景url设置为一个图像,但该图像无法填充浏览器的宽度: 我还尝试设置width属性使其更宽,但似乎没有效果 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> #bg { height:1
width
属性使其更宽,但似乎没有效果
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
#bg {
height:1500px;
background: url("img/timg7.jpg") center top no-repeat;
width:1800px;
}
</style>
</head>
<body id="bg">
<div style="width:400px; height: 200px; background-color: antiquewhite">
BLOCK
</div>
</body>
</html>
标题
#背景{
高度:1500px;
背景:url(“img/timg7.jpg”)中心顶部不重复;
宽度:1800px;
}
块
在这种情况下,您应该使用背景大小,背景大小有一个值
尝试使用:
background-size: 120%;
在这种情况下,您应该使用背景大小,背景大小有一个值 尝试使用:
background-size: 120%;
尝试使用:
背景尺寸:封面
请删除这些高度和宽度尝试使用:
背景尺寸:封面
并请删除这些高度和宽度为此,您需要
背景大小
属性
您的CSS应该是:
#bg {
background: url("img/timg7.jpg");
background-size: cover;
background-repeat: no-repeat;
}
为此,您需要
背景大小
属性
您的CSS应该是:
#bg {
background: url("img/timg7.jpg");
background-size: cover;
background-repeat: no-repeat;
}
试试这个:
#bg {
background: url("img/timg7.jpg") center top no-repeat;
background-size: cover;
}
试试这个:
#bg {
background: url("img/timg7.jpg") center top no-repeat;
background-size: cover;
}
您不需要在
正文
上使用id,就像使用JavaScript获取document.body
一样,您只需在CSS中使用正文
。当然,这不是你的问题。请参阅下面的代码:
html,body{
padding:0; margin:0;
}
body{
background:url(img/timg7.jpg) no-repeat; background-size:cover;
}
顺便说一句,您应该使用外部CSS,这样它会被缓存到浏览器内存中。您不需要在
正文
上添加id,就像文档一样。正文
使用JavaScript获取,您只需在CSS中使用正文
。当然,这不是你的问题。请参阅下面的代码:
html,body{
padding:0; margin:0;
}
body{
background:url(img/timg7.jpg) no-repeat; background-size:cover;
}
顺便说一句,你应该使用外部CSS,这样它会被缓存到浏览器内存中。你给了你的身体一个宽度?那是怎么回事?你给了你的身体一个宽度?那是怎么回事?