How to avoid overlapping (overlapping) <select> elements in a form on the same page?

Asked

Viewed 953 times

3

I use wordpress as CMS and created a form with the plugin WPCF7 (Contact Form 7). It turns out that some form elements such as select, checkbox and radio button overlap each other in a way that I can’t adjust them. Ver Imagem

With the help of jQuery I can define a z-index value for each element <select> generated by the WPCF7 plugin shortcode, however, they still overlap each other or are superimposed by other form elements such as checkboxes, as we can see in the image.

Even defining a z-index value for the elements <select></select> form with the help of jQuery, they continue to be affected by this effect "overlapping".

Is there a solution in css and/or jQuery that sets the z-index value in a "universal context" for all form elements on a page? Or would this be something related to the WPCF7 plugin?

SOLUTION - Case study:

For those who are experiencing such a situation, just do as mentioned in the answer chosen for this question, i.e., use css to define a z-index value for a given form element.

Regarding the Contact Form 7 plugin, those who use it know that we usually use "shortcodes" to generate the form elements. Thus, following the reasoning of the answer to this question, I solved the problem as follows:

1- Surround the WPCF7 shortcode that represents the form element affected by the problem with a tag <div> and define a class to be handled by css.

Ex.:

<div class="select-profissao">[select* select-profissao id:cd-dropdown class:cd-select "Enfermeiro(a)" "Técnico(a)"]</div>

Where [select* select-professional id:cd-dropdown class:cd-select "Nurse(a)" "Technical(a)"] is the shortcode of the Contact Form 7 plugin responsible for generating the element <select></select>.

the shortcode mentioned above generates the following html markup:

<div class="select-profissao">
<select class="cd-select" id="cd-dropdown">
<option value="-1">EU SOU PROFISSIONAL</option>
<option value="Enfermeiro(a)">Enfermeiro(a)</option>
<option value="Técnico(a)">Técnico(a)</option>
</select>
</div>

2 - Then write the css:

.select-profissao {
z-index: 1000;
position: relative;
} 

Just follow the same structure for other elements <select></select> created with the plugin and adjust the z-index value of each element independently.

  • 1

    Could you post the solution as a response below? It is more suitable to the website format.

1 answer

1


You already tried to use this?

<style>
    *{
        z-index: 1000;
     }
</style>
  • 1

    Thank you @Samir Braga! I was insisting on achieving the result using javascript/jQuery only. That was the solution. I simply wrapped the Contact Form 7 plugin’s shortcode with a <div> and defined a class, and then used css to adjust the z-index value of the form’s select elements. <div class="select-professional"> [select* select-professional id:cd-dropdown class:cd-select "Nurse(a)" "Technical(a)"] </div> and css: . select-professional { z-index: 1000; position: relative;}

  • Give a like there in my answer. :)

  • Can you explain the concept behind the solution? So that future visitors to this topic understand why the problem was occurring.

  • The asterisk ( * ) in the css means universal, ie for all page elements. For example: *{ z-index: 1000; background: #f1f1f1; width: 100%; } All elements will end up with z-index: 1000, with background: #f1f1f1 and 100% page width.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.