如何分离图像文件夹和css文件夹以在maven项目中相互使用

时间:2012-06-24 10:41:26

标签: css image

我的maven项目中有两个CSS文件和三个图像。当我将图像放在CSS文件夹中时它工作正常但是当我将图像移动到图像文件夹时,这些图像将不会显示在网页中。我想在我的项目上有一个很好的结构,因此有一个单独的图像文件夹。我该怎么做?我想我需要在我的CSS中做一些更改,但不知道如何以及在哪里。我对CSS知之甚少。

layout.css中

*{
margin:0;
padding:0;
   }
 body {
font:14px/1.3 Arial,sans-serif;
background-color:#212121;
}
header {
background-color:#212121;
box-shadow: 0 -1px 2px #111111;
color:#fff;
display:block;
height:70px;
position:relative;
width:100%;
z-index:100;
}
header h2{
font-size:22px;
font-weight:normal;
left:50%;
margin-left:-400px;
padding:22px 0;
position:absolute;
width:540px;
}
header a.stuts,a.stuts:visited{
border:none;
text-decoration:none;
color:#fcfcfc;
font-size:14px;
left:50%;
line-height:31px;
margin:23px 0 0 110px;
position:absolute;
top:0;
}
header .stuts span {
font-size:22px;
font-weight:bold;
margin-left:5px;
}
.container {
height: 571px;
margin: 30px auto;
width: 957px;
 } 

和menue.css

#nav,#nav ul {
list-style: none outside none;
margin: 0;
padding: 0;
}
#nav {
background: url('menu_bg.png') no-repeat scroll 0 0 transparent;
clear: both;
font-size: 12px;
height: 58px;
padding: 0 0 0 9px;
position: relative;
width: 957px;
}
#nav ul {
background-color: #222;
border:1px solid #222;
border-radius: 0 5px 5px 5px;
border-width: 0 1px 1px;
box-shadow: 0 5px 5px rgba(0, 0, 0, 0.5);
left: -9999px;
overflow: hidden;
position: absolute;
top: -9999px;
z-index: 2;

-moz-transform: scaleY(0);
-ms-transform: scaleY(0);
-o-transform: scaleY(0);
-webkit-transform: scaleY(0);
transform: scaleY(0);

-moz-transform-origin: 0 0;
-ms-transform-origin: 0 0;
-o-transform-origin: 0 0;
-webkit-transform-origin: 0 0;
transform-origin: 0 0;

-moz-transition: -moz-transform 0.1s linear;
-ms-transition: -ms-transform 0.1s linear;
-o-transition: -o-transform 0.1s linear;
-webkit-transition: -webkit-transform 0.1s linear;
transition: transform 0.1s linear;
}
#nav li {
background: url('menu_line.png') no-repeat scroll right 5px transparent;
float: left;
position: relative;
 }
#nav li a {
color: #FFFFFF;
display: block;
float: left;
font-weight: normal;
height: 30px;
padding: 23px 20px 0;
position: relative;
text-decoration: none;
text-shadow: 1px 1px 1px #000000;
}
#nav li:hover > a {
color: #00B4FF;
}
#nav li:hover, #nav a:focus, #nav a:hover, #nav a:active {
background: none repeat scroll 0 0 #121212;
outline: 0 none;
 }
#nav li:hover ul.subs {
left: 0;
top: 53px;
width: 180px;

-moz-transform: scaleY(1);
-ms-transform: scaleY(1);
-o-transform: scaleY(1);
-webkit-transform: scaleY(1);
transform: scaleY(1);
}
#nav ul li {
background: none;
width: 100%;
}
#nav ul li a {
float: none;
}
#nav ul li:hover > a {
background-color: #121212;
color: #00B4FF;
}
#lavalamp {
background: url('lavalamp.png') no-repeat scroll 0 0 transparent;
height: 16px;
left: 13px;
position: absolute;
top: 0px;
width: 64px;

-moz-transition: all 300ms ease;
-ms-transition: all 300ms ease;
-o-transition: all 300ms ease;
-webkit-transition: all 300ms ease;
transition: all 300ms ease;
}
 #lavalamp:hover {
-moz-transition-duration: 3000s;
-ms-transition-duration: 3000s;
-o-transition-duration: 3000s;
-webkit-transition-duration: 3000s;
transition-duration: 3000s;
}
#nav li:nth-child(1):hover ~ #lavalamp {
left: 13px;
}
#nav li:nth-child(2):hover ~ #lavalamp {
left: 90px;
}
#nav li:nth-child(3):hover ~ #lavalamp {
left: 170px;
}
#nav li:nth-child(4):hover ~ #lavalamp {
left: 250px;
 }
#nav li:nth-child(5):hover ~ #lavalamp {
left: 330px;
 }
#nav li:nth-child(6):hover ~ #lavalamp {
left: 410px;
}
#nav li:nth-child(7):hover ~ #lavalamp {
left: 490px;
}
#nav li:nth-child(8):hover ~ #lavalamp {
left: 565px;
 }

最后是index.jsp:

  <!DOCTYPE html>
  <html lang="en" >
  <head>
    <meta charset="utf-8" />
    <link href="<%=request.getContextPath()%>/resources/css/layout.css" rel="stylesheet" 
    type="text/css" />
    <link href="<%=request.getContextPath()%>/resources/css/menu.css" rel="stylesheet" 
    type="text/css" />
   </head>
   <body>
    <header>
        <h2>Welcome</h2>

    </header>
    <div class="container">

        <ul id="nav">
            <li><a class="hsubs" href="#">Menu 1</a>
                <ul class="subs">
                    <li><a href="#">Submenu 1</a></li>
                    <li><a href="#">Submenu 2</a></li>
                    <li><a href="#">Submenu 3</a></li>
                    <li><a href="#">Submenu 4</a></li>
                    <li><a href="#">Submenu 5</a></li>
                </ul>
            </li>
            <li><a class="hsubs" href="#">Menu 2</a>
                <ul class="subs">
                    <li><a href="#">Submenu 2-1</a></li>
                    <li><a href="#">Submenu 2-2</a></li>
                    <li><a href="#">Submenu 2-3</a></li>
                    <li><a href="#">Submenu 2-4</a></li>
                    <li><a href="#">Submenu 2-5</a></li>
                    <li><a href="#">Submenu 2-6</a></li>
                    <li><a href="#">Submenu 2-7</a></li>
                    <li><a href="#">Submenu 2-8</a></li>
                </ul>
            </li>
            <li><a class="hsubs" href="#">Menu 3</a>
                <ul class="subs">
                    <li><a href="#">Submenu 3-1</a></li>
                    <li><a href="#">Submenu 3-2</a></li>
                    <li><a href="#">Submenu 3-3</a></li>
                    <li><a href="#">Submenu 3-4</a></li>
                    <li><a href="#">Submenu 3-5</a></li>
                </ul>
            </li>
            <li><a href="#">Menu 4</a></li>
            <li><a href="#">Menu 5</a></li>
            <li><a href="#">Menu 6</a></li>

            <div id="lavalamp">
            </div>
        </ul>

     </div>
    </body>
    </html>

和3张图片        lavalamp.png,        menu_bg.png,        menu_line.png。

1 个答案:

答案 0 :(得分:0)

我相信您遇到的问题在于您设置路径的方式。您正在设置相对于css文件的图像路径。看看这个CSS paths - 我希望这就是你要找的东西^ - ^。

如果你想要快速和脏的版本 - &gt;

以下是您需要了解的相关文件路径:

  

以“/”开头,返回根目录并从那里开始

     

以“../”开头向后移动一个目录并从那里开始

     

以“../../”开头,向后移动两个目录并启动   那里(依此类推......)为了向前迈进,先从第一个&gt;开始子目录并继续前进