Trouble with CSS transition on input field within a form

Having trouble getting my input element to transition properly. It seems like the transition tag is not affecting the input element, and I can't figure out why.

.mainForm {
  border-radius: 50px;
  border: springgreen 5px solid;
  width: 50%;
  padding: 50px;
  margin-top: 50px;
  background-color: rgba(150, 255, 150, 0.5);
}

input {
  border: rgba(50, 51, 52, 0.5) solid 5px;
  border-radius: 50px;
  font-size: 20px;
  outline: none;
  padding: 10px 25px;
  transition: width .35s ease-in-out;
}

input:focus {
  width: 75%;
}

button {
  border-radius: 50px;
  padding: 10px;
  border: rgba(50, 51, 52, 0.5) solid 5px;
  transition: width .35s ease-in-out;
}

button:hover {
  background-color: rgba(50, 51, 52, 0.25)
}
<center style="margin-top: 50px;">
  <h1 style="display:inline;font-family:courier;">
    <span style="font-family:fantasy;">
                Google
                </span> Search Replica</h1>
  <form method="get" action="https://google.com/search" autocomplete="off" class="mainForm">
    <input name="q" placeholder="Search...">
    <button type="submit"><img src="https://image.flaticon.com/icons/png/512/54/54481.png" width="20px"></button>
  </form>
</center>

Answer №1

Make sure to specify a width for the normal state as well in order for the transition to function properly. All properties affected by the transition must have defined states for the transition to occur smoothly:

<!DOCTYPE html>
<html>
    <head>
        <title>Project003 || Google search replica</title>
        <style type="text/css">
            .mainForm{border-radius:50px; border:springgreen 5px solid;width:50%; padding:50px;margin-top: 50px; background-color:rgba(150,255,150,0.5);}
            input{width:25%; border:rgba(50,51,52,0.5) solid 5px;border-radius:50px;font-size:20px;outline:none;padding:10px 25px;transition: width .35s ease-in-out;}
            input:focus{width:75%;}
            button{border-radius:50px;padding:10px;border:rgba(50,51,52,0.5) solid 5px;transition: width .35s ease-in-out;}
            button:hover{background-color:rgba(50,51,52,0.25)}
        </style>
    </head>
    <body>
        <center style="margin-top: 50px;">
            <h1 style="display:inline;font-family:courier;">
                <span style="font-family:fantasy;">
                Google
                </span>
                Search Replica</h1>
            <form method="get" action="https://google.com/search" autocomplete="off" class="mainForm">
                <input name="q" placeholder="Search...">
                <button type="submit"><img src="https://image.flaticon.com/icons/png/512/54/54481.png" width="20px"></button>
            </form>
        </center>
    </body>
</html>

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

Determine the value of an option based on a different element

Here is the HTML markup I am working with: <div class="wrap_select"> <span class="select" id="selectdateRange">Today, 25 March, Sun</span> <select class="styled" id="dateRange" name="dateRange"> <option value ...

Electron Applies a 1px Border Surrounding the titleBarOverlay

I am completely new to Electron and Node.js, so please forgive me if I misuse any terminology. Currently, I am developing a Windows 10 application and I would like to customize the title bar area of my app similar to other Electron applications such as Gi ...

Tips for adjusting the class of elements in neighboring rows of an HTML table with the help of jQuery's nextAll() selector

While attempting to switch classes using the jQuery selector .nextAll(':lt(3)'), I encountered an issue. The class change does not take effect on new rows of HTML tables. It seems like the class change for the next 3 cells is only being applied ...

Tips for Customizing the Active Class in Bootstrap 3

After spending the last 3 days searching online and trying various examples, I still can't figure out how to style the active class properly. Below is the HTML code snippet: <div class="navbar navbar-inverse navbar-fixed-top" id="mainHeader" ...

Querying data-bind attribute value from span tag using Selenium WebDriver

I am trying to extract the content within this tag: <span> <a class="jsk-sa-dialog link-lightbox-valores" data-bind="attr: { href: '#sa-valor-' + $root.types().id }" href="#sa-valor-2"> Link to click that opens a new window ...

The try and catch block in JavaScript is failing to correctly capture the HTTP status

I have a function that successfully posts JSON to an API endpoint. Here is the code I am using: function sendValuesPageLoad(){ var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { try { if (xhr.readyState === ...

Mapping an array in ReactJS based on the specific order of another array

In my experience with Unmitigated, the answer proved beneficial. If you're arriving from a Google search, please scroll down for more information. Order: [ "567", "645", "852", "645", "852", "852 ...

What specific CSS selector should be targeted in order to modify the appearance of this button?

I'm attempting to alter the appearance of a button within my Wordpress site, but I've hit a roadblock in identifying the correct element to modify. So far, I've tried targeting: .input#chained-quiz-action-1, however, the button stubbornly re ...

Construct a table featuring nested rows for every parent entry

Table 1 orderid customerName totalCost ---------------------------------- 1 Jonh £200.00 2 Ringo £50 Table 2 orderlineid orderid productName productPrice Quantity ----------------------------------------------- ...

Can Spring Boot be set up to return JSON instead of HTML for InvalidTokenException when configuring OAuth2?

When testing my Spring Boot application, I realized that querying one of my REST endpoints with an invalid token using Postman resulted in a response content in HTML format instead of JSON. The endpoint correctly responded with 401 InvalidTokenException, b ...

unable to locate the nearest available table

This is my HTML code: <div id="dvUser"> <table id="tblUser" > <tbody> <tr> <td> <input class="sfCheckBox" type="checkbox" title="view" checked="checked"> </td> </tr> <tr> <td> <input class="sf ...

Deleting entries from a selection of items in a list generated from an auto-fill textbox

I have successfully implemented an auto-complete Textbox along with a styled div underneath it. When the client selects an item from the Textbox, it appears in the div after applying CSS styling. Now, I am looking to create an event where clicking on the s ...

Navigating towards a particular aspx webpage

I am working on a project in asp.net and encountered an issue on one of my aspx pages. The problem is that there are two options to choose from, Bug and Change Request. When a user clicks on Bug, they should be directed to IssueDetails.aspx, while clicking ...

Use CSS to apply word-breaking to the <p> element that contains an <a

I am working with HTML and have the following code: <p>Read the <a target="_blank" class="highlight" href="www.url.com">'Design Network Hierarchy and Settings'</a> chapter in your version's user guide to learn how to creat ...

What is the best way to properly showcase text retrieved from a database in HTML?

I am developing an application with the use of PHP and MySQL. The data in the database is stored as shown below: https://i.sstatic.net/rHj1x.png However, when the result is displayed on the HTML page, it appears like this: https://i.sstatic.net/r7VTP.p ...

Including Vuetify in my project has triggered a SecurityError, specifically relating to the CSSStyleSheet.cssRules getter being restricted from accessing cross-origin stylesheets

Looking to create a Vue application that opens a CKEditor component in a separate window, I managed to do so following the method outlined in this helpful post. I have even set up a Codesandbox demonstration to showcase the functioning example. However, u ...

Prevent IonContent from scrolling to the bottom or top when using Ionic framework

In my Ionic app, I have a long text page with 2 buttons that trigger the actions scrollToBottom and scrollToTop. Due to the length of the page, I have set the scroll duration to be 30 seconds. I am facing two issues here: How can I stop the scrolling ...

Angular index.html file can include a conditional script

I am currently working on an Angular project, where the index.html serves as the main entry point for the application, just like in any other Angular project. This file contains important links and configurations. Within the HTML code snippet below, you w ...

Issue with Table Element's Full Width Within Parent Element

Here is a demonstration of the scenario in JSFiddle I have made updates to the JSFiddle demonstration here: http://jsfiddle.net/x11joex11/r5spu85z/8/. This version provides more detailed insight into how the sticky footer functions well, albeit with a hei ...

Adjusting the width of images using jQuery Mobile or jqTouch

I am looking to incorporate a static footer image with 5 navigation buttons into my mobile website. You can view the image here. The default color for the icons should be blue, but I want the yellow icon to appear only when hovered over or in an active sta ...