How come the styles in my CSS file aren't being applied to my images based on their class or ID?

When I apply a className or id to my img tag in my JavaScript (using React.js) and then add a style that references that id or class, the style does not get applied. However, when I do the same for a div, everything works perfectly fine.

<--JavaScript-->

import React from "react";
import TitleImage from './Images/TitleBG.png'
import TitleImage2 from './Images/TitleMG.png'
import TitleImage3 from './Images/TitleCG.png'
import './header.css'; 

const TopHeading = () => {

    return(

        //This is a div with the ID "TopHeading", and the style is applied correctly.

        <div id="TopHeading">

            {/*The image with class "image1" does not have its style applied.*/}

            <img className="image1" alt="Dofus" src={TitleImage}/>
            <img width='auto' alt = "Memory Game" height='50px' src={TitleImage2}/>
            <img width='auto' alt = "Character" height='50px' src={TitleImage3}/>
            <div className="aDiv"></div>
        </div>
    );
};

<--CSS-->

#TopHeading{
    display: grid;
    align-items: center;
    justify-items: center;
  
    background-color: rgb(131, 192, 131);
    height: 300px;
};

.image1{
    border-style: solid;
    width: auto; 
    height:250px;
}

.aDiv{
    size: 50px;
    border-style: solid;

The style of the ID gets properly applied to the div.

https://i.stack.imgur.com/prMWX.png

However, the style of the image with the class is somehow ignored:

https://i.stack.imgur.com/jcFyF.png

Answer №1

The mistake in your CSS code is the presence of a semicolon before the class rule, which renders the selector invalid. Remember to only use semicolons inside curly brackets { }.

This incorrect code snippet:

;
div
{
  height: 50px;
  width: 50px;
  background: red;
}
<div></div>

Should be corrected to:

div
{
  height: 50px;
  width: 50px;
  background: red;
}
<div></div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The console is showing an error message stating that the variable "i" is not

Currently, I am developing the dashboard for my discord.js bot. While working on it, I encountered an issue where a variable I created to select an array from my JSON file is being reported as undefined by the console. $(function() { $.getJSON( "./data/ ...

Leverage the Express JS .all() function to identify the specific HTTP method that was utilized

My next task involves creating an endpoint at /api that will blindly proxy requests and responses to a legacy RESTful API system built in Ruby and hosted on a different domain. This is just a temporary step to transition smoothly, so it needs to work seam ...

Having trouble installing Material UI on React 18?

I'm facing an issue while trying to integrate Material UI and icons into my React 18.0 project. The project was built using the latest create-react-app. npm install @material-ui/core @material-ui/icons npm ERR! code ERESOLVE npm ERR! ERESOLVE unable ...

Merge HTML/CSS with JavaFX's FXML and customize the style using CSS

Quick Summary: I have a cool button on CodePen that rotates and grows when hovered over using HTML/CSS. I want to incorporate this button into my JavaFX GUI, built with SceneBuilder and FXML files. The GUI currently features buttons numbered 1-4, and I wo ...

Next js Link Button with Material-UI Enhancements

Currently, I am working on a project using Server-Side-Rendering React with Next-JS and Material-UI. I am looking to implement a button from Material UI that functions as a Link with Dynamic routes. I am having trouble figuring out how to achieve this. I ...

The script from '*' is being denied execution because its MIME type ('application/json') is not executable, and a strict MIME type check is in place

Here is the code I used to retrieve data from the confluence rest api: <script type="text/javascript" src="Scripts/jquery.min.js"></script> <script> $.ajax({ type: "GET", url: "https://blog.xxxxx.com/rest/api/content? ...

Developing a specialized command-line application for currency conversion is my current project

Currently, I am working on developing a command-line application for currency exchange. I have created an interface to define the structure of an object array that will store the keys and values of currency names along with their current values in the inte ...

What is the best way to create a slideshow that automatically starts upon loading and pauses when hovered over?

I have recently set up a div element for my slideshow. I've included a script to enable navigation using next and previous arrows. However, I am looking to add an automatic slideshow feature that stops on hover. As a beginner, I would appreciate any a ...

Are HTML mistakes considered as WCAG violations?

In my quest to ensure that my website is WCAG compliant, I have done a lot of research. However, one question still lingers in my mind: Would a document with HTML errors still be considered WCAG 2.0 AA compliant? I recently ran Total Validator and it pro ...

Issue with pagination and filtering in Smart-table.js

Presently, my focus is on developing functionality for Smart-table.js, which requires the following features: Retrieve JSON data from a web service Create a table with pagination and filtering capabilities Implement filters for individual columns or globa ...

Creating Vue.js components dynamically

Is it possible to programmatically insert a modal component in Vue? For instance: Vue.component('modal', {...}) Then, in any component, is there a way to do something like this: Vue.component('login', { methods: { openLoginM ...

The $or operator in mongoose falls short in providing complete data when paired with the find() method

I am currently utilizing the find method in conjunction with the $or operator to search the database for any duplicate data within this specific line. const duplicate = await NewItemsData.find({ $or: newItems }); Upon inspecting the variable in the consol ...

The useSelector from @reduxjs/toolkit in Next.js is returning an undefined value

Utilizing js and @reduxjs/toolkit in my current project has resulted in an issue where the useSelector method is returning undefined values when trying to access data from the store. Below is a snippet of my reducer file: import { createSlice } from "@red ...

How should an iterable be sorted in React?

Let's break down the scenario using pseudo code: {this.props.myIterable.map((iterable) => { return ( <div>iterable.somevalue</div> ) }).sort((a,b) => {return b - a}) To clarify, I am iterating over certain props and displaying ...

Clickable link remains functional after being hidden

Even though I have hidden the Games-div using the .hide() function in jQuery, my links are still clickable. Is there a way to make them unclickable after being hidden? Here is the link to my code on jsFiddle: http://jsfiddle.net/hypertje/Frv8G/ Note: The ...

Turn off padding in material ui card

Currently, I am utilizing a material UI card and upon inspecting the card, I noticed the presence of this unique class: "MulticardContent-root". This class adds padding of 16 which I would like to remove. Strangely, it is not located within the styles co ...

What makes Angular date pickers sluggish?

Have you ever noticed that Angular JS date pickers consume a lot of CPU? When multiple date pickers are present on a page, they can noticeably reduce the site's speed. Is there a way to minimize this issue? Take for example the official Angular for ...

Is there any way I can verify the invocation of signOut in this Jest test case?

I am attempting to perform testing on my home page within a next app. However, I have encountered an issue with a button in the Home component that triggers a logout firebase function. Despite my attempts to mock this function and verify whether or not i ...

"Encountered an issue while attempting to load resource: net::ERR_CONNECTION_REFUSED" for the assets, CSS, app.js, and vendor.js files during production (using React, Babel,

Currently, I am in the process of setting up a replica of the steemit client from https://github.com/steemit/steemit.com. During development, everything seems to work fine. However, when attempting to run the same setup in a production environment using t ...

Steps for filling an HTML table within a dynamically loaded DIV

I have a container in my HTML page where I dynamically load other pages using the jQuery.load() function. One of the pages requires me to populate a table from the database just after/before it loads. How can I trigger a JavaScript function to execute righ ...