Replacing defined WordPress CSS styles

I was considering posting this query on the Wordpress Stack Exchange platform, but it's more related to CSS than Wordpress.

Unless I need to delve into the CSS files of a plugin to customize the styles, should I go there to ask this question?

I am trying to override some important CSS styles that are being applied either by my theme (Genesis Framework with a customized Minimum Pro child theme) or the Gravity Forms plugin.

On this page, you can see that I have a form which resizes with the window. At 500px width, I want all select and input fields to have a width of 100%. I have identified the specific location in my media queries and added the code there. However, because there is a width: 95% !important; set somewhere (not in my stylesheet), my 100% setting is getting overwritten by 95%.

Here are the styles I want to override:

.gform_wrapper .ginput_complex input[type=text], 
.gform_wrapper .ginput_complex input[type=url], 
.gform_wrapper .ginput_complex input[type=email], 
.gform_wrapper .ginput_complex input[type=tel], 
.gform_wrapper .ginput_complex input[type=number], 
.gform_wrapper .ginput_complex input[type=password], 
.gform_wrapper .ginput_complex select {
    width: 95% !important;
}

.gform_wrapper .ginput_complex .ginput_right input[type=text], 
.gform_wrapper .ginput_complex .ginput_right input[type=url], 
.gform_wrapper .ginput_complex .ginput_right input[type=email], 
.gform_wrapper .ginput_complex .ginput_right input[type=tel], 
.gform_wrapper .ginput_complex .ginput_right input[type=number], 
.gform_wrapper .ginput_complex .ginput_right input[type=password], 
.gform_wrapper .ginput_complex .ginput_right select {
    width: 95% !important;
}

This is the overall override style I want to apply to ALL forms:

@media only screen and (max-width: 500px)
input, select, textfield {
width: 100%!important;
}

Since this is related to Wordpress, I don't have the HTML code, but I have captured a screenshot of the CSS styles (you can also view this by right-clicking on one of the inputs).

My question is, how can I overwrite these top-level styles with my media query set width? I have tried adjusting the styles but it seems like I might be missing something. Hopefully not?

UPDATE:

So, I have included the two different sets of styles provided by Alexander O'Mara and Fabio, but neither of them worked for me. I have commented out Alexander O'Mara's code in this snippet. You can see how I am implementing both of them.

@media only screen and (max-width: 500px) {

    a.alignright, img.alignright, .wp-caption.alignright {
            width: 100%;
    }

    .gform_wrapper ul li.gfield {
        width: 100%!important;
    }

    .ginput_left, .ginput_right { 
        width: 100%!important; 
        margin-top: 1.5em;
    }

    input, select, textfield { width: 100%!important;}

    .ui-datepicker-trigger { display: none;}

    .gform_wrapper .ginput_complex input[type="text"] {width: 100%!important;}

    .header-image .site-title a {
        background-size: contain !important;
        margin: 0 auto;
        max-width: 300px;
        padding: 11% 0;
    }


    /*.apply-now-form_wrapper .top_label input.medium, 
    .apply-now-form_wrapper .top_label select.medium {
        width: 100%!important;
        border: 2px solid blue;
    }*/

    html .gform_wrapper .ginput_complex input[type=text],
    html .gform_wrapper .ginput_complex input[type=url],
    html .gform_wrapper .ginput_complex input[type=email],
    html .gform_wrapper .ginput_complex input[type=tel],
    html .gform_wrapper .ginput_complex input[type=number],
    html .gform_wrapper .ginput_complex input[type=password],
    html .gform_wrapper .ginput_complex select {
        width: 100% !important;
        border: 2px solid red !important;
    }

}

I have set it up so that when the styles are applied, either a blue border shows up around them in Alexander O'Mara's snippet or a red border shows up when Fabio's snippet works. However, so far, as I toggle between them, I have had no luck.

It seems like it is completely ignoring these styles. Any insights on this issue would be greatly appreciated.

Answer №1

To override styles marked as !important, you can apply a more specific !important style using a different selector. For instance, to override the rules below:

.gform_wrapper .ginput_complex input[type=text],
.gform_wrapper .ginput_complex input[type=url],
.gform_wrapper .ginput_complex input[type=email],
.gform_wrapper .ginput_complex input[type=tel],
.gform_wrapper .ginput_complex input[type=number],
.gform_wrapper .ginput_complex input[type=password],
.gform_wrapper .ginput_complex select {
    width: 95% !important;
}

You can simply add html before each rule like this:

html .gform_wrapper .ginput_complex input[type=text],
html .gform_wrapper .ginput_complex input[type=url],
html .gform_wrapper .ginput_complex input[type=email],
html .gform_wrapper .ginput_complex input[type=tel],
html .gform_wrapper .ginput_complex input[type=number],
html .gform_wrapper .ginput_complex input[type=password],
html .gform_wrapper .ginput_complex select {
    width: 100% !important;
}

This method can be applied to other scenarios as well. Instead of using the gform classes, you can choose different classes that the elements you wish to override belong to.

Answer №2

It appears that the issue lies within the specificity of the style sheet targeting elements by their class names. Your general override will only affect elements without those classes, so you must adjust your CSS accordingly.

Therefore, you should modify

input, select, textarea {
    width: 100% !important;
}

to

.gform_wrapper .top_label input.medium, .gform_wrapper .top_label select.medium {
    width: 100% !important;
}
.apply-now-form_wrapper .top_label input.medium, .apply-now-form_wrapper .top_label select.medium {
    width: 100% !important;
}

and target the desired elements accordingly.

It seems redundant that your style override is identical to the existing declaration, but if you wish to apply a different style in the future, this solution should suffice.

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

Aligning an SVG icon at the center of a button

I have elements that are currently being used as buttons, but I want to switch them out for actual button tags. This would improve accessibility and allow keyboard navigation using the tab key to focus on my buttons. Each button contains a centered SVG ima ...

CSS Resizing the screen leads to misalignment of the footer layout

I am currently working on a page located at However, I have encountered an issue where the footer is not displayed properly when the screen size is changed. Below is the CSS code for the footer: #footer_1 { background: url("../images/bgfooter2.png") ...

place an image next to a div element

Currently, I have a table-like structure with two columns that I am struggling to make mobile responsive. Take a look at the code snippet below: setTimeout(function() { odometer.innerHTML = '1925' }) .fiftyFiftySection { back ...

Having trouble with CSS box alignment issues in the top margin

I am working on customizing a CSS box for a navigation menu. Here is the current CSS code: .navigation-div { text-align:right; margin-top:14px; box-shadow:0px 0px 10px rgba(0,0,0,0.47); padding: 0; color:#E3E3E3; background-color: ...

Implementing a customized mobile style sheet for Google Maps v3

Currently, I am attempting to enforce the Mobile stylesheet for Google Maps v3 JavaScript within a jQueryMobile application. Within the screen stylesheet, the zoom control consistently stays in the top left corner and my efforts to relocate it have proven ...

Merging the Select and Input elements side by side using Bootstrap grid system

Is there a way to combine all form group items like Select and Input using only the bootstrap framework? I attempted the method below, but there is an extra space between the Select and Input Box. Check out the DEMO ...

Incorporating fresh data from a node.js backend to refresh a webpage section

I'm currently working on creating an app that can retrieve the song a user is currently listening to using a web scraper. While I've managed to direct users to the page and display the current song title, they must manually refresh the entire pag ...

Achieving an IE7 opacity background while keeping the text unaffected

This is the given HTML code structure (view in JS Fiddle) How can I adjust the background color to be 20% opaque white while keeping the text black? It needs to be compatible with IE7. <ul class="menu"> <li class="first expanded active-trail ...

How can I prevent text highlighting on a website?

Is there a way to lock the copy button on my site without restricting the save as button, which is activated by right click? I want users to be able to save the website as an HTML file, but prevent them from copying text. Can this be achieved using Javas ...

Issues with hover styles and transitions not being correctly applied to newly appended elements in Firefox

Utilizing an SVG as an interactive floor plan, I have implemented a feature where hovering over different areas on the floor plan (<g> elements) causes them to expand and float above other areas. The element scaling is triggered by CSS, but I use jQu ...

The text relentlessly presses the button within the confines of bootstrap

I am facing an issue with the alignment of the buttons in my HTML code. As the text inside the <p> tag grows, it pushes the button to the right. I want all the buttons to be positioned in the bottom-right corner of every div regardless of the text si ...

Clicking on the ajax tab control in asp.net displays a single rectangular box - how can this be removed?

When using tab control in Ajax, I encountered an issue where a blue rectangle box appeared when clicking or opening the page. How can I remove this unwanted box? ...

Preventing Flash of Unstyled Content in ElectronJS Browser Windows

Upon creating a new BrowserWindow and utilizing loadURL to incorporate an html file within the renderer, there is a brief instance where unstyled content is displayed for approximately half a second before the css is loaded. window.loadURL('file://&a ...

Enable automatic scrolling when a button on the previous page has been clicked

Imagine there are two buttons (Button 1 and Button 2) on a webpage (Page A). Clicking on either button will take you to the same external page (Page B). How can we ensure that Button 1 takes you to the top of Page B, while Button 2 automatically scrolls do ...

Fascinating CSS quandary: does the transparency of a parent element impact the transparency of a child element that is absolutely positioned, but not in relation

Check out this test case: https://jsbin.com/merujogudo/1/edit?html,css,output Should the element with .test class be transparent or not? Note: The current state is as follows: In Chrome and Firefox (latest versions): transparent In IE11: opaque It wou ...

The concept of transparency and visual representation

Is there a way to prevent the opacity of the parent div from affecting the opacity of the img? <div class="parent_div" style="opacity:0.2"> <p>Some text</p> <img class="gif" style="opacity: 1;" src="ht ...

Leveraging Font Awesome and Material Icons within ngFor in Angular 2

I have a unique situation where I need to display a dynamic list of icons in a right side bar. These icons are added to the sidebar based on user actions and are displayed using the ngFor directive. The challenge here is that some icons come from Font Awe ...

A collection of items that mysteriously affix themselves to the top of the page as

Unique Context In my webpage, I have a specific div element with the CSS property of overflow: auto. Within this scrolling div, there is structured content like this: <h3>Group A</h3> <ul> <li>Item 1</li> <li>I ...

The placeholder text in the matInput field is not being displayed

As a newcomer to Angular, I am facing a challenge that has left me unable to find a solution. Below is the code snippet in question: <mat-form-field> <input matInput placeholder="ZIP" style="color:red;"> </mat-form-field& ...

Scrolling with Buttons in both Right and Left directions

I am working with three divs: left, middle, and right. The middle div will contain content, while the left and right divs are designated for buttons that will scroll the middle div. Specifically, I plan to display lists of pictures in the middle div. If a ...