简体   繁体   中英

CSS background-image not showing

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="css/font-awesome.css">

        <style type="text/css">
            body {
                background-image: url(man_meteor.jpg);
                background-repeat: no-repeat;  
                background-size: cover;
                background-attachment: fixed;
                background-position: center;
            }

Why is my background img not showing? Below is how my files are arranged. 在此处输入图片说明

As you suggest that your content is written inside a file called home.jsp, I suspect you are mapping "/" to one of your servlets which forwards your home.jsp to the client. This isn't right because this mapping will map every other resources to the same servlet that you use to forward your home.jsp. The correct mapping is to map "" instead.

One of your blocks in your web.xml should look like this instead:

<servlet-mapping>
    <servlet-name>The name of your servlet that forwards home.jsp</servlet-name>
     <url-pattern></url-pattern>
</servlet-mapping>

Seeing your code i can say that you need to specify height:200px OR height:400px example and next just for safety add double quotes like background-image: url("man_meteor.jpg"); . Try this their are else other ways to get around.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM