Align the elements of the contact form to the opposite sides

I am experiencing an issue with my contact form where all elements are flowing horizontally instead of vertically. I would like everything to be floated to the left and aligned vertically, except for the "message" box and submit button which should be on the right side.

How can I fix this problem?

Check out the code on jsfiddle

<div id="contact">
        <div id="contact-form" class="clearfix">  
        <h2><img src="img/chat.png" alt="contact frsh studio"></h2> 
        <ul id="errors" class="">  
            <li id="info">There were some problems with your form submission:</li>  
        </ul>  
        <p id="success">Thanks for your message! We will get back to you ASAP!</p>  
        <form method="post" action="process.php"> 
            <input type="text" id="name" name="name" value="" placeholder="NAME" required="required" autofocus="autofocus" />  
            <input type="email" id="email" name="email" value="" placeholder="EMAIL" required="required" />   
            <select id="enquiry" name="enquiry">  
                <option value="refrsh">Brand REFRSH</option>  
                <option value="consult">Brand Consultation</option>  
                <option value="support">Just a Hello!</option>  
            </select>  
            <textarea id="message" name="message" placeholder="MESSAGE" required="required" data-minlength="20"></textarea>  
            <span id="loading"></span>  
            <input type="submit" value="Holla!" id="submit-button" />  
            <p id="req-field-desc"><span class="required">*</span> kind of necessary</p>  
        </form>  
    </div>  
    </div><!-- end contact -->


#contact-form { 
    width: 690px;
    padding:20px;  
    margin: 50px auto;    
    position:relative;  
}   
#contact-form h2 {  
    margin-bottom:20px;
    margin-top:40px;
    text-align: center;  
}  
#contact-form input,  
#contact-form select,  
#contact-form textarea,  
#contact-form label {  
    font-size:15px;  
    margin-bottom:2px;
}  
#contact-form input,  
#contact-form select,  
#contact-form textarea {
    float: left !important;  
    width:320px;   
    margin-bottom:20px;  
    padding:4px;  
}    
#contact-form textarea {  
    height:150px;  
    resize: none;  
}
#contact-form #message {
    clear: both;
    float: right !important;
}
#contact-form label {  
    display:block;  
}  
#contact-form .required {  
    font-weight:bold;  
    color:#F00;  
}  
#contact-form #submit-button {  
    width: 100px;  
    border: 2px solid #515151;  
    display:block;  
    float:rightright;  
    margin-bottom:0px;  
    margin-right:6px; 
}   
#contact-form #loading {  
    width:32px;  
    height:32px;  
    background-image:url(../img/loading.gif);  
    display:block;  
    position:absolute;  
    rightright:130px;  
    bottombottom:16px;  
    display:none;  
}  
#errors {  
    border:solid 1px #E58E8E;  
    padding:10px;  
    margin:25px 0px;  
    display:block;  
    width:437px;  
    -webkit-border-radius:8px;  
    -moz-border-radius:8px;  
    border-radius:8px;  
    background:#FFE6E6 url(../img/cancel_48.png) no-repeat 405px center;  
    display:none;  
}  
#errors li {  
    padding:2px;  
    list-style:none;  
}  
#errors li:before {  
    content: ' - ';  
}  
#errors #info {  
    font-weight:bold;  
}  
#errors #info:before {  
    content: '';  
}  
#success {  
    border:solid 1px #83D186;  
    padding:25px 10px;  
    margin:25px 0px;  
    display:block;  
    width:437px;  
    -webkit-border-radius:8px;  
    -moz-border-radius:8px;  
    border-radius:8px;  
    background:#D3EDD3 url(../img/accepted_48.png) no-repeat 405px center;  
    font-weight:bold;  
    display:none;  
}  
#errors.visible, #success.visible {  
    display:block;  
}  
#req-field-desc {  
    font-style:italic;  
}  
/* Remove box shadow firefox, chrome and opera put around required fields. It looks rubbish. */  
input:required, textarea:required {  
    -moz-box-shadow:none;  
    -webkit-box-shadow:none;  
    -o-box-shadow:none;  
    box-shadow:none;  
}  
/* Normalize placeholder styles */  
/* chrome, safari */  
::-webkit-input-placeholder {  
    color:#CCC;  
    font-style:italic;  
}  
/* mozilla */  
input:-moz-placeholder, textarea:-moz-placeholder {  
    color:#CCC;  
    font-style:italic;  
}  
/* ie (faux placeholder) */  
input.placeholder-text, textarea.placeholder-text  {  
    color:#CCC;  
    font-style:italic;  
}

Answer №1

Here is the updated JSFiddle link: http://jsfiddle.net/kG67D/1/

In reference to my previous comment, it's important to remember to apply the CSS definition for clear when working with elements that are floated.

In this particular case, adding clear: left; was all that was needed to resolve the issue.

#contact-form input,  
#contact-form select,  
#contact-form textarea {
    clear:left;
    float: left;
    width:320px;   
    margin-bottom:20px;  
    padding:4px;  
}   

I also made some adjustments to the HTML structure. Sometimes rearranging elements can help achieve the desired layout. For example, moving the <textarea> to the beginning of the form was necessary for proper display.

It's worth noting that there are multiple ways to create layouts using HTML and CSS; my approach was just one suggestion.

If you're looking for more information on floats, I recommend checking out this informative guide: http://css-tricks.com/all-about-floats/

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

Choosing the Right Alignment for Your Selection Box

How can I adjust the alignment of the select box to make it inline with the others? I also need to apply this alignment to the three option input boxes. CSS: #newwebsiteSection, #websiteredevelopmentSection, #otherSection{ display:none; } #newwebsite ...

Social Engine is incapable of analyzing the HTML code

Currently working on a website using Social Engine 4.8.9 version that is still in development mode. Upon inspecting the html code with the chrome inspector, I find it incredibly complex to decipher. For instance, when I click on the login page link http:// ...

What is the best way to change styles in CSS for parent and child elements using selectors?

Hey there! I am currently working on customizing the navigation menus in WordPress and here is the HTML code for the navigation menus: <nav id="primary-navigation" class="site-navigation primary-navigation" role="navigation"> <h1 class="menu- ...

"Utilizing Bootstrap to add borders to div elements is a

https://i.sstatic.net/yPt46.png Hey there! I am working on a project using bootstrap 4. I encountered an issue that I can't seem to solve. I placed an image inside a div, set the div's height and width to 200px with overflow hidden. The image w ...

Creating a dynamic form that efficiently captures user information and automatically redirects to the appropriate web page

Sorry for the unusual question, but it was the best way I could think of asking. I have come across websites with fill-in-the-blank lines where you can input your desired information and then get redirected to another page. For example: "What are you sea ...

Enhancing the appearance of each letter within a word

I am currently working on styling the word "Siteripe". Each letter should have a different color, just like it is shown on this website. I have successfully styled only the first letter using the following CSS code: #namer:first-letter { color:#09C; f ...

Unveiling the Power of Angular in Handling Date and Time

Recently, I encountered an issue with the following code snippet: <ng-template>{{date:'MM/dd/yyyy h:mm:ss a Z'}}</ng-template>. This code displays a date and time in one long line. My goal is to insert a line break between the date an ...

"An issue with IE9 causing small dots on rounded corners during rendering

Help Needed: Strange IE9 Rendering Issue I'm experiencing an odd rendering problem in Internet Explorer 9. You see those little white dots on the left? What could be causing them? Any suggestions on how to remove them? Microsoft, why always so myst ...

Customizing the input field to have a width of 100%

Could someone provide a solution, like a link or working example, for creating input fields with rounded corners that have a width of 100% and a customizable right border? Here is the current structure I am using: <span class="rounded left-corner" ...

Creating a component that surpasses all others

I have a code snippet that contains styling information for two div elements. How can I ensure that my <div id="home"> appears below my <div id="navigate"? Any suggestions? #home { background-color: black; color: grey; text-align: c ...

Using HTML and CSS to create interactive icons that change color when clicked, similar to how a link behaves

Have you ever wondered if there's a way to make an icon act like a link when clicked, just like regular text links turning purple? And not just the last one clicked, but every single icon that gets clicked. Trying to use the :visited pseudo was unsucc ...

Steps for aligning a table in the middle of a webpage

Can someone help me align my table to the center of the webpage? I have tried using align="right" and "center" but neither seem to be working. Any tips on how to position the table correctly? <table style="table-layout:fixed;" align="right" cellspaci ...

Numerous hyperlinks leading to different products within the same image

https://i.sstatic.net/T7P4V.jpg I am looking for a solution to create clickable links on a picture that contains multiple items (3 in my specific case, as shown in the image above). Currently, I am using position:absolute to place links on each item, but ...

Using Multiple SCSS Files to Reference a Centralized Style Sheet

I am currently developing a React application and facing an issue with my SCSS files. I have three SCSS files, one main file that contains theme variable colors, and the other two are located in component folders. When I import the main SCSS file into the ...

Enhancing dynamically generated elements with CSS styling

I have been working on developing my own jQuery Gallery Plugin. The crucial initial markup that is required to initialize the plugin includes: Initial HTML <div class="riGallery"> <ul> <li><a href="http://www.example.com" ...

What is the best way to accomplish a smooth transition of background colors similar to this design

I was browsing different websites and stumbled upon this amazing background color transition that caught my attention. I really liked it and now I want to create something similar on my own website. Despite my best efforts, I haven't been able to achi ...

The hamburger menu in Bootstrap 5 is not displaying properly on mobile screens and appears to be unstable

Although the desktop screen is working fine, I am encountering 2 issues on the mobile screen: Check out this JSFiddle Demo: https://jsfiddle.net/uyvdqL9s/ On the mobile screen, the hamburger menu appears in the center instead of on the right along with t ...

Troubleshooting CSS compatibility issues in Firefox browser (or HTML rendering as plain text)

In a unique web page comparing two photos, the clicked one changes, but there's an issue in Firefox where HTML displays as text and links don't work. CODE:- * { box-sizing: border-box; } html { height: 100%; } body { height: 100%; mar ...

Tips for choosing elements in jQuery that do not contain a particular element

How can I target elements in jQuery that do not contain a specific element within them? I am trying to create a sidebar that will close when the user clicks either the menu or the sidebar itself, excluding dropdown menus. Below is the structure of the menu ...

I am encountering an issue with opening a dropdown select option upon clicking in C# while using Selenium

I am encountering an issue while attempting to open the Register page from my account. The UI developer utilized Bootstrap code, and Bootstrap developers have included a JS function on click. However, when I execute this code, an error is thrown: "OpenQA.S ...