【问题标题】:how to use external css for body tag in jsp如何在jsp中使用外部css作为body标签
【发布时间】:2016-01-25 13:34:40
【问题描述】:

到目前为止,我在同一个 jsp 文件中使用 css 代码为我的 jsp 页面设置背景图像,我通过将 css 代码映射到 body 标记来做到这一点。有用。就像:

<html>
<style>
body
{
    background:url(deploy/images/bg.jpg) no-repeat center center fixed;
    background-size: cover;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    margin: 0;
    padding: 0;
}
</style>
<body id="body">
<h1>hello</h1>
</body>
</html>

上面的 jsp 存在于 web-inf 文件夹中,我需要将 css 从外部放置在 web-inf/deploy/css 文件夹中,并在所有其他 jsp 中使用外部 css。

如何在 web-inf/deploy/css 文件夹中创建外部 css,以及如何在所有其他 jsps 中将其引用为 body 标签。谢谢。

【问题讨论】:

    标签: html css jsp background-image stylesheet


    【解决方案1】:

    这应该可行:

    <html>
        <head>
            <jsp:include  flush="true" page="deploy/css_folder/body.css.jsp"/>
        </head>
        <body id="body">
            <h1>hello</h1>
        </body>
    </html>
    

    在 body.css.jsp 中(在 deploy/css_folder 中):

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <style>
    body
    {
        background:url(../images/bg.jpg) no-repeat center center fixed;
        background-size: cover;
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        margin: 0;
        padding: 0;
    }
    </style>
    

    【讨论】:

      【解决方案2】:

      创建文件

      myCSS.css
      

      您放置 css 代码的位置。将此文件放在 css 文件夹中。 然后在您的页面中添加以下内容:

      <link href="css/myCSS.css" rel="stylesheet" type="text/css" />
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-03-06
        • 2022-10-06
        • 1970-01-01
        • 2011-11-15
        • 2016-01-22
        • 2013-07-18
        • 1970-01-01
        相关资源
        最近更新 更多