Html 在 JSP 中添加图像作为背景
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35240758/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding Image as a background in JSP
提问by Bobby
I have a JSP in which I am trying to add a background Image. I am getting the nav bar from a header into the body. I am trying to add the background image to the body and when I add it, it is overlapping on the navigation bar. Below is the code of my JSP:
我有一个 JSP,我试图在其中添加背景图像。我正在从标题到正文中获取导航栏。我正在尝试将背景图像添加到正文,当我添加它时,它在导航栏上重叠。下面是我的 JSP 代码:
<jsp:include page="index_header.jsp"></jsp:include>
<div class="container">
<div style='position:absolute;zindex:0;left:0;top:0;width:100%;height:100%'>
<img src='images/im3.jpg' style='width:100%;height:100%' alt='[]' />
</div>
</div>
How do I keep the nav bar on the page and add image to the rest of the body. Kindly help me fixing this.
如何将导航栏保留在页面上并将图像添加到正文的其余部分。请帮我解决这个问题。
回答by whistling_marmot
You can add a background image to the navbar whose URL points to a blank image.
您可以向导航栏添加背景图像,其 URL 指向空白图像。
<html>
<head>
<style>
body {
background-image: url("images/im3.jpg");
}
.no-background {
background-image: url("images/blank.jpg");
}
</style>
</head>
<body>
<h1 class="no-background">Hello World!</h1>
</body>
</html>
I just created blank.jpgwith the default image when you open MS Paint.
In my example, I've added the no-backgroundclass to the h1
element. You would instead add this class to your nav-bar.
当您打开 MS Paint 时,我刚刚使用默认图像创建了blank.jpg。在我的示例中,我向元素添加了无背景类h1
。您可以将此类添加到您的导航栏。