Looking for assistance with CSS? Need help with positioning elements and creating hover effects?

I have created a custom Mailchimp subscribe form code that suits my specific needs.

  1. The red button currently appears below the email box, but I would like to shift it to the right and on the same level as the email box.

  2. Additionally, I am looking to add a hover effect to the button (changing its color to black).

Despite trying various methods, I have been unsuccessful in achieving these changes. As a newcomer to CSS, any assistance offered would be greatly appreciated. Thank you.

#mailchimp {
  background: #383838;
  color: #ff2727;
  padding: 40px 15px;
}
#mailchimp input {
  border: medium none;
  color: gray;
  font-family: times new roman;
  font-size: 16px;
  font-style: bold;
  margin-bottom: 15px;
  padding: 10px 12px;
  width: 350px;
}
#mailchimp input.email {
  background: #fff;
}
#mailchimp input.name {
  background: #fff;
}
#mailchimp input[type="submit"] {
  background: #ff2727;
  color: #fff;
  cursor: pointer;
  font-size: 20px;
  width: 40%;
  padding: 8px 0;
}
#mailchimp input[type="submit"]:hover {
  color: #000000;
}
<div id="mailchimp">
<form action="//askchange.us11.list-manage.com/subscribe/post?u=32e8df9557dd399bb3ba2ae61&amp;id=62317f4783" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
    <div id="mc_embed_signup_scroll">
        <div class="indicates-required"><span class="asterisk">*</span> indicates required</div>
        <div class="mc-field-group">
            <input type="email" value="Enter your email" name="EMAIL" SIZE="30" class="required email" id="mce-EMAIL"onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;">
        </div>
        <div id="mce-responses" class="clear">
            <div class="response" id="mce-error-response" style="display:none"></div>
            <div class="response" id="mce-success-response" style="display:none"></div>
        </div>    <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
        <div style="position: absolute; left: -5000px;" aria-hidden="true"><input type="text" name="b_32e8df9557dd399bb3ba2ae61_62317f4783" tabindex="-1" value=""></div>
        <div class="clear"><input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button"></div>
    </div>
</form>
</div>

Answer №1

To align the input button on the right side and below the input box, you need to specify fixed sizes for both the container of the input and the input button. Then set the width of the input box to 100% and float the button to the right.

#mailchimp {
   width: 400px; // provide a fixed size
}
#mailchimp input {
   width: 100%; // set the width to 100%
   box-sizing:border-box;
}
#mailchimp input[type="submit"]  {
   float: right;
}
#mailchimp input[type="submit"]:hover {
   background-color:black;
   color: white;
}

MODIFY YOUR CSS AND HTML AS FOLLOWS:

#mailchimp {
      background: #383838;
      color: #ff2727;
      padding: 40px 15px;
      width: 400px; 
    }
    #mailchimp input {
      border: medium none;
      color: gray;
      font-family: times new roman;
      font-size: 16px;
      font-style: bold;
      margin-bottom: 15px;
      padding: 10px 12px;
      width: 100%; //set the width to 100%
      box-sizing:border-box;
    }
    #mailchimp input.email {
      background: #fff;
    }
    #mailchimp input.name {
      background: #fff;
    }
    .mc-field-group {
        width: 60%;
        float: left;
    }
    #mailchimp input[type="submit"] {
      background: #ff2727;
      color: #fff;
      cursor: pointer;
      font-size: 20px;
      width: 40%;
      padding: 8px 0;
      float: right;
    }
    #mailchimp input[type="submit"]:hover {
       background-color:black;
       color: white;
    }

Update your HTML structure as follows:

<div id="mailchimp">
<form action="//askchange.us11.list-manage.com/subscribe/post?u=32e8df9557dd399bb3ba2ae61&amp;id=62317f4783" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
    <div id="mc_embed_signup_scroll">
        <div class="indicates-required"><span class="asterisk">*</span> indicates required</div>
        <div class="mc-field-group">
            <input type="email" value="Enter your email" name="EMAIL" SIZE="30" class="required email" id="mce-EMAIL"onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;">
        </div>
        <div class="clear"><input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button"></div>
        <div id="mce-responses" class="clear">
            <div class="response" id="mce-error-response" style="display:none"></div>
            <div class="response" id="mce-success-response" style="display:none"></div>
        </div>    <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
        <div style="position: absolute; left: -5000px;" aria-hidden="true"><input type="text" name="b_32e8df9557dd399bb3ba2ae61_62317f4783" tabindex="-1" value=""></div>

    </div>
</form>
</div>

Answer №2

To ensure proper alignment, apply the CSS property 'display:block' to your input element and then use 'float:left'.

Your hover effect is on point, but remember that you're currently changing the text color to black only. Update 'color:#000000' to 'background-color:#000000' for a more noticeable change.

Answer №3

Modify the background color when hovering over the submit button:

#mailchimp input[type="submit"]:hover { 
   background-color: #000000; 
}

Align the submit button to the right side of the page:

#mailchimp input[type="submit"] { 
   float: right;
}

#mailchimp input.email { 
    float: left;
}

Learn more about how the 'float' property functions here: http://www.w3schools.com/css/css_float.asp

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

The method to retrieve post data from Angular / Ionic to PHP

I'm having some issues accessing the JSON data that I'm posting from Angular / Ionic to PHP. Below is the PHP code that I'm using: $jsonData = file_get_contents('php://input'); $data = json_decode($jsonData, true); When I saved ...

What is the process for making a new post?

Having some trouble with using the form correctly. I've been trying to figure out how to create a post, but I'm encountering an issue; I can't seem to get posting to work properly. I am looking to save both POST and Image FILE. views.py @ ...

The subscriber continues to run repeatedly, even after we have removed its subscription

The file brief-component.ts contains the following code where the drawer service is being called: this.assignDrawerService.showDrawer(parameter); In the file drawer-service.ts: private drawerSubject = new BehaviorSubject<boolean>(false); public ...

Manipulating the zIndex and hiding elements in jQuery with smartystreets

Currently, I am utilizing the SmartyStreets jQuery plugin on a PHP page, which has been incredibly helpful. On this same page, there is a jquery modal popup form that I need to incorporate. Unfortunately, I have run into an issue where the SmartyStreets " ...

Having issues with the display of Bootstrap SelectPicker dropdown in a dataTable?

I am currently populating data into a jQuery datatable dynamically with the help of AJAX. Each row in the table contains a dropdown selectpicker from Bootstrap, displayed as follows: https://i.sstatic.net/g0czE.png However, I am experiencing issues with ...

Exploring the world of ASP .NET development with the powerful Sonar

We're currently working on an ASP .NET project and are looking for a way to analyze JavaScript files on-the-fly. Unfortunately, SonarLint only offers analysis for C# files. The incremental analysis feature seems to have been phased out, and issues ana ...

Show label and selection box

I've been trying to add a checkbox to the display tag table, but I'm having trouble getting it to function properly. I want the header checkbox to select all rows in the table when checked Additionally, individual rows should be selectable Whe ...

retrieving data from GET variables and sending to a PHP array

Is there a way to retrieve form variables and store them in an array in memory without reloading the page? I'm not very experienced with this, so any guidance would be appreciated. My goal is to update a JSON file using PHP based on form inputs. JSON ...

A step-by-step guide on performing requests sequentially within a useEffect hook

My useEffect function triggers a request when changing dependencies (department and two dates fields). useEffect(() => { getFilteredRestReport({ date_start: formatDatePatchPoint(date[0]), date_end: formatDatePatchPoint(date[1]), de ...

Ways to stop inline divs from shifting to a new line inside their container

My issue involves two inline divs that are wider than their parent element, causing the second div to drop down to the next line. Here's a link to see it in action: http://jsfiddle.net/uVqG6/2/ How can I prevent the second div from wrapping to the ne ...

Mongoose Filtering in Rest API: A Comprehensive Guide

Currently, I am utilizing Express to construct an API. Within this API, my objective is to retrieve a list of customers from MongoDB by using Mongoose. The code snippet below showcases the route I have set up (please disregard any paging and limit concerns ...

Tips for adjusting the close date based on the selected date in a dropdown datepicker

Here is a sample code snippet: <input id="date1" name="start_date" id="dpd1"/> <select class="form_line_only form-control" name="ho_night"> <option selected> 0 </option> <option ...

Is there a way to replicate onbeforeunload in a Vue.js 2 application?

I have a Vue component that is monitoring whether it has unsaved changes. I want to alert the user before they move away from the current form if there are unsaved modifications. In a traditional web application, you could use onbeforeunload. I tried imple ...

Increase the spacing between the scrollbar and the border

Looking to create some breathing room between the scrollbar and the right border of my text area. I've tried adjusting the margin-right/left values in -webkit-scrollbar with no success. Here's my style component: const FormTextArea = styled.texta ...

Preventing or deleting local cache when sending a canvas blob through AJAX requests

I am sending a canvas image to my server via AJAX using the following method: myCanvas.toBlob( function( blob ) { var fdata = new FormData( ); fdata.append( 'myFile', blob ); $.ajax( { url: 'http://myScript.foo', ...

Regular expression for precise numerical values of a specific magnitude (any programming language)

I have been searching for a solution to what I thought was a common problem but haven't found one yet. What I need is a regular expression that will fail on a specific number of significant figures (a Max), but pass for fewer than the Max. It should ...

Iterating over the IDs of div elements using jQuery loop

Currently, I am working with a bootstrap accordion and attempting to retrieve the ID and HREF values for each individual accordion using jQuery. Here is the code snippet that I have been utilizing: $('.room-loop').each(function(id){ $('. ...

What is the best way to anchor an image so that it remains fixed in its position relative to the browser or screen resolution?

I inquired about an issue a few days back, but I realize now that my explanation was unclear. To make things clearer, let me present two images to illustrate my problem. This is how it appears for me: . However, individuals with different screen resolution ...

jQuery and Easy Dialog

My jQuery Model window has a form inside. Even though I have set autoOpen to false in my dialog, the fields are still visible when the page is created. All forms are contained within a div. This is what my dialog code looks like: $("#dialog-form").dial ...

Implementing jQuery's live() method to handle the image onload event: a guide

Looking to execute a piece of code once an image has finished loading? Want to achieve this in a non-intrusive manner, without inline scripting? Specifically interested in using jQuery's live() function for dynamically loaded images. I've attemp ...