Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css background image in a different folder from css

Tags:

html

css

my css is in assets/css/style.css and my image is in assets/img/bg.png But when i try to link the background image:

background: url(../img/bg.png);

it instead uses assets/css/../img/bg.png as the url. Why is it?

like image 543
Jürgen Paul Avatar asked Jan 09 '12 01:01

Jürgen Paul


2 Answers

Html file (/index.html)

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
     <link rel="stylesheet" media="screen" href="assets/css/style.css" />
</head>
<body>
     <h1>Background Image</h1>
</body>
</html>

Css file (/assets/css/style.css)

body{
    background:url(../img/bg.jpg);  
}
like image 190
Adriano Silva Avatar answered Sep 21 '22 17:09

Adriano Silva


For mac OS you should use this :

body {
 background: url(../../img/bg.png);
}
like image 36
Wariored Avatar answered Sep 19 '22 17:09

Wariored