Add a focus style to the submit button input

Having an issue with my CSS code. I can't get the style to apply to my submit button, but it works on the search field when focused.

Please review my code snippet and screenshot below.

What could be causing this problem?

CSS

.search-form .search-field {
    height: 10px;
    display: inline-block;
    margin: 0;
    width: 112px!important;
    border: 1px solid #e4e4e4;
    border-radius: 2px;
    padding: 10px 30px 10px 12px;
}

.search-form .search-submit {
    position: absolute;
    height: 32px;
    border-right: 1px solid #e4e4e4;
    border-top: 1px solid #e4e4e4;
    border-bottom: 1px solid #e4e4e4;
}

.search-form .search-field:focus {
    border: 1px solid #A5E7D6;

}


.search-form .search-field:focus + .search-form .search-submit {

 border-right: 1px solid #A5E7D6;
    border-top: 1px solid #A5E7D6;
    border-bottom: 1px solid #A5E7D6;

}

HTML / PHP

    <form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>">
    <label> <span class="screen-reader-text"><?php echo _x( 'Search for:', 'label' ) ?></span>
        <input type="search" class="search-field" placeholder="Search" value="<?php echo get_search_query() ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label' ) ?>" /> </label>
    <input type="submit" class="search-submit" value="Submit"></input>
</form>

https://i.sstatic.net/jXGWi.png

Answer №1

Your CSS code was spot on, just make this change:

.search-form .search-field:focus +  .search-submit

.search-form .search-field {
  height: 10px;
  display: inline-block;
  margin: 0;
  width: 112px!important;
  border: 1px solid #e4e4e4;
  border-radius: 2px;
  padding: 10px 30px 10px 12px;
  border-right: none;
}

.search-form .search-submit {
  position: absolute;
  height: 32px;
  border-right: 1px solid #e4e4e4;
  border-top: 1px solid #e4e4e4;
  border-bottom: 1px solid #e4e4e4;
  background:transparent;
  border-left: none;
}

.search-form .search-field:focus {
  border: 1px solid #A5E7D6;
  outline: none;
  border-right: none;
}

.search-form .search-field:focus +  .search-submit {
  border-right: 1px solid #A5E7D6;
  border-top: 1px solid #A5E7D6;
  border-bottom: 1px solid #A5E7D6;
  border-left: none;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<form class="search-form">
  <input class="search-field" type="text" placeholder="Search" />
  <button class="search-submit" ><i class="fa fa-search"></i></button>
</form>

Answer №2

My solution is the most effective

<form class="search-form">
  <input class="search-field" type="text" placeholder="Search" />
  <button class="search-submit" ><i class="fa fa-search"></i></button>
</form>

  <style>
.search-form .search-field {
  height: 10px;
  width: 112px;
  border: 1px solid #e4e4e4;
  padding: 10px 30px 10px 12px;
  border-right: none;
}

.search-form .search-submit {
  position: absolute;
  height: 32px;
  border: 1px solid #e4e4e4;
  background:none;
  border-left: none;
}
.search-form .search-field:focus ,.search-form .search-field:focus +  .search-submit  {
  border-color: #A5E7D6 !important;
  outline: none;
}
</style>

Answer №3

To resolve the issue, simply eliminate the use of the (+) operator in the CSS code below:

.search-form .search-field:focus .search-form .search-submit {

 border-right: 1px solid #A5E7D6;
    border-top: 1px solid #A5E7D6;
    border-bottom: 1px solid #A5E7D6;

}

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

I seem to be having trouble getting the home page to display properly in the app, even though I believe my code is correct. I would greatly appreciate any help in identifying the mistake

I have been struggling to render the HomePage using react Router for the past two days. I would greatly appreciate any support you can provide. Despite my numerous attempts, I have been unable to solve this problem. I even tried tools like chatgpt but al ...

Tips for preventing FormLabel components from turning blue when a radio button is selected

Currently, I am working on a Reactjs project that utilizes Material Ui components. In this project, I am tasked with creating a form to generate a new event where users can select the event location type from three options - In-Person, Hybrid, and Virtual ...

The AngularJS element fails to display on the screen

I am currently learning AngularJS and I am struggling to understand how components are linked to the view in the tutorial. I have created a component that is quite similar: angular.module('phonecatApp').component('nameList', { temp ...

What is the process for including an SVG file in my JavaScript .textContent?

I've been struggling to add an exclamation SVG to this section, but for some reason I can't make it work. I've searched on Google for a solution, but haven't found one yet. The SVG file is already downloaded and stored in my project fo ...

Adjust the appearance of input fields that exclusively have the value "1"

When designing my website, I encountered a problem with the style I chose where the number "1" looks like a large "I" or a small "L." I am wondering if there is a way to use JavaScript to dynamically change the font style for input fields that only contai ...

The header logo will have an absolute position to overlay the navigation menu when the screen is resized

I am currently working on a website layout that involves using position: absolute for the logo to overlay another div below it, purely for stylistic reasons. While I have achieved this effect, it doesn't translate well into responsive web design. When ...

Generate a variety of HTML ordered lists

Can anyone assist me in determining the type of ordered list shown below? What is the method to achieve an ordered list like this: (a) (b) (c) in HTML? ...

Update the class of the panel immediately prior to a click event

Is it possible to change the class before the animation starts or when opening/closing the panel? Currently, the class only changes after the animation has finished and the panel is already open or closed. Here is an example: http://jsfiddle.net/0b9jppve/ ...

Converting CSS to LESS with multiple classes sharing the same properties: step-by-step guide

I have some CSS code here that I'd like to convert into LESS format. Can you help me with that? .A .B h4, .A .B h4 a, .A .C h4, .A .C h4 a, .D h4, .D h4 a { color: #345e8a !important; display: inline-block; font-family: @font-family-sans ...

The CSS transition timing seems to be malfunctioning as not all elements are smoothly transitioning, specifically the text within the li and anchor tags is not

I'm attempting to achieve a smooth transition effect on a navbar when hovering over it, changing the color from one to another. The navbar contains a list of words, but I am encountering an issue where during the transition, there is a quick flash (ap ...

What is the best way to implement jQuery on my website?

Instead of copying all the example code here, you can check out the jQuery demo page: Demo Page I would like to integrate the Latest News example with scrolling text in red from the demo page into my website. The demo page also provides links to the sour ...

Enhancing Angular2 Forms with ngControl

I'm attempting to utilize ngControl in order to add error classes based on the user's input. However, I am facing challenges trying to make it work effectively. I can see that the appropriate classes are being set (line ng-invalid), but when I a ...

Struggling to locate the element using xpath on a JavaScript enabled website in Selenium with Chrome

I have been attempting to extract data from a website that utilizes Javascript. Despite researching similar inquiries on xpath in Selenium, I have not found a solution. I initially tried using requests, but as the JavaScript doesn't load completely, I ...

Displaying maximum number of items in each row using ngFor

Is there a way to automatically create a new row within the 'td' element after the ngFor directive has generated 10 image repeats? Currently, all the images are displayed in a single td and as more images are added, they start to shrink. <td ...

Hiding elements with CSS using the display:none property and using the :

Trying to display an image when hovering over another image. Works well in Safari, but Chrome and Firefox fail to load the image properly. Have searched for solutions related to visibility:hidden but none seem to solve this cross-browser issue. HTML being ...

Is there a way to transmit a div using Node.js?

Scenario: I am developing a web application that allows users to draw on a canvas, save the drawing as an image, and share it with others using Node.js. Current Progress: Drawing functionality (real-time updates on both clients). Saving the canvas as a ...

Choose Default Value in Drop-Down List in AngularJS when Page Loads

Within the realm of Angularjs, there exists a DropDown: <select ng-model="category" ng-change="categoryChanged(category)" class="form-control" data-ng-options="category as category.name for category in categories"> <option value="">Se ...

Express app unable to retrieve dropdown menu data using Node.js BodyParser

I am currently working on creating a pug file for a signup form and I'm encountering an issue with the drop-down menu not functioning. How can I properly include my drop-down menu in the body parser? I initially assumed it would be processed with json ...

Adjusting the size of HighCharts HighMaps with a custom function

Simple query here (I believe) I have a DIV with the class "container" acting as my Map. The Highcharts plugin I'm using is responsive, but it only resizes when the window does. I'm looking to manually trigger a resize without adjusting my windo ...

The CSS stylesheet appears to be properly linked, however, it is not displaying correctly on the preview page

Here are the locations of my folders: index.ejs can be found inside Markdown Blog/views/articles This is where my css stylesheet is located: ../../css/styles.css Despite ctrl+clicking the path and successfully navigating to the css file, the styles do no ...