How can I split my button into two distinct colors?

Here is a button example with CSS styling:

CSS

.Btns {
        width:200px;              
        height:75px;
        background-color:lightblue;
        color:black;
        font-weight:bold;

    }

HTML:

<button id="btnProduct" type="button" class="Btns" >

JQUERY:

$("#btnProduct").html('<span style="background-color:red;width:100px">Production:</span></br></br><span class="blue">55</span>');

I am trying to make the top part of my button red by using jQuery. However, even though I have set the span width to 100%, it still does not fill the entire upper area of the button.

$("#btnProduct").html('<span style="background-color:red;width:100px">Production:</span></br></br><span class="blue">55</span>');
.Btns {
  width: 200px;
  height: 75px;
  background-color: lightblue;
  color: black;
  font-weight: bold;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button id="btnProduct" type="button" class="Btns">
 
</button>

Answer №1

There is no requirement for JavaScript or any other unconventional tools to achieve this, simply implement the following CSS code:

.ButtonStyle {
  width:200px;
  height:75px;
  background:linear-gradient(to bottom, red, red 50%,  lightblue 50%, lightblue);
  color:black;
  font-weight:bold;
}

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 styling of a CSS class in Internet Explorer may not be applied correctly if there are multiple elements sharing the same class name

For nearly a full week now, I've been plagued by a persistent issue! Here's the situation: I have 6 step tabs - step 1, step 2, and so on. Each tab has a CSS class called "locked" and "active." "Locked" - this style features top: 3em;, causing ...

What could be causing my CSS/Layout to alter once AJAX/JavaScript has been executed?

When the user clicks, an AJAX call is made to retrieve data from a third-party API. The frontend/layout renders correctly before this action; however, after the data is fetched and displayed in the frontend, the layout changes. Upon debugging multiple tim ...

Enhance your visual content by incorporating text onto images with CSS/Bootstrap5

I'm having trouble getting my rows and columns to display on top of my background image. I've been struggling with this issue for a while now. Any assistance on this matter would be greatly appreciated! I'm fairly new to this, so if it&apos ...

State of Active Scroll group

How can I dynamically add the "active" class to a link based on which section it has scrolled to? I want the active state to be applied without a hover effect, only when the corresponding section is currently in view. #pagemenu{ display: block; positio ...

When hovering over elements, my li tags undergo a transformation

I am working on a simple menu code, which is just a list of items. ul li { position: relative; top: 55px; height: 30px; background: #212; display: inline-block; width: 29%; margin: 1%; margin-bottom: 0; padding: 5px; -webkit-border-t ...

When the hover effect is triggered, the background animation smoothly resets back to its initial position once the

I have a picture with a clear background that I want to add a CSS3 background animation to when the mouse hovers over it. Here is the CSS code I am currently using: @keyframes in { from {background-color: #fff;} to {background-color: #900;} } @-webkit-k ...

Ensure the clarity tabs labels have the padding-left CSS property added

In my project, there are 2 clarity tabs (you can view the StackBlitz reference here). https://i.sstatic.net/jhLcn.png I want to apply the padding-left property specifically to Tab1 (the tab label itself, not the content) in order to create some space aro ...

Achieving and maintaining the center alignment of a horizontal dropdown menu

Struggling with creating a fixed, 100% width nav bar that stays centered when the page is resized? The drop down menu headings are causing issues as they seem to float left instead of staying centered. Not sure how to fix it? Take a look at the live resul ...

Tips for preventing the appearance of two horizontal scroll bars on Firefox

Greetings, I am having an issue with double horizontal scroll bars appearing in Firefox but not in Internet Explorer. When the content exceeds a certain limit, these scroll bars show up. Can someone please advise me on how to resolve this problem? Is ther ...

The Border Radius Problem in Google Chrome

Greetings! I am currently working on a project for a website and have encountered an issue with the gallery on the projects page. The images are meant to be displayed as circles, and when hovered over, they should maintain their circular shape and have a b ...

Firefox does not support padding-top in pseudo elements, unlike Chrome and Safari which do

I am aiming to create three square boxes that adjust their size based on the browser's dimensions. Each box will contain only one line of text, so I plan to use padding to fill any extra space. My website utilizes flexbox, and I initially thought I h ...

Prevent fields from being edited until the main field is filled out

Currently, I am in the process of designing a form with three primary fields at the top – Organization Name, Department, and Address. The other fields are not relevant for now. It is imperative that the user inputs data into the Organization field before ...

Update the contents of a different element upon hover using dynamic PHP functionality

Often, solutions involving the use of java script/jquery to achieve a specific behavior require knowing the exact id of the element. However, in dynamic situations where the id is not always known, it can pose a challenge. In my case, I'm generating a ...

Issue with Chrome's -webkit-object-fit not functioning properly

When trying to use -webkit-object-fit in the stylesheet on Chrome, I encounter an error stating "unknown property name". Is this property just not supported by Chrome? It seems that -webkit-border-image is working fine. ...

Bizarre bouncing dots created with CSS animations

This is the CSS class I created for my Loader: .loading{ color:black; position:fixed; width: 270px; height:100px; font-size:20px; top:0; bottom: 0; left: 0; right: 0; margin: auto; transition: 1s ease-out; opacity:1; } .loadin ...

Challenges with resizing floating divs

As a beginner in Web Development, I am tasked with creating a web portfolio for an assignment. In my design layout, I have a navigation bar in a div floated left, and a content div floated right serving as an about me section containing paragraphs and lis ...

Using Tailwind's media query functionality within ReactJS

I have a situation where I have a div containing an image within it. I am attempting to use media queries from the Tailwind CSS framework. <div className="flex"> <img src="/assets/logo.png" className="h-20 md:w-2" ...

What is the best way to eliminate the white border from my website's code?

If you'd like to see the code in action, check out my JSFiddle html, body { height: 100%; } #background { height: 100%; background: url(http://phosproject.com/wp-content/themes/phos_theme/images/7.jpg); no-repeat center cente ...

Struggling with uploading an image in a react application

Hey everyone, I'm encountering some issues with importing images into my project. Previously, I was able to import images successfully in my old project using the same method that worked before, but it's not working this time around. The way I im ...

Steps for implementing overflow scroll on a div with an unspecified height

The layout I'm working with looks like this: .page { width: 360px; height: 704px; border: 1px solid red; } header { height: 10%; width: 100%; display: flex; align-items: center; justify-content: center; background-color: lightblue; } ...