gpt4 book ai didi

javascript - 在图像上显示列表 : the text goes to the right of it

转载 作者:太空宇宙 更新时间:2023-11-04 05:22:25 24 4
gpt4 key购买 nike

我有一个 img 元素用作导航栏的背景,然后我将在 img 元素的顶部显示导航链接。正如您将在下图中看到的,我的问题是保存链接的 ul 显示在导航栏的右侧,而不是显示在导航栏上方。为什么要这样做以及如何让我的链接位于 img 的顶部?

现在是这样的:看看白色的文字 This is how it looks

它应该是这样的 This is how it should look

我的代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/homepage.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Kamalei - Home Page</title>
<style type="text/css">
<!--
html, body, div, form, fieldset, legend, label, img { margin: 0; padding: 0; } table { border-collapse: collapse; border-spacing: 0; } th, td { text-align: left; } h1, h2, h3, h4, h5, h6, th, td, caption { font-weight:normal; } img { border: 0; }

body { text-align: center; min-width: 1200px; }

#backgroundImg { z-index: -1; position: absolute; left: 0px; top: 0px; }

#heading { height: 300px; }
#main { margin: 0 auto; }
#navBar { display: inline; height: 700px; width: 200px; z-index: 1; position: relative; } /* I am pretty sure the cause is because I use "inline" but I need it to position the navbar correctly to the left */
#content { display: inline; height: 700px; width: 800px; padding: 20px; padding-left: 30px; }

#navBarImg { position: relative; z-index: 0; padding-right: -5px; margin-right: -5px; } /* Remove gap between navbar & content divs */
#contentImg { }

#navbar ul li { padding: 0; margin: 0; }
#navLinks { color: white; top: 0; left: 0; position: absolute; }
-->
</style>

</head>

<body>

<div id="heading">
abc
</div>

<div id="main">
<div id="navBar">
<!-- Error occurs here: the unordered list is displayed to the right of the nav bar instead
of where it should be which is inside the navbar -->
<ul>
<li id="navLinks">abcdef</li>
</ul>

<img id="navBarImg" src="images/navBackground.png" alt="" width="200px" height="700px"/>

</div>

<div id="content">
<img id="contentImg" src="images/contentBackground.png" alt="" width="800px" height="700px"/>
</div>
</div>


<!-- Must keep the background image at the bottom of body -->
<img id="backgroundImg" src="images/background.png" alt="" width="100%" height="1100px"/>

<script type="text/javascript">
<!--
window.onresize = setBackgroundImgWidth;
-->
</script>

</body>

</html>

最佳答案

您需要将导航栏背景设为 div 的背景图像,而不是作为 html 一部分的图像。这是在文本下方显示图像的最干净的方式。您可以在 css 中为 div 设置高度和宽度,以确保整个图像也显示出来。

关于javascript - 在图像上显示列表 : the text goes to the right of it,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6247611/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com