因此,根据我的理解,在完成基本的 GFX 之后,我最终决定尝试编写自己的网站。首先,我想清楚地定位所有内容,但出于某种原因我似乎无法掌握它,这太令人沮丧了。
我一直遇到的主要错误是它似乎不适合任何让我恼火的分辨率。我听说过使用 %,但这似乎并不能解决问题。
我遇到的最新错误是,当我使用如下代码时,我的图像甚至没有显示:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="refresh" content="30">
<meta name="keywords" content="Voyage, Voyage Community, Website">
<meta name="description" content="Voyage Community">
<title>The Voyage</title>
<link href="site.css" rel="stylesheet" type="text/css" />
<style type="text/css">
</style>
</head>
<body background="images/Background.png">
<div id="header">
<div class=".headerImage1">
</div>
这是我的 CSS 样式表:
#header
{
width:100%;
height:auto;
}
.headerImage1
{
background-image:url('images/Header.png');
position: absolute;
width: 100%;
height:120px;
}
有什么帮助吗?
编辑:这是最新的更新:
body
{
margin: 0px;
padding: 0px;
background: url("images/Background.png")
}
#header
{
position: absolute;
top: -160;
left: 420;
right: 0px;
}
.headerImage1
{
margin: 0px;
padding: 0px;
position: absolute;
width:100%;
height:100%;
background-repeat:no-repeat;
}
现在我要用 HTML 而不是 CSS 进行定位吗?
(这是一张 IMG,展示了它目前的样子:http://puu.sh/6Rg11.jpg) (只是用另一个 SS 来显示它在不同分辨率下的样子:http://puu.sh/6RgHg.jpg - 为什么它显示不同?
最佳答案
关于图片不显示:
首先,去掉<div class=".headerImage1">
中的点
在 CSS 样式定义中类前面只有一个点,在 HTML 中没有。
点本身在 CSS 中表示“这是一个类”。
同样,如果你有 id="words"
在 HTML 中是 #words
在 CSS 中。
其次,在您的 CSS 中使用它,并删除 background=
来自您的 HTML:
body {
background: url("images/Background.png")
}
对于这两种情况,请确保您的图像实际存在于您使用的 URI 中。如果它们不在根目录中,则 URI 以 /
开头(即 /images/
而不是 images/
)
关于分辨率/定位问题:
首先,删除额外的间距。确保包含类似这样的内容以删除自动添加的额外空间,如果您期望 100%
则不需要它。覆盖任何东西:
#header {
margin: 0px;
padding: 0px;
/* the above remove extra space around and inside #header */
width:100%;
height:auto;
}
/* add this to your body tag in CSS */
body {
margin: 0px;
padding: 0px;
}
其次,为您的 #header
设置一个位置当你使用 position: absolute
,像这样:
#header {
position: absolute;
top: 0;
left: 0;
right: 0px;
}
顺便说一句,当你做第二件事时,可能不需要第一件事,你也不需要使用 width: 100%
要么。
最后,您似乎希望它工作的方式是,您想使用 <img>
headerImg1
的标签并按照我为 #header
显示的方式设置尺寸上面,而不是直接调整图像的大小。否则,您需要移动您的 top
, left
, right
您现在拥有的类的属性,而不是 #header
和我一样。
关于html - HTML/CSS 中的定位/解析问题,以及向页面添加图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21686687/