What could be the reason for the body background color refusing to change

I'm currently working on a JavaScript calculator project and I'm using this code snippet from codepen. The issue I'm facing is that despite setting the body background color to black, it still appears white. Could there be a spacing problem causing this unexpected behavior? This is something new for me and I haven't encountered it before :( Any tips on how I can resolve this issue would be greatly appreciated! Thanks in advance...

html, body{
    background-color:black;
  }
 
  #calcOutput{
  
    width:250px;
    height:75px;
    border-top-left-radius:2em;
    border-top-right-radius:2em;
    margin-right:auto;
    margin-left:auto;
    margin-top:20px;
    padding-top:20px;
  }
  
  #calculator{
    background-color:grey;
    width:250px;
    padding-top: 20px;
    padding-bottom: 30px;
    border-bottom-left-radius:2em;
    border-bottom-right-radius:2em;
    margin-right:auto;
    margin-left:auto;
  }
  #steps{
    padding-left:50px;
    font-size:2em;
  }
  .bigButton{
    width:93px;
  }
  a{
    margin: 5px;
    width: 2.6vw;
    height: 2.6vw;
  }
   
<head>
    <title>Document</title>
     
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
     <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
     
</head>
<body>
   
    <div class="text-center">
      <h1>Calculator</h1>
      <h2>JS calculator</h2>
    </div>
    <div id ="calcOutput">
      <span id= "steps">0</span>
      <hr/>
    </div>
    <div class="text-center" id="calculator">
      <a class="btn btn-danger" id="deleteAll">AC</a>
      <a class="btn btn-danger" id="backOne">CE</a>
      <a class="btn btn-primary" id="/">/</a>
      <a class="btn btn-primary" id="*">*</a>
        <br/>
     <a class="btn btn-primary" id="7">7</a>
    <a class="btn btn-primary" id="8">8</a>
    <a class="btn btn-primary" id="9">9</a>
    <a class="btn btn-primary" id="-">-</a>
      <br/>
      <a class="btn btn-primary" id="4">4</a>
    <a class="btn btn-primary" id="5">5</a>
    <a class="btn btn-primary" id="6">6</a>
    <a class="btn btn-primary" id="+">+</a>
      <br/>
      <a class="btn btn-primary" id="1">1</a>
    <a class="btn btn-primary" id="2">2</a>
    <a class="btn btn-primary" id="3">3</a>
    <a class="btn btn-primary" id=".">.</a>
      <br/>
      <a class ="btn btn-primary bigButton" id="0">0</a>
      <a class ="btn btn-primary bigButton" id="total">=</a>
    </div>    
</body>
</html>

Answer №1

since you are utilizing bootstrap, which defines the body background as white, you have two options in this scenario:

Option One

utilize !important

html, body{
    background-color:black !important;
  }
 
  #calcOutput{
  
    width:250px;
    height:75px;
    border-top-left-radius:2em;
    border-top-right-radius:2em;
    margin-right:auto;
    margin-left:auto;
    margin-top:20px;
    padding-top:20px;
  }
  
  #calculator{
    background-color:grey;
    width:250px;
    padding-top: 20px;
    padding-bottom: 30px;
    border-bottom-left-radius:2em;
    border-bottom-right-radius:2em;
    margin-right:auto;
    margin-left:auto;
  }
  #steps{
    padding-left:50px;
    font-size:2em;
  }
  .bigButton{
    width:93px;
  }
  a{
    margin: 5px;
    width: 2.6vw;
    height: 2.6vw;
  }
   
<head>
    <title>Document</title>
     
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
     <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
     
</head>
<body>
   
    <div class="text-center">
      <h1>Calculator</h1>
      <h2>JS calculator</h2>
    </div>
    <div id ="calcOutput">
      <span id= "steps">0</span>
      <hr/>
    </div>
    <div class="text-center" id="calculator">
      <a class="btn btn-danger" id="deleteAll">AC</a>
      <a class="btn btn-danger" id="backOne">CE</a>
      <a class="btn btn-primary" id="/">/</a>
      <a class="btn btn-primary" id="*">*</a>
        <br/>
     <a class="btn btn-primary" id="7">7</a>
    <a class="btn btn-primary" id="8">8</a>
    <a class="btn btn-primary" id="9">9</a>
    <a class="btn btn-primary" id="-">-</a>
      <br/>
      <a class="btn btn-primary" id="4">4</a>
    <a class="btn btn-primary" id="5">5</a>
    <a class="btn btn-primary" id="6">6</a>
    <a class="btn btn-primary" id="+">+</a>
      <br/>
      <a class="btn btn-primary" id="1">1</a>
    <a class="btn btn-primary" id="2">2</a>
    <a class="btn btn-primary" id="3">3</a>
    <a class="btn btn-primary" id=".">.</a>
      <br/>
      <a class ="btn btn-primary bigButton" id="0">0</a>
      <a class ="btn btn-primary bigButton" id="total">=</a>
    </div>    
</body>
</html>

Option Two

In your html page, place your customized css reference below the bootstrap css reference so that your custom css can override the bootstrap css.

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="path/to/your/customized/style.css">

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

Create a CSS style to set the background with a half height positioned behind the

I am looking to create a div with a background and overlay effect. Here is what I have done so far: I want it to look like this: body { background: blue; } .wrap { height: 300px; width: 600px; margin: 0 auto; background-color: #000000; } .b ...

What is the precise width?

Here's a question for you: an HTML element has the following styles applied to it - width: 150px, padding: 3px, border: 4px, margin: 7px. What is the actual width of the element? I'm confused by this question because it specifies that the width ...

Is there a way to effortlessly scroll an element when the CSS overflow property is designated as auto?

I need help with creating a testimonial section where two divs automatically scroll inside a fixed-height container. Currently, only one div is scrolling while the other remains static in my code. I have implemented JavaScript for automatic scrolling wit ...

What is the process for incorporating icons and choices into the header bar?

Seeking advice on how to incorporate an icon into the right side alignment of a simple blank header on my webpage, similar to the image provided. I have searched through numerous threads on StackOverflow without finding a suitable solution. Could someone s ...

Simple HTML alignment tool instead of Bootstrap

Are there any other options besides Bootstrap for a predefined CSS library that can help align and customize an HTML page quickly? I have been using ASP.NET and Bootstrap for my development, but I'm looking for something new. If there is another libr ...

Adding div elements using checkbox switch

In this code snippet, my aim is to display costs based on checkbox selection and generate corresponding totals in the bottom row when the checkboxes are toggled. The goal is to allow users to choose relevant items and have the total cost calculated accordi ...

Having difficulties with my online form

Each page of my website features the following form: <section class="footer-one"> <form action="sendmail.php" method="post" onsubmit="return validateForm()"> <div> <div class="row half"> <div class="6u"> <input type="text ...

Is it possible to send both props and a function within a single onClick event in React?

After spending hours searching for the right solution, I have yet to find it. Let me explain my situation clearly. I have an Image Carousel feature on my website that should open when a user clicks on an image. I have 5 images on the website, and when a us ...

Learn how to create an endless scrolling effect on a static webpage using only pure JavaScript

Looking to achieve an Infinite Page Scroll Effect similar to Twitter without relying on jQuery or any other library, using pure JavaScript. I'm new to JavaScript and need assistance with implementing this effect in search results displayed within a La ...

Sorting Columns in JQuery Datatables

Encountering an issue with JQuery DataTables (datatables.net) where it takes 2 clicks to sort the columns when there are only 2 rows in the table. The first column sorts on the first click, but subsequent columns require multiple clicks. Despite testing th ...

Using Javascript, delete all chosen HTML elements containing innerText

Looking to extract certain HTML tags from a block of code in TextArea1 and display the modified output in TextArea2 upon clicking a button. <!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8&quo ...

Using SCSS to target a sibling class when hovering over an element with CSS

Is there a way to alter styles of a sibling element on hover using only CSS? I attempted something similar but was unsuccessful. HTML: <ul> <li class="item active">name1</li> <li class="item">name2</li> <li clas ...

Tips on adding style to your jQuery autocomplete dropdown

I am currently utilizing jQuery autocomplete functionality. I have configured it to communicate with a service and retrieve records: <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1 ...

A Guide on Integrating a Javascript Reference into HTML while Displaying a PHP Object

Our website relies heavily on PHP modules to generate objects that are essential for constructing our web pages. Some of the key modules we have include: Anchor (ahref) Button CheckBox ComboBox DateTime Email Label Note Password Phone RadioButton RichTe ...

Positioning Backgrounds with Padding in DIV Elements

I am trying to figure out how to add a check mark next to text in a button with specific styling. I have managed to get the check mark aligned properly using Background:left center, but I also want to add padding and adjust spacing. Is there a way to achie ...

Prevent a HTML button from being clicked multiple times before it disappears (using Django)

I am currently working on a Django project that involves events where users can join by adding their user_id and event_id to the attend model. On the event page, there is a join button form that, when clicked, adds the user to the attendees list. After cli ...

What is the Best Way to Send JavaScript Variables to MYSQL Database with PHP?

I am having trouble sending my variable to a MySQL database. The database only displays the variable when using the HTML input tag. The error message I received was "Undefined index: rate & amount." Seeking assistance to resolve this issue. Thank you! ...

The Chrome browser allows interaction between two separate divs, where a button located in one div can impact

One issue I encountered involves a button located within a div that has unintended consequences for another div. Here is the basic structure of the elements: <div> <div> <div> <div> <butto ...

Unveiling the method to fetch the emitted value from a child component and incorporate it into the parent component's return data in Vue

How can I retrieve the title value passed by the Topbar component and incorporate it into the data() return section? I attempted to create a method to pass the value, but was unsuccessful despite being able to successfully log the value in the parent file. ...

Dynamically updating the scroll area in Ionic using real-time data

Hello, I am currently working on an Ionic project and have created a code pen for it. At the moment, the code pen just displays an image with two buttons for zooming in and out. However, I have encountered an issue. When I click on zoom in and scroll to ...