I am looking to add color to a particular element in my HTML code

Is it possible to style the button where the number is greater than 25, similar to how we did with numbers greater than 15?

Your assistance is greatly appreciated. Thank you.

I have been struggling to apply specific styling to a particular item in my HTML code without success.

<div class="calc">
<div id="display" class="display">0</div>
<div class="keypad">

<div class="keys-row first-keys-row">
<div class="key clear-all">AC</div>
<div class="key show-display">80</div>
<div class="key show-display">85</div>
<div class="key show-display">90</div></div>

<div class="keys-row">
<div class="key show-display">20</div>
<div class="key show-display">25</div>
<div class="key show-display">30</div>
<div class="key show-display">35</div></div>

<div class="keys-row">
<div class="key show-display">5</div>
<div class="key show-display">10</div>
<div class="key show-display">15</div>
<div class="key calculate">=</div></div></div></div>

<style>
.calc {
color: #fff;
width: 400px;
padding: 10px;
background-color: #302d2d;
border: 10px solid #302d2d;
border-bottom: 5px solid #302d2d;
border-radius: 10px;
margin-left: 10px;}

.calc .display {
font-size: 40px;
margin-bottom: 20px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
background-color: gray;
border: 10px solid gray;
border-radius: 10px;
color: black;
height: 80px;}

.keys-row {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;}

.keypad .keys-row .key {
background-color: #999191;
font-size: 35px;
text-align: center;
width: 95px;
line-height: 75px;
border-radius: 50px;
margin: 0 5px;
cursor: pointer;
user-select: none;}

.keypad :first-child :nth-child(1){
background-color: black;}

.keypad .keys-row .key:active{
background-color: #a5a5a590;}

.keypad :last-child :nth-child(4){
background-color: lightseagreen;}

.keypad :last-child :nth-child(4):active{
background-color: #17807a;}

.keypad :last-child :nth-child(3){
background-color: #b22222;}

.keypad :last-child :nth-child(3):active{
background-color: #801818;}
</style>

Answer №1

.keypad div:nth-child(2) div:nth-child(2) {
    background: #b22222;
}
  • Using the CSS selector div:nth-child(2) targets the second DIV within the .keypad class.
  • The second instance of div:nth-child(2) selects the second button within that specific DIV.

Answer №2

Perhaps consider this alternative:

        <div class="keys-row second-keys-row">
        <div class="key show-display">20</div>
        <div class="key show-display">25</div>
        <div class="key show-display">30</div>
        <div class="key show-display">35</div></div>
        
        <div class="keys-row third-keys-row">
        <div class="key show-display">5</div>
        <div class="key show-display">10</div>
        <div class="key show-display">15</div>
        <div class="key calculate">=</div></div></div></div>

<style>
        .keypad .keys-row.second-keys-row .key.show-display:nth-child(2){
        background-color: red;}

        .keypad .keys-row.third-keys-row .key.show-display:nth-child(3){
        background-color: red;}
</style>

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

What is the method with the greatest specificity for applying styles: CSS or JS?

When writing code like the example below: document.querySelector('input[type=text]').addEventListener('focus', function() { document.querySelector('#deletebutton').style.display = 'none' }) input[type=text]:focu ...

Mastering the art of combining style with the perfect class name

I am looking to update all instances of <p class="p1"><span class="s1"> Sent with the appropriate style that was defined earlier in my iOS project. I am relatively new to iOS development and this is a dynamic HTML content that can render in v ...

Disabling modifications caused by enabling dark mode settings and plugins

After creating a website with a dark theme, I noticed that plugins like 'dark reader' and the built-in night mode of Kiwi browser on mobile are altering the colors of certain elements and removing gradient effects. Is there a way to prevent these ...

Set a maximum height for the <td> element within a table, regardless of the length of the text in neighboring cells

Here is the situation I'm dealing with: In the thread, the postbit (blue box with avatar inside) looks fine for most posts (the first three). However, the fourth postbit is vertically elongated due to longer post content. I have been trying differe ...

What is the process for integrating the toastr-rails gem into a Rails 6 project?

Hey guys, I've been struggling to integrate the toastr gem into my Rails 6 project where I already have the devise gem set up. My main roadblock seems to be understanding webpacker and how to make toastr-rails webpacker friendly. Despite going throu ...

Retrieve various identification numbers from one division and transfer them to another using AJAX

In my project, I have implemented a functionality where clicking on one DIV should trigger the opening of the next DIV in sequence. The first DIV triggers the second DIV to open, the second DIV opens the third DIV, and so on. This is achieved using collaps ...

Discover and locate inactive element using Selenium in Python

Struggling with Automation: Unable to Locate Button on Website I'm currently facing a challenge in automating a website as I am unable to locate a specific button using Selenium. The problem lies in the fact that the button is disabled by default, ma ...

Utilizing CSS float with dynamic height

Is there a way to achieve height:auto; for a parent element even when child elements are using float:left; or float:right? Solution for the Parent Element: #parent { width:100px; height:auto; padding-bottom:10px; background:#0F0; ...

Vue: the placeholder option in the select input is no longer visible once v-model is added

<select class="cursoruser-pointer p-2 w-full rounded-full "> <option class="rounded-full " disabled selected value="">Language to learn</option> <option class="rounded-ful ...

Having trouble with implementing jQuery fadeIn for thumbnail images inside a div?

I'm trying to create a functionality where clicking on a thumbnail image in a div will display the full-size version of that image in another div. I want to implement this using the jQuery fadeIn function, but my code isn't working and I am not v ...

Guide on executing a PHP file from HTML or Javascript

I've been searching for a while now without any luck in finding an answer to this seemingly simple question. I don't mind if the page reloads or shows results instantly; all I want is to have a button on my website trigger the execution of a PHP ...

When there is an absence of data, the jQuery datatable mysteriously van

I have encountered an issue in my Django app where a datatable used in the template disappears if there is missing data in any column or row. The problem occurs when trying to download the data in CSV, Excel, PDF, or copy format. Here is the HTML code snip ...

How to access the IDs of child pages in WordPress

Being new to WordPress and PHP, I apologize if this question has been answered before. I have searched extensively but haven't found a solution that works for me. The WordPress documentation is quite complex for me to navigate through functions and ho ...

Intrigued by the connection between background and calc()?

Hello everyone! I'm currently involved in a project and have a quick question regarding the calc function. As we all know, it functions perfectly on all browsers... ========== great! ============= background-color:#dfdfdf; background-image:url(..) ...

Looking for a JavaScript tool to create XHTML content from input parameters?

Do you have a moment for a rather complex query? :) I am interested in sending data in JSON format from the server to the client. The data will then be utilized by JavaScript to create XHTML based on this information. Currently, I am in search of a libr ...

If the width is divisible by a certain value

I have a question regarding the width of my element that I want to divide by 90. If this width is a multiple of 90, I set the width of the element. If not, I move on to the next. For example, when the window width is 1000px and the element is at full widt ...

Update the div's class according to the video file it is linked to

Is it possible to dynamically show or hide a div depending on the source of a video being played? I have a slideshow of videos running using bigvideo.js and I am looking for a way to toggle the visibility of certain divs based on which video is currently ...

IN to CM Conversion Size Chart

I'm just starting out and I want to make a size chart table that can convert between metric units. For example, I have table data with values in "inches" and I want to be able to switch it to "centimeters" with the click of a button. Some of the data ...

What is the best way to use absolute positioning in React Native to align an element with its grandparent?

I am trying to position a Font Awesome icon in a React Native project using absolute positioning relative to the grandparent element, rather than its direct parent. After some research, I came across the following information on this page: https://reactna ...

Instructions on creating a "ripple" effect on a webpage using CSS

I am attempting to create a wavy border effect where two sections meet on a page (refer to the image below). What is the most effective way to achieve this? The waves should be uniform in size. EDIT: To whoever flagged this as 'already answered' ...