Lincks Posted July 8, 2023 Share Posted July 8, 2023 This is my index.php page <?php //echo session_save_path(); error_reporting(E_ALL); ini_set('display_errors', 1); include ("database.php"); ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport"content="width-device-width, initia=scale=1.0"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous"> <script defre src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz" crossorigin="anonymous"></script> <link rel="stylesheet" href="styles.css"> <title>index</title> </head> <body> <h2>hello world</h2> <div class="background-image"> <div class="form-box"></div> </div> </body> <style> .background-image{ background-image: url('/blueSunset.jpg'); background-size: contain; width: 200px; height: 200px; } </style> </html> This is my styles.css page h2{ color: blue; } .background-image{ background-image: url(blueSunset.jpg); width: 200px; height: 200px; } My image is in the same directory as the two files. When I try styling using class it doesn't work in all cases not just this instance Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted July 24, 2023 Share Posted July 24, 2023 In case you are still looking for an answer, the issue might be caused by .background-image being defined twice. The definition in your styles.css is being ignored in this case, since you override all the rules in the <style> tag for the page. For example, the following rule from styles.css background-image: url(blueSunset.jpg); Is overridden by the following rule in the <style> tag: background-image: url('/blueSunset.jpg'); Note that the first rule says your image is in the same folder as the stylesheet...where the second rule says the image is in the root directory (note the slash). If the image isn't in the root directory, it won't show up. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.