Utilizing the style attribute instead of a class for tag styling

Currently working on an app utilizing ASP.NET Web Forms and aiming to incorporate bootstrap.css for styling purposes. However, encountering issues with button properties conflicting between the default Style.css and bootstrap.

This is the HTML markup:

<asp:Button ID="Button1" type="button"  CssClass="btn btn-primary" runat="server"
Text="View data" OnClick="Button1_Click" />

Default Style.css Properties:


input[type="submit"], input[type="button"], button {<br>
background-color: #d3dce0;<br>
border: 1px solid #787878;<br>
cursor: pointer;<br>
font-size: 1.2em;<br>
font-weight: 600;<br>
padding: 7px;<br>
margin-right: 8px;<br>
width: auto;<br>
}

Bootstrap Properties:


.btn-primary {<br>
color: #ffffff;<br>
background-color: #428bca;<br>
border-color: #357ebd;<br>
}<br>

The issue lies in the background-color being pulled from Style.css instead of bootstrap.

What could be causing this conflict?

Answer №1

The reason behind this phenomenon lies in specificity. The guidelines state:

  • If the declaration comes from a 'style' attribute rather than a rule with a selector, count it as 1, otherwise 0 (= a) (In HTML, values of an element's "style" attribute are considered style sheet rules without selectors, making a=1, b=0, c=0, and d=0.)
  • Calculate the number of ID attributes in the selector (= b)
  • Tally up the other attributes and pseudo-classes in the selector (= c)
  • Add up the element names and pseudo-elements in the selector (= d)

By concatenating these four numbers a-b-c-d (in a numerical system with a high base) we get the specificity.

In essence:

input[type="button"]   has specificity   0,0,1,1
.btn-primary           has specificity   0,0,1,0

The first example takes precedence due to its higher specificity, regardless of their order.

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

Implementing a Vue.js Scrollable Table

I am currently working on a table that is populated using the vue.js v-for method: <table> <tr><th>Name</th><th>Surname</th></tr> <tr v-for="user in users"><td>@{{user.name}}</td><td>@{ ...

Enhance your security with ASP.NET Web API Key Authentication in Azure

I am on the final stages of completing my ASP.NET web API project and I am looking to deploy it on Azure. I am wondering what would be the most effective method for implementing API key authentication for the users accessing the endpoints? For instance, s ...

Blazor Bootstrap - Issue with Dropdown Remaining Open When Clicking Outside Element

Having trouble implementing the default Bootstrap dropdown behavior in my Blazor Server app. I need the dropdown menu to close when I click anywhere outside of it. I attempted using @onfocusout, but ran into issues. If I click inside a form input and then ...

Utilizing Bootstrap for Efficient Image Alignment

I'm encountering an issue with my code and I am unsure of how to fix it. The current state of my code is different from the desired outcome https://i.sstatic.net/Ti1kK.jpg As you can see, the image above does not match the appearance of the image I ...

Attempting to implement a jQuery function to toggle the visibility of the submenu

Hey there! After spending some time digging into this, I've hit a roadblock. I'm struggling to figure out how to keep the sub-menu active even when the mouse is no longer hovering over it, similar to how the bootstrap menu functions. Here' ...

Activate an event on a shadow DOM element that is covered by an element in the light DOM (not directly related)

I am currently facing a challenge in retrieving the coordinates of a table cell within a shadow DOM. This table cell may have overlay elements displayed above it, which could span over multiple cells and may not necessarily be direct children of the cell I ...

What is the best way to determine the height of a DIV element set to "auto"?

When setting a fixed height on a div using jQuery, such as $('div').height(200);, the value of $('div').height() will always be 200. This remains true even if the content within the div exceeds that height and overflow is hidden. Is th ...

Align your content perfectly on a full-screen slick slider

Attempting to center content over a full-screen slick slider from kenwheeler.github.io/slick/, I used a flexbox but the content remains at the edge of the viewport. It seems like an issue with the position tag in the slick CSS, but I can't figure out ...

Encircle the text within intersecting divs

I am facing an issue with my main div that contains some text and 2 other overlapping divs. The text in the main div is getting overlapped by the other two divs. I need help to make the text in the main div wrap around the overlapping divs. It may sound s ...

Adjust image size based on the size of the screen

I am facing an issue with two images that are created for a 1024 x 768 resolution but I need to use them in a higher resolution. The challenge is to align these two images so that the circle from the first image falls between the second image. Although I ...

What is the functionality of CSS radio tabs?

Can anyone provide a breakdown of how the final section of this code operates? Specifically: [type=radio]:checked { } [type=radio]:checked ~ .content { z-index: 1; } I am brand new to CSS and wanted to experiment with creating interactive CSS tabs, whi ...

Autocomplete suggestions in Sublime Text 2 help users find the right files seamlessly

Do you know if Sublime Text 2 has the capability to automatically suggest directories and files when adding an external script, href, or other elements in a file? I find this feature very helpful when using Webstorm and would be interested in having the ...

After the scaffold generator, the Twitter-bootstrap buttons now feature text in a subtle gray

I seem to be facing a similar issue to what was discussed in this thread about Twitter Bootstrap displaying buttons with greyed text. The problem I am encountering is with a btn-info button that has a dropdown - after clicking on an item in the dropdown, t ...

Having difficulty modifying the styling of a paragraph within a div container

I have been working on a function that is supposed to adjust the font-size and text-align properties of a paragraph located within a div tag once a button is pressed. function customizeText() { document.getElementById('centretext').innerHTML = ...

Arrange the placement of a box outside of the primary DIV while maintaining a connection to it

I've encountered a hurdle that's hindering my progress. I'm attempting to shift a small box containing various options (like report, like, dislike, etc.) out from the main DIV while keeping it securely attached from the outside. Let me illus ...

Adjusting the height of table rows in Angular within a Razor cshtml file

Is there a way to set the height of a table row and ensure it respects the defined height without taking different heights? I tried using styles with white-space: pre-wrap, overflow: hidden, and text-overflow: ellipsis, but it's not working as expecte ...

Boost the dimensions of the content property within a CSS class

I am currently using the content property to display a dashed arrow "-->" in my CSS class. However, the arrow appears very small and I would like to increase its size directly in the CSS class itself. This arrow is meant to be displayed before each elem ...

Uploading a File to a Remote WCF Service via jQuery AJAX on Different Domains

I am currently facing some difficulties in achieving the following task and would really appreciate any guidance you can provide. My goal is to upload a file from my HTML5 site to a cross domain WCF service hosted in IIS 7.5. Additionally, I need to send ...

Can the ID attribute be used in the closing tag of an HTML element

Could this code be improved by properly closing the div with an ID: <html> <body> <div id="main"> </div id=main"> </body> </html> ...

Enhancing User Experience on Android Devices: Automatic Website Zoom-In Feature for Responsive Design

For the first time, I am delving into creating a responsive website design. I seem to be encountering difficulties when it comes to smartphones. I have been using the following meta-tag to ensure that the website loads "zoomed in". (I found this method on ...