Jump to content

styling for class(background colour) is not working yet element styling(h2) is working


Lincks

Recommended Posts

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

 

Link to comment
Share on other sites

  • 3 weeks later...

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. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.