Button style not being affected by CSS

I'm having trouble changing the background color of a button in CSS. The CSS link is working perfectly fine, and the button changes color when I attempt to apply Bootstrap or use DOM to change it, but not when I use pure CSS.

Here's the code snippet:

// let sexybutton= document.querySelector('.sexy');

// sexybutton.style.backgroundColor="red";

// console.log(sexybutton.style);

//Currently commented out because I don't want to do it this way. Adding this here to mention that the button style does change using this method.
.body{
    background-color: #CCD6A6;
}

.sexy{
    background-color: red;
}
HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://kit.fontawesome.com/fdee82af88.js" crossorigin="anonymous"></script>

  <link rel="canonical" href="https://getbootstrap.com/docs/4.0/examples/album/">
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Permanent+Marker&display=swap" rel="stylesheet">

  <!-- Bootstrap core CSS -->
  <link href="https://getbootstrap.com/docs/4.0/dist/css/bootstrap.min.css" rel="stylesheet">

  <!-- Custom styles for this template -->

  <link rel="stylesheet" href="style.css">
</head>
<body class="body">
    <button class="sexy" type="submit">Click this</button>
</body>

<script src="index.js"></script>
</html>

Answer №1

It seems like your CSS syntax needs some adjustments. Remember that the semi-colon ; should be placed after each CSS property, not at the end of each CSS rule.

.background{
    color: blue;
}

.container{
    font-size: 16px;
}
<!-- Include Bootstrap stylesheet -->
<link href="https://getbootstrap.com/docs/4.0/dist/css/bootstrap.min.css" rel="stylesheet">

<body class="background" >
    <button class="container" type="submit">Click here</button>
</body>

Answer №2

CSS doesn't follow the same syntax rules as C/C++ or any other language that requires a semicolon at the end of each line. You can't just type a semi-colon to end a style.

What you wrote was:

.body{
    background-color:#CCD6A6
};

.sexy{
    background-color: red
};

but the correct way is:

.body{
    background-color:#CCD6A6;
}

.sexy{
    background-color: red;
}

In CSS, you must include a semicolon at the end of each line. For example, color: red; instead of };

Answer №3

This is illegible due to incorrect semi-colon placement.

.body{
background-color:#CCD6A6
};

.sexy{
background-color: red
};

Here is the corrected version:

.body{
background-color:#CCD6A6;
}

.sexy{
background-color: red;
}

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

When the mouse is moved, display a rectangle on the canvas

I am having an issue with drawing a rectangle on canvas. The code below works fine, except that the path of the rectangle is not visible while the mouse is moving. It only appears when I release the mouse button. Any assistance would be greatly appreciate ...

Utilizing the power of datatable.js to refine and sort through first and last

I'm currently working on an application that uses a dataTable to filter first names and last names. I have separate text-fields for entering first name and last name, but the filtering function is applying to both fields. I need a way to ensure that o ...

Arranging columns with Bootstrap

I have a unique design using Bootstrap as shown below: <div class="row"> <div class="col-md-2"> 1 </div> <div class="col-md-8"> 2 </div> <div class="col-md-2"> 3 </div> </d ...

Prolong the duration of a Facebook SDK access token to 60 days using C#!

How can I extend the 2-hour access token to a 60-day access token using the C# SDK? Can someone provide a sample code snippet for this specific section where the code has already been substituted with the 2-hour access token? Background: Despite trying va ...

Geolocation ranking in Elasticsearch

I am experiencing constant errors with sorting in my elasticsearch query. The query is shown below: query { "query": { "bool": { "filter": { "geo_distance": { ...

Setting the width of a wizard modal to auto

I am facing an issue with my modal wizard. The width of the first modal is perfect, but when I navigate to the second and third modals by pressing next, they automatically take on a fixed width size that I need to modify. I have tried declaring the width ...

Is there a way to bring in a variable from the front end script?

Is it possible to transfer an array of data from one HTML file to another? If so, how can this be done? Consider the following scenario: First HTML file <script> let tmp = <%- result %>; let a = '' for (const i in tmp){ ...

Guide to activating form elements using a JQuery function

I need help setting up a form with 11 rows and 11 columns. By default, the form fields should be disabled, but when I click on an "EDIT" button, they should become enabled. Any assistance would be greatly appreciated. Thank you in advance. Here is my edit ...

Encountered a node-pre-gyp installation error while running npm install

As I attempted to follow the React in Action book, I encountered an issue with the project repo - book's project repo Upon running npm install on Ubuntu, I encountered the following error: npm ERR! errno 1 npm ERR! <a href="/cdn-cgi/l/email-prote ...

Looking to set up a layout with two columns in the first row and one column in the second row, then combine the two columns using HTML and CSS

My goal is to set up a layout with two columns in the first row, one at 70% width and the other at 30%, and a single column in the second row. However, when I add text and images, the content doesn't position as expected: body { background-image: ...

Accessing a variable from an external JavaScript file using jQuery

Can someone help me out with this issue I'm facing? I am having trouble getting a string returned to a variable in my embedded Javascript code. token.js: function token () { return "mysecretstring"; } HTML Code: <!DOCTYPE html> <h ...

How to Incorporate Routes as Subroutes in Express.js

I am currently working on constructing a modular express.js server with a well-organized structure. I have experimented with using routes similar to components in React. index.js var syncsingle = require('./XYZ/syncsingle'); app.get('/sync ...

Is there anyone available to assist me with troubleshooting a login session that is not functioning properly

I'm a beginner in php and I'm facing an issue with logging in as a different user in a project. After logging out and returning to the browser, the previous user's window keeps opening. Below is the code for index.php: <?php if ( ...

Converting the source to your image assets in Angular: A step-by-step guide

I am looking to update the source code. Here is an example: <div *ngFor="let item of meal.allergenList" class="btn btn-primary"> <img [src]="item" alt=""> </div> I want to make the following co ...

What benefits come from employing jQuery for data storage techniques?

After learning more about jQuery data storage, I have a question. Is there any advantage to using either of these methods: $('#editCity').data('href', "xx"); var a = $('#editCity').data('href'); or $('#edit ...

Sorting objects in Angular using ng-options

I am working with an object that has the following structure: { 3019: 'Javascript', 3046: 'Css' } After that, I display this object in a select element like this: <select ng-model="langChoosed" ng-options="key as val ...

What is the method for sending information to an HTML file with Express.js?

I am currently wrapping up a project for my web development bootcamp and I am facing some difficulties with adding new data to my HTML using a form. Although I have set up the HTML properly, I am not able to see any new data when I try to post it. Addition ...

Using Typescript: Defining a function parameter that can be either of two interfaces

While browsing through this specific question, I noticed that it was somewhat related to my current issue, although there were notable differences. In my scenario, I have a function named parseScanResults which accepts an object as its argument. This obje ...

What is the best method for sending a document to a web API using Ajax, without relying on HTML user controls or forms?

I have successfully utilized the FormData api to upload documents asynchronously to a web api whenever there is a UI present for file uploading. However, I now face a situation where I need to upload a document based on a file path without relying on user ...

Perform a task upon clicking the JavaScript menu

Implementing dropdown menu items using a text link with JavaScript and CSS. You can view a demo here. I am looking to trigger an action when each menu item is clicked. Currently, they are not behaving as expected. HTML: <span class="inline-dropdown- ...