Html 表和背景img问题
我的网站有问题。我无法使表格出现在img上。它显示在图像的下方或上方。我需要一些代码方面的帮助。事实上,我不希望img每次都能重新调整并适应用户窗口。插入img的代码如下Html 表和背景img问题,html,css,Html,Css,我的网站有问题。我无法使表格出现在img上。它显示在图像的下方或上方。我需要一些代码方面的帮助。事实上,我不希望img每次都能重新调整并适应用户窗口。插入img的代码如下 <body oncontextmenu="return false;" background="bg_body.jpg"> <style> <!-- body { margin: 0px; } --> </style> <img src='whatever' style=
<body oncontextmenu="return false;" background="bg_body.jpg">
<style> <!-- body { margin: 0px; } --> </style>
<img src='whatever' style='width: 100%; height: 100%;' />
a实际上帮助了我,但并没有100%解决这个问题,因为img中并没有出现这个表
<body oncontextmenu="return false;" background="bg_body.jpg">
<style> <!-- body { margin: 0px; } --> </style>
<img src='whatever' style='width: 100%; height: 100%;' />
考虑使用CSS背景属性 HTML(类似于此,未经测试):
如果你想让背景图像“调整”到浏览器的大小,你必须修改它才能工作。一种常见的方法可能是使用两个div标记;第一个将包含100%大小的图像,具有绝对定位。第二个包含实际的身体内容,具有更高的z值。这比你想象的要多得多
有关这方面的详细讨论,请参阅此线程:考虑使用CSS背景属性 HTML(类似于此,未经测试):
如果你想让背景图像“调整”到浏览器的大小,你必须修改它才能工作。一种常见的方法可能是使用两个div标记;第一个将包含100%大小的图像,具有绝对定位。第二个包含实际的身体内容,具有更高的z值。这比你想象的要多得多
有关这方面的详细讨论,请参阅以下帖子:这里有几点没有太大意义: “oncontextmenu=”返回false;您是否正在尝试运行某种javascript?如果是,您需要在“return false”之前调用函数,如下所示:
<body onload="someFunction() return false;">
<style type="text/css">
body{
background-image:url(../path/to/image);
background-repeat:no-repeat;
height:100%;
width:100%;
}
</style>
另外,我不认为你可以按照你的方式为一个元素设置背景,它更像这样:
<table style="background:path/to/my/image/...">
<style type="text/css">
*{margin:0;padding:0;}
html,body{height:100%;}
.backgroundlayer { position:absolute;top:0;left:0;z-index:1; }
.toplayer { position:absolute;top:0;left:0;z-index:2; }
</style>
我很想再帮点忙,但请你解释清楚一点
好的,我建议你这样做:
<table style="background:path/to/my/image/...">
<style type="text/css">
*{margin:0;padding:0;}
html,body{height:100%;}
.backgroundlayer { position:absolute;top:0;left:0;z-index:1; }
.toplayer { position:absolute;top:0;left:0;z-index:2; }
</style>
无论是在外部样式表上,还是嵌入在头部标记中,都可以使用一些简单的CSS设置图像大小,如下所示:
<body onload="someFunction() return false;">
<style type="text/css">
body{
background-image:url(../path/to/image);
background-repeat:no-repeat;
height:100%;
width:100%;
}
</style>
身体{
背景图像:url(../path/to/image);
背景重复:无重复;
身高:100%;
宽度:100%;
}
试试这个,看看它是否管用,如果管用不了,我会帮你更多。这里有几件事没有太大意义: “oncontextmenu=“return false;”是否正在尝试运行某种javascript?如果是,则需要在“return false”之前调用函数,如下所示:
<body onload="someFunction() return false;">
<style type="text/css">
body{
background-image:url(../path/to/image);
background-repeat:no-repeat;
height:100%;
width:100%;
}
</style>
另外,我不认为你可以按照你的方式为一个元素设置背景,它更像这样:
<table style="background:path/to/my/image/...">
<style type="text/css">
*{margin:0;padding:0;}
html,body{height:100%;}
.backgroundlayer { position:absolute;top:0;left:0;z-index:1; }
.toplayer { position:absolute;top:0;left:0;z-index:2; }
</style>
我很想再帮点忙,但请你解释清楚一点
好的,我建议你这样做:
<table style="background:path/to/my/image/...">
<style type="text/css">
*{margin:0;padding:0;}
html,body{height:100%;}
.backgroundlayer { position:absolute;top:0;left:0;z-index:1; }
.toplayer { position:absolute;top:0;left:0;z-index:2; }
</style>
无论是在外部样式表上,还是嵌入在头部标记中,都可以使用一些简单的CSS设置图像大小,如下所示:
<body onload="someFunction() return false;">
<style type="text/css">
body{
background-image:url(../path/to/image);
background-repeat:no-repeat;
height:100%;
width:100%;
}
</style>
身体{
背景图像:url(../path/to/image);
背景重复:无重复;
身高:100%;
宽度:100%;
}
试试看它是否有效,如果不行,我会帮你更多。如果你想让背景图像适合浏览器的大小(我猜是这样,但是如果你的图像有100%的高度和宽度,这似乎是你想要的),你可以这样做:
<table style="background:path/to/my/image/...">
<style type="text/css">
*{margin:0;padding:0;}
html,body{height:100%;}
.backgroundlayer { position:absolute;top:0;left:0;z-index:1; }
.toplayer { position:absolute;top:0;left:0;z-index:2; }
</style>
*{边距:0;填充:0;}
html,正文{高度:100%;}
.backgroundlayer{位置:绝对;顶部:0;左侧:0;z索引:1;}
.toplayer{位置:绝对;顶部:0;左侧:0;z索引:2;}
然后在代码的主体中
<body>
<img src="someimage.png" style="height:100%;width:100%;" class="backgroundlayer" />
<div class="toplayer">
my content above the image...it doesn't have to be a div...use a table if you want
</div>
</body>
图片上方的我的内容…不必是div…如果需要,可以使用表
如果您希望背景图像适合浏览器的大小(我猜是这样,但如果您的图像上有100%的高度和宽度,这似乎是您所追求的),您可以执行以下操作:
<table style="background:path/to/my/image/...">
<style type="text/css">
*{margin:0;padding:0;}
html,body{height:100%;}
.backgroundlayer { position:absolute;top:0;left:0;z-index:1; }
.toplayer { position:absolute;top:0;left:0;z-index:2; }
</style>
*{边距:0;填充:0;}
html,正文{高度:100%;}
.backgroundlayer{位置:绝对;顶部:0;左侧:0;z索引:1;}
.toplayer{位置:绝对;顶部:0;左侧:0;z索引:2;}
然后在代码的主体中
<body>
<img src="someimage.png" style="height:100%;width:100%;" class="backgroundlayer" />
<div class="toplayer">
my content above the image...it doesn't have to be a div...use a table if you want
</div>
</body>
图片上方的我的内容…不必是div…如果需要,可以使用表
你能详细解释一下“表格”吗?…看看我现有的网站。我想让这个img出现一次,而不是重新出现(适合窗口取决于用户的分辨率)。我的按钮+文本都是用表格制作的。但当我把我在问题中发布的代码与图片分开,并显示按钮和文本。检查源代码从这里你可以解释更多关于“表”…看看我现有的网站。我想让这个img出现一次,而不是重新出现(适合窗口取决于用户的分辨率)。我的按钮+文本都是用表格制作的。但当我把我在问题中发布的代码与图片分开,并显示按钮和文本。查看这里的源代码,看看我现有的站点legene2explosive.tk。我想让这个img出现一次,而不是重新出现(适合窗口取决于用户的分辨率)。我的按钮+文本都是用表格制作的。但当我把我在问题中发布的代码与图片分开,并显示按钮和文本;语句是正确的…它只是取消了上下文菜单,所以它并不意味着运行任何进一步的功能。该功能适用于表格和图像,图像不被删除,但不适用于fit on browser。明白我的意思吗?看看我现有的网站lineake2explosive.tk。我想让这个img出现一次,而不是重新出现(适合窗口取决于用户的分辨率)。我的按钮+文本都是用表格制作的。但当我把我在问题中发布的代码与图片分开,并显示按钮和文本;语句是正确的…它只是取消了上下文