Attempting to position the text area and the button in a horizontal layout

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

   <form class="container">
      <div class="row">
      
         <div class="col-md-5">
            <h2>Template</h2>
            <textarea id="template" value={this.state.value1} placeholder=" Hello {{name}}! {% if test -%} How are you?{%- endif %}" onChange={this.handleChange1.bind(this)}/>
            
         </div>
         <div class="col-md-5 align-right">
         <h2>Render</h2>
         <div id="render"> {this.state.loading || !this.state.data ? < div id="render"></div> : <div>{this.state.data.toString().replace(/•/g, " ")}</div>}
         </div>
         <div class="col-md-5">
           <input type="button" class="btn btn-success" id="convert" value="Convert" onClick={this.click} disabled={this.state.isLoading}/>
           <input type="button" class="btn btn-danger" id="clear" value="Clear" onClick={this.resetForm}/>
         </div>
      </div>

I am attempting to position the button on the right side of the grey box to create a horizontal alignment with all text boxes and buttons.

When trying to use inline-block on the div class col-md-5, it causes everything to shift vertically instead of horizontally.

Below is the CSS code:

h2{
font-family: "Times New Roman", Times, serif;
font-style: normal;
}


ul{
    list-style-type: none;

}
.col-md-5{
     margin: auto;
}
*{ margin: 0; padding: 0; }


#template,
#render,
#values {

     width: 100%;
    min-height: 300px;
    resize: vertical;
    font-family: "Courier New", Courier, monospace;
    border: 1px solid #ccc;

}



#render {
    background: #eee;
}

Answer №1

Your current setup uses col-md-5 for the buttons' container div.

Remember, one row in Bootstrap is made up of 12 columns.

To solve the issue, you can either switch to col-md-2 or adjust the size of the textarea's container div accordingly.

If changing to col-md-2 doesn't fix the problem, try resetting your default CSS with this code:

* { margin: 0; padding: 0; }

Answer №2

Just a quick addition to the previous answer - don't forget to close your textarea tag properly. It's not a self-closing element.

    <form class="container">
        <div class="row">

            <div class="col-md-6">
                <h2>Template</h2>
                <textarea id="template" value={this.state.value1} placeholder=" Hello {{name}}! {% if test -%} How are you?{%- endif %}" onChange={this.handleChange1.bind(this)}></textarea>

            </div>
            <div class="col-md-3">
                <h2>Render</h2>
                <div id="render"> {this.state.loading || !this.state.data ? < div id="render"></div> : <div>{this.state.data.toString().replace(/•/g, " ")}</div>}
            </div>
            <div class="col-md-3">
                <input type="button" class="btn btn-success" id="convert" value="Convert" onClick={this.click} disabled={this.state.isLoading}/>
                <input type="button" class="btn btn-danger" id="clear" value="Clear" onClick={this.resetForm}/>
            </div>
            </div>
    </form>

Answer №3

When using Bootstrap, keep in mind the 12 column system. If your total exceeds 12, elements may be pushed to a new line. To avoid this issue, consider adjusting the last column like so:

<div class="col-md-2">
           <input type="button" class="btn btn-success" id="convert" value="Convert" onClick={this.click} disabled={this.state.isLoading}/>
           <input type="button" class="btn btn-danger" id="clear" value="Clear" onClick={this.resetForm}/>
         </div>

Answer №4

I have identified a couple of issues in the code provided:

  1. The second div with the class col-md-5 was not properly closed.
  2. According to Bootstrap guidelines, the sum of column numbers should be 12 in a row if you are following a 12-column grid system.

Here is the updated code that I believe resolves these issues:

<div class="row">
  <div class="col-md-5">
    <h2>Template</h2>
    <textarea id="template" value={this.state.value1} placeholder=" Hello {{name}}! {% if test -%} How are you?{%- endif %}" onChange={this.handleChange1.bind(this)}/>
  </div>
  <div class="col-md-5">
    <h2>Render</h2>
    <div id="render"> {this.state.loading || !this.state.data ?
      <div id="render"></div> :
      <div>{this.state.data.toString().replace(/•/g, " ")}</div>}
    </div>
  </div>
  <div class="col-md-2">
    <input type="button" class="btn btn-success" id="convert" value="Convert" onClick={this.click} disabled={this.state.isLoading}/>
    <input type="button" class="btn btn-danger" id="clear" value="Clear" onClick={this.resetForm}/>
  </div>
</div>

Answer №5

The total for col-md-5 is reaching 15. Ensure your button is set to col-md-2 as specified above, or you can adjust all of them to col-md-4.

   <form class="container">
  <div class="row">

     <div class="col-md-4">
        <h2>Template</h2>
        <textarea id="template" value={this.state.value1} placeholder=" Hello {{name}}! {% if test -%} How are you?{%- endif %}" onChange={this.handleChange1.bind(this)}/>

     </div>
     <div class="col-md-4">
     <h2>Render</h2>
     <div id="render"> {this.state.loading || !this.state.data ? < div id="render"></div> : <div>{this.state.data.toString().replace(/•/g, " ")}</div>}
     </div>
     <div class="col-md-4">
       <input type="button" class="btn btn-success" id="convert" value="Convert" onClick={this.click} disabled={this.state.isLoading}/>
       <input type="button" class="btn btn-danger" id="clear" value="Clear" onClick={this.resetForm}/>
     </div>
  </div>

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

Different types of arrays suitable for the useState hook

I have a scenario where I am utilizing setState to assign an array of objects. Here is the code snippet: const [friendList, setFriendList] = useState<any>(); const _onCompleted = (data: any) => { let DATA = data.me.friends.map( (item ...

Unable to run EJS script inside ajax 'success' function

I am facing an issue with my EJS page that utilizes AJAX to retrieve data. After loading the data, I intend to add specific content to a div. Within the added content, there are checkboxes controlled by the following script: <script> $('#select ...

Tips for inserting a PHP array into an email communication

I have a question regarding sending emails through PHP. How can I include PHP arrays in the message section of an email? Here is a simple array that I created and attempted to include in the email, but it seems incorrect as I couldn't find any releva ...

RequireJS is causing issues with file uploading functionality

Encountering an issue when trying to load fileupload with requirejs. The specific error message received: TypeError: this._on is not a function I suspect that the problem lies in the fact that fileupload also requires jquery.ui.widget to be loaded. I att ...

Trouble retrieving data from subsequent server actions in Next.js version 13.4

I'm interested in exploring how to access returned values from the alpha release of server actions in Next.js 13. For more information, you can check out the documentation provided by the Next team. For instance, let's consider a sample server a ...

What is the best way to decrease the size of the text in the header as the user scrolls down?

I have a fixed header with a large text. I would like the text to decrease in size as someone scrolls down, and return to its original size when the scroll is at the top. The CSS applied when scrolling down should be: font-size: 15px; padding-left: 1 ...

Obtaining cookies from a separate domain using PHP and JavaScript

Imagine you have a cookie set on first.com, called "user". Now, the goal is to retrieve that cookie on second.com using JavaScript and AJAX. Unfortunately, it's not working as expected and you're receiving xmlHttp.status=0. Here is a sample code ...

Overlapping Sidebar obstructing Header section

Within the realm of React js, I have meticulously crafted a Header component and a SideBar (more specifically, a Mini variant drawer) component residing in distinct files. Notably, the SideBar drawer is derived from MUI 5 on the dashboard page. How might o ...

Breaking apart a JavaScript string into specific, fixed-length segments

Is there a more efficient and simpler way to split a string into fixed-length pieces in JavaScript without the use of extra modules or libraries? The current method I'm using involves looping through the string and adding substrings of a specific leng ...

Promise rejection caused by SyntaxError: Unexpected token i found in JSON at position 0 while trying to fetch a raw file from Gitlab

I'm attempting to retrieve a raw file from a Gitlab repository by following the official documentation. Here are the functions in question: methods: { async getProjects(url, method, payload) { const token = this.$store.getters.token ...

When using the v-for directive to display all elements of an array, only the information of the clicked array should be listed when using the

I am facing an issue with my array of locations. There are 2 divs in play - one containing the list of locations and the other displaying additional info when a location is clicked. The problem arises when I click on a specific location, let's say Sc ...

Error: The validation process failed due to missing information. The file name and path are both required for validation

In my current project, I am attempting to upload a file from the frontend to the backend and save it. However, I am encountering an error that looks like this: Error The error message is as follows: this.$__.validationError = new ValidationError(th ...

Comparing MUI Components to React Bootstrap Technologies

Hello everyone! I'm currently working on a project with react js and I have a question for you all. Do you think it's excessive to combine MUI Components and React Bootstrap in the same app? ...

How to generate a hyperlink using the GitHub API with JavaScript/jQuery

I have a table of commits displaying the SHA, author, message, and date of each commit I made in a specific GitHub repository. Is there a way to turn the message column into a clickable link that directs to the corresponding GitHub page showing details of ...

Utilizing JavaScript's Facebook Connect feature on a Ruby on Rails website

My ruby-on-rails web application is in need of integrating "Facebook connect" functionality to enable users to share various activities on Facebook. Are there any Javascript methods I can use for this purpose? Any demos you can suggest? In addition, I wou ...

Tips for focusing on a background image without being distracted by its child elements

I am trying to create a zoom effect on the background-image with an animation but I am encountering issues where all child elements are also animated and zoomed. When hovering over the element, I want only the background part to be animated and zoomed, and ...

Navigate to the location using AngularJS elements in the JavaScript iframe1

Dealing with an issue while working on AngularJS. I am facing a frustrating problem where I am attempting to use one link to open links in two separate iframes. All aspects of this function correctly, except for the actual links. The issue arises when usin ...

Discovering whether x is equal to any value within an array using JavaScript

I am seeking a way to modify my current if statement, which looks like this: if (x==a||x==b||x==c||x==d||x==e) { alert('Hello World!') }; Is there a method to test whether x matches any of the values in an array such as [a,b,c,d,e]? Your as ...

Having trouble importing components in NativeScript Vue?

I am just starting to explore the world of NativeScript and working on my first project using it. I am facing an issue while trying to incorporate a header component into my main App. Unfortunately, when I run the iOS emulator, the header does not appear o ...

Develop a unique splitter code that utilizes pure javascript and css, allowing users to drag and drop with precision

I am facing an issue with setting the cursor above my drop panel, as it results in a flicker effect. How can I set the cursor for my example to work properly? I have tried multiple different approaches to make this work. Although I am using the provided ...