Having trouble creating an inlined form with HTML and CSS

I'm attempting to create a horizontal forum within WordPress using HTML and CSS. The issue I'm facing is that the form is not displaying inline as intended, but rather in a standard format. Below are the codes I'm working with:

   <!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
    <title>newsletter</title>
</head>

<body>
    <div class="newsletter-subscribe">
        <div class="container">
            <div class="intro">
                <h2 class="text-center"><strong>CAPTURING PHOTOS, MAKING VIDEOS AND TRAVELING WITH THIS PASSION</strong><br></h2>
                <p class="text-center">How to take your best photographs, create videos that everyone will admire, grow on social media by working with what you love and improving your techniques.</p>
            </div>
            <form class="form-inline" method="post" action="the link">

                  <div id="mc_embed_signup_scroll">
                    <div class="form-inline"><input class="form-control form-control-sm" type="text" placeholder="Your name..." name="FNAME" required=""><input class="form-control" type="email" name="EMAIL" placeholder="Your best email..." required=""></div>
                    <div class="form-inline"><button class="btn btn-primary" type="submit">Subscribe </button></div>
            </form>
        </div>
    </div>
</body>

</html>

and here is the CSS code, which I have not included directly in the HTML due to working in WordPress:

h2{font-size:24px;font-weight:700;margin-bottom:25px;line-height:1.5;padding-top:0;margin-top:0;color:inherit}
.form-inline {
  display: flex;
  flex-flow: row wrap;
    align-items: center; }
  .form-inline {
    flex-direction: column;
 }

.newsletter-subscribe
.intro{font-size:16px;max-width:500px;margin:0 auto 25px}.newsletter-subscribe
.intro p{margin-bottom:35px}
.newsletter-subscribe

.newsletter-subscribe
form .form-control{background:#eff1f4;border:none;border-radius:3px;box-shadow:none;outline:0;color:inherit;text-indent:9px;height:45px;margin-right:10px;min-width:250px}.newsletter-subscribe

This is the current display I am seeing.

Answer №1

To achieve the desired result, you need to eliminate the following piece of code from your styles:

.form-inline {
   flex-direction: column;
}

But why?

The reason is that flex-direction: column; transforms each div child into an independent row, aligning them all in a column format, similar to what was previously achieved.

The next step to create inline form inputs and buttons is by moving the button tag out of the individual division with the same class and enclosing all elements within a single div like this:

 <div class="form-inline">
    <input class="form-control form-control-sm" type="text" placeholder="Your name..." name="FNAME" required="">
    <input class="form-control" type="email" name="EMAIL" placeholder="Your best email..." required="">
    <button class="btn btn-primary" type="submit">Subscribe</button>
 </div>

Final steps

Your final code composition will resemble the snippet below:

h2 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 25px;
  line-height: 1.5;
  padding-top: 0;
  margin-top: 0;
  color: inherit;
}

.form-inline {
  display: flex;
  justify-content: center;
  align-items: center;
}

.newsletter-subscribe .intro {
  font-size: 16px;
  max-width: 500px;
  margin: 0 auto 25px;
}

.newsletter-subscribe .intro p {
  margin-bottom: 35px;
}

.newsletter-subscribe .newsletter-subscribe form .form-control {
  background: #eff1f4;
  border: none;
  border-radius: 3px;
  box-shadow: none;
  outline: 0;
  color: inherit;
  text-indent: 9px;
  height: 45px;
  margin-right: 10px;
  min-width: 250px;
}
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
  <title>newsletter</title>
</head>

<body>
  <div class="newsletter-subscribe">
    <div class="container">
      <div class="intro">
        <h2 class="text-center"><strong>CAPTURING PHOTOS, CREATING VIDEOS AND TRAVELING WITH THIS PASSION</strong><br></h2>
        <p class="text-center">How to capture your best photos, produce videos admired by all, grow on social media working with what you love, and enhancing your skills. </p>
      </div>
      <form class="form-inline" method="post" action="the link">

        <div id="mc_embed_signup_scroll">
          <div class="form-inline">
            <input class="form-control form-control-sm" type="text" placeholder="Your name..." name="FNAME" required="">
            <input class="form-control" type="email" name="EMAIL" placeholder="Your best email..." required="">
            <button class="btn btn-primary" type="submit">Subscribe </button>
          </div>
      </form>
      </div>
    </div>
</body>

</html>

UPDATE

To add spacing between these inputs, apply the margin property to each div child as follows:

.form-inline input, .form-inline button {
   margin: 0 5px;
}

The final outcome will be:

h2 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 25px;
  line-height: 1.5;
  padding-top: 0;
  margin-top: 0;
  color: inherit;
}

.form-inline {
  display: flex;
  justify-content: center;
  align-items: center;
}

.form-inline input, .form-inline button {
  margin: 0 5px;
}

.newsletter-subscribe .intro {
  font-size: 16px;
  max-width: 500px;
  margin: 0 auto 25px;
}

.newsletter-subscribe .intro p {
  margin-bottom: 35px;
}

.newsletter-subscribe .newsletter-subscribe form .form-control {
  background: #eff1f4;
  border: none;
  border-radius: 3px;
  box-shadow: none;
  outline: 0;
  color: inherit;
  text-indent: 9px;
  height: 45px;
  margin-right: 10px;
  min-width: 250px;
}
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
  <title>newsletter</title>
</head>

<body>
  <div class="newsletter-subscribe">
    <div class="container">
      <div class="intro">
        <h2 class="text-center"><strong>CAPTURING PHOTOS, CREATING VIDEOS AND TRAVELING WITH THIS PASSION</strong><br></h2>
        <p class="text-center">How to capture your best photos, produce videos admired by all, grow on social media working with what you love, and enhancing your skills.</p>;
      </div>
      <form class="form-inline" method="post" action="the link">

        <div id="mc_embed_signup_scroll">
          <div class="form-inline">
            <input class="form-control form-control-sm" type="text" placeholder="Your name..." name="FNAME" required="">
            <input class="form-control" type="email" name="EMAIL" placeholder="Your best email..." required="">
            <button class="btn btn-primary" type="submit">Subscribe </button>
          </div>
      </form>
      </div>
    </div>
</body>

</html>

NOTE: The margin property shorthand includes top, right, bottom, and left margins respectively. Using it as margin: 0 5px, sets top and bottom margins to 0 while right and left margins are set to 5px.

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

Static express fails to load CSS files from the main folder

When my app is loaded from a url like: server.com/pdf/12345, it tries to find static files at GET /pdf/12345/assets/css/stylesheet.css and returns a 404 error. I've been struggling to get it to search for the files in /public/assets instead. I've ...

What is the reason behind my resizer bar not changing color to green?

Whenever I resize the bar between the West and Inner Center areas, it turns green. However, the bar between the Inner Center and Inner South areas does not change color. How can I make it turn green when resizing, including adding the orange highlight for ...

Ways to patiently wait in a for loop until the ajax call is completed

I am a beginner in web development and currently working on a small website project that involves using ajax to display new comments. Below is the function I have created: function show_comments() { $('div#P_all_posts>div').each(function () { ...

Utilizing Fancybox with a polymer paper-card: A step-by-step guide

I have a collection of paper-cards and I am looking for guidance on integrating the fancybox library to display the content of each paper-card. Here is a sample of a paper-card: <paper-card heading="Emmental" image="http://placehold.it/350x150/FF ...

Retrieving the value of a button tag in JavaScript for an AJAX request

Essentially, I have a collection of <a> tags retrieved from a database. These tags are visible to users and trigger an ajax function when clicked on. Currently, one button serves the purpose for all tags. The structure of these tags is as follows: ...

Enhancing code with new Javascript functionality

Currently utilizing the WordPress Contact Form 7 plugin and in need of updating my existing JavaScript code to include an onclick function and data-img attribute for checkboxes. Due to the limitations of Contact Form 7 shortcode, adding attributes beyond i ...

Retrieve every HTML element that is currently visible on the screen as a result

I have a dynamic HTML table that updates frequently, with the potential for over 1000 rows. Instead of replacing the entire table each time it updates, I am exploring options to only update the visible rows. My initial approach involved iterating through ...

"Engaging with the touchscreen inhibits the triggering of click

Within this div, I have implemented touch-action:pan-y;. Surrounding this div is an anchor tag. If you click on the div, the link will successfully redirect. However, if you swipe on the div and then click, the link won't work on the first attempt bu ...

I am experiencing an issue where the value of int in jQuery.ajax is being sent, but

When I attempt to send data to an ajax post call, I am receiving a return of "NULL." Although I am successfully sending other data, I have omitted it from the snippet for clarity. Upon logging the variable in my console, it appears. Checking the network t ...

Basic illustration of AJAX web-app, encompassing client and server components

Currently, I am immersing myself in the world of AJAX by tapping into online resources and delving into some informative books. While doing so, I discovered that AJAX is not exactly a groundbreaking technology in and of itself, but rather a method of lever ...

PHP include does not bring in the CSS file

My project has a main.css file stored in the styles folder at the root: #header { background-color: aqua; height: 120px; } Within header.php, there is the following code: <!DOCTYPE html> <html> <head> <link rel="styleshe ...

Interacting with Watir and Cucumber, unfortunately the link is not functional

Being new to the world of Watir and Cucumber, I am currently in the process of running an automation script to create Live IDs. The link that I want to click on the webpage is labeled "New" and it should take me to a form where I can add a new contact for ...

Stop iframe zooming on Android devices

I am facing an issue with an iframe that contains form elements. I have attempted to include a meta tag within the iframe page: <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/> Also, I tried se ...

Having trouble maintaining the original events on a cloned element

My goal is to duplicate an element passed into a function and retain all associated events, including ones like $('.example').on('click', function(e) ... )} that are defined within the document ready. Here's what I'm trying: ...

Changing form data upon submission in Symfony2Alternatively: Adjusting form values post

I am facing an issue with a form that has the following fields: name (required). slug (required). The slug field is required in the backend, but users are allowed to leave it blank in the form field. If the user leaves the slug blank, it should aut ...

Creating a dynamic HTML table using Vue 3

My table is not showing the data I'm fetching from my API. Even though I can see the data in my console.log, it's not populating the table. Could there be an issue with how I'm calling the data to display in the table? <template> < ...

Ways to adjust a column width to be equal to the full width

My HTML table has columns with fixed widths, except for one that I want to expand to fill the remaining space with a minimum width set. I attempted using width: auto, but it didn't achieve the desired result of filling the leftover space. ...

Check the form using jQuery to see if the input value is empty, and then remove the submit click

Attempting to create a jQuery form validation code that checks for empty values or words with a length less than a specified limit. If the conditions are met, the submission click is unbound, an error hint is displayed in a div, and then after 5 seconds, t ...

The offset values of $(element) keep increasing indefinitely when they are updated repeatedly

After researching how to utilize JavaScript drag functionality to move elements, the goal is to dynamically adjust the cursor position within a square when dragged. In an attempt to simplify the process and avoid storing x and y offsets as separate variabl ...

C++ HTML parsing tool inspired by Jsoup

In my quest to extract data from various web pages using Java, I relied on the Jsoup library for its efficiency. However, I now face the challenge of having to convert my code to C/C++. The problem is, I'm struggling to find a suitable HTML parser for ...