Unable to display button image when using both id and style class in CSS

During my transition from Java 7 to Java 8, I've encountered a peculiar issue. Here's a brief explanation:

In my FXML file, I have a button defined with style class button-red-big and id btnInput:

<Button id="btnInput" fx:id="btnInput" alignment="BOTTOM_RIGHT" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#handle_InputButton" prefHeight="100.0" prefWidth="100.0" styleClass="button-red-big" text="%experthome.button.input" textAlignment="CENTER" wrapText="true" />

Upon hovering over the red button, it changes to white due to the CSS code snippet below:

.button-red-big {
    -fx-background-color: rgb(207,28,0);
    -fx-background-radius: 6, 5;
    -fx-background-insets: 0, 1;
    -fx-background-repeat: no-repeat;
    -fx-background-position: center center;
    -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.4) , 5, 0.0 , 0 , 1 );
    -fx-text-fill: #ffffff;
    -fx-font-size: 10pt;
    -fx-font-weight: bold;
}

.button-red-big:hover {
    -fx-background-color: #ffffff;
    -fx-text-fill: rgb(207,28,0);
}

.button-red-big:pressed {
    -fx-padding: 10 15 13 15;
    -fx-background-insets: 2 0 0 0,2 0 3 0, 2 0 4 0, 2 0 5 0;
}

To enhance its appearance, I included an image on the button - a red image for hover state and a white image for normal state, handled through CSS based on the button's id and style class:

#btnInput .button-red-big {
    -fx-background-image: url("/src/img/Input_w.png"); //white image
}

#btnInput .button-red-big:hover {
    -fx-background-image: url("/src/img/Input_r.png"); //red image
}

While this setup functioned perfectly in Java 7, I'm facing challenges with the image loading in Java 8. Simply adding the -fx-background-image line directly within .button-big-red resolves the issue temporarily, but it's not an ideal solution given that I use different images for various buttons like so:

#btnAnalysis .button-red-big {
    -fx-background-image: url("/src/img/Analysis_w.png");
}

#btnAnalysis .button-red-big:hover {
    -fx-background-image: url("/src/img/Analysis_r.png");
}

#btnOutput .button-red-big {
    -fx-background-image: url("/src/img/Output_w.png");
}

#btnOutput .button-red-big:hover {
    -fx-background-image: url("/src/img/Output_r.png");
}

I hope this provides some clarity. Any insights into what might be causing this behavior?

Answer №1

There seems to be an issue with your selector.

#btnAnalysis .button-red-big { ... }

This code will target elements with the css class button-red-big that are nested within elements with the id btnAnalysis.

You might want to consider using just

#btnAnalysis { ... }

This will select the element with the id btnAnalysis, or you can try

.button-red-big { ... }

To target elements with the style class button-red-big, or alternatively

#btnAnalysis.button-red-big { ... }

(notice there is no space) which will target elements with both the id btnAnalysis and the style class button-red-big.

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

How to use xpath to specifically retrieve numeric values from an xml document

I'm working with an XML that looks like this: <div class="_4079e399">The age is 24 years</div> I need to extract the number 24 using only an XPath expression. I attempted //*[@class="_4079e399"]/translate(., translate(. ...

Access in-depth data by clicking on a map to get detailed information

Recently, I took on the challenge of managing a golf club website after the original creator had to step away. One urgent issue I need to address is fixing a malfunctioning flash animation that provides information about each hole on the course. My plan is ...

Troubleshooting problem with Firefoxdriver and Browsermob integration

public class PerfTestt { public static void main(String[] args) throws Exception { ProxyServer server = new ProxyServer(8080); server.start(); Proxy proxy = server.seleniumProxy(); DesiredCapabilities capabilities = new DesiredCapab ...

Tips for changing the default height of Elastic UI dropdown menus

I am attempting to adjust the height of the Task combobox to match that of the Date Picker, but the styling is not being applied when done through a class or inline. https://i.sstatic.net/3Cua1.png I have tried inline styling the element as: <EuiForm ...

Position pictures in the same row in a straight line

I am struggling to align a set of images properly. The screenshot below shows the current layout: My goal is to have all four images lined up in a single row, with any additional images starting on a new row. I have attempted various methods, but none ha ...

The wait.until(ExpectedConditions.elementToBeClickable) method doesn't seem to be properly timing out within the specified duration

When using Selenium WebDriver with Java, I encountered an issue where I needed to click on a grayed-out element on the page that was visible but not interactive. I tried using ExplicitWebDriverWait to wait for the element to become clickable, but it did no ...

Adding custom fonts to DOMPDF: a step-by-step guide

First, I moved the dompdf library folder to /dompdf Next, I added a /fonts folder containing Roboto-Black.ttf Then, I created an index.php file <?php // Autoloader inclusion require_once 'dompdf/autoload.inc.php'; // Namespace reference ...

Implementing spacing to columns in Bootstrap 4

Is there a way to add margin to the "col" element with the class "mr-md-3" without causing any layout breaks within the containing div? .content { height: 200px; border: 1px solid black; } <script src="https://ajax.googleapis.com/ajax/libs/jquery ...

Illuminated container with shading

I'm struggling to style a box with a unique glow effect and shadow at the bottom. I've hit a roadblock in creating this particular effect. The glow effect I am aiming for is shown here: https://i.stack.imgur.com/i2va8.png My attempts to create ...

CSS Style in Safari does not conceal Div on Tailwind

When switching the screen from desktop to mobile in ReactJS/Tailwind, I have hidden certain images using the following code: <div className="flex shrink flex-row justify-between w-[60%] h-[25%] sm:w-[95%] sm:h-[52%] mb-[-10px] mt-[-15px] lg:mt-0&qu ...

When placed within a <li> element, the <a> tag will not create a hyperlink to a page, but it will

I have encountered an issue with my anchor links. All of them are working properly except for the one in the second ul with an href="page1". Interestingly, the link shows the correct destination at the bottom left of my screen and works when I right-click ...

Arrange fixed-position elements so that they adhere to the boundaries of their adjacent siblings

Is there a way to keep two fixed elements aligned with their sibling element on window resize? <div class="left-img"> IMAGE HERE </div> <!-- fixed positioned --> <div class="container"> Lorem ipsum... </div> <div class=" ...

Is there a way to make text within a Div selectable even if it is positioned behind another Div with a higher z-index?

Currently grappling with some code, unfortunately cannot easily paste the problematic part here as I am unsure of its exact location. Here's the situation: there is a div containing text that needs to be selectable, however, there is another div with ...

The stylesheet reference, <link rel="stylesheet" href="../css/style.css">, appears to be malfunctioning

My project structure includes css files in a folder named css and jsp files in a folder named jsp, both located inside the WEB-INF folder. I am wondering how to access the css file within a jsp file. <link rel="stylesheet" href="../css/style.css> T ...

Caution: The `className` property does not align with Material UI css which may cause issues upon reload

https://i.stack.imgur.com/MxAiY.png If you are facing the error/missing CSS, check out this video for a visual representation. While older versions of similar questions exist on Stack Overflow such as React + Material-UI - Warning: Prop className did not ...

Finding a hyperlink in Selenium without the presence of an id or class attribute

Could someone please help me with identifying this specific HTML "node" using WebDriver? <a href="http://www.google.pl/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=2&amp;cad=rja&amp;uact=8&amp;ved=0CDAQFjAB ...

Avoiding redundant SQL queries in Spring Boot JPA ManyToOne relationship

There are three objects with a simple relationship outlined below: University: @Entity public class University { @Id @GeneratedValue private Long id; private String name; } Faculty: @Entity public class Faculty { @Id @GeneratedValue p ...

What can I do to eliminate the excess white space within my div element?

I've built this app using the create-react-app CLI, but I'm struggling to remove the extra white spaces surrounding my main container. Check out the screenshot below for reference. Currently, the only div in my app has the following CSS: .main ...

What is the best way to have a div created by JavaScript automatically expand to cover the entire screen after clicking on a dynamically generated table cell?

A unique interactive game inspired by Jeopardy is in the works. By clicking on a specific element within the game board, players can reveal questions fetched from the Jeopardy API. These questions are then presented elegantly within a dynamically created d ...

using mixins with styled-components

I have encountered a challenge while attempting to pass a mixin from Material UI to a styled-component. The problem lies in finding a way to transfer the mixin value to the styled-component without having to assign it to a css property. Unfortunately, dire ...