What is the best way to position a textarea and text input on top of each other alongside a radio button?

Currently struggling with the layout of a website project, specifically positioning a text input and a textarea above each other next to a larger radio box. I came across a similar issue on Stack Overflow but unfortunately, it did not solve my problem. Ideally, I need the layout to be like this: https://i.sstatic.net/MUApR.png

.szavazas {
  margin-left: 5%;
  margin-top: 3%;
}

.raddio {
  float: left;
  width: 200px;
  margin-bottom: 5%;
  color: white;
  background: green;
  border-radius: 8px;
  border: 1px solid #003300;
  text-align: left;
  box-shadow: 0 0 2px 1px black;
  height: 350px;
}

input[type="radio"] {
  text-align: left;
  margin-top: 10px;
  margin-bottom: 10px;
}

.velemeny {
  float: left;
  box-shadow: 0 0 2px 1px black;
  width: 200px;
  height: 175px;
}

.textin {
  float: left;
  border: 1px solid black;
  background-color: #003300;
  color: white;
  width: 200px;
  height: 165px;
}
<div class="szavazas">
  <form class="raddio" action="/action_page.php">
    <input type="radio" name="plant" value="Large Flamingo Flower">Large Flamingo Flower<br>
    <input type="radio" name="plant" value="Gerbera">Gerbera<br>
    <input type="radio" name="plant" value="Indoor Runner Plant">Indoor Runner Plant<br>
    <input type="radio" name="plant" value="Crab Flower">Crab Flower<br>
    <input type="radio" name="plant" value="Green Finch">Green Finch<br>
    <input type="radio" name="plant" value="Ivy">Ivy<br>
    <input type="radio" name="plant" value="Azalea">Azalea<br>
    <input type="radio" name="plant" value="Mother-in-Law's Tongue">Mother-in-Law's Tongue<br>
    <input type="radio" name="plant" value="Variegated Dragon Tree">Variegated Dragon Tree<br>
    <input type="radio" name="plant" value="Philodendron">Philodendron<br>
  </form>
  <textarea class="opinion" rows="7" cols="40" placeholder="Share your opinion about the plant/flower and if you have encountered it before."></textarea>
  <form class="textin" action="/action_page.php">
    Here will be some long text that I will write here.<br>
    <input type="text" name="otherplant">
  </form>
</div>

Answer №1

To achieve the desired alignment, you can utilize the powerful flex property in CSS. This property allows you to create various layouts according to your needs.

Refer to the code snippet below for a better understanding and a starting point:

Learn more about flex: https://codepen.io/enxaneta/full/adLPwv/

.layout {
  display: flex;
}

.right-side {
  display: flex;
  flex-direction: column;
}

.szavazas {
  margin-left: 5%;
  margin-top: 3%;
}

.raddio {
  float: left;
  width: 200px;
  margin-bottom: 5%;
  color: white;
  background: green;
  border-radius: 8px;
  border: 1px solid #003300;
  text-align: left;
  box-shadow: 0 0 2px 1px black;
  height: 350px;
}

input[type="radio"] {
  text-align: left;
  margin-top: 10px;
  margin-bottom: 10px;
}

.velemeny {
  float: left;
  box-shadow: 0 0 2px 1px black;
  width: 200px;
  height: 175px;
}

.textin {
  float: left;
  border: 1px solid black;
  background-color: #003300;
  color: white;
  width: 200px;
  height: 165px;
}
<div class="layout">
  <div class="left-side">
    <form class="raddio" action="/action_page.php">
      <input type="radio" name="noveny" value="Nagy Flamingóvirág">Nagy Flamingóvirág<br>
      <input type="radio" name="noveny" value="Gerbera">Gerbera<br>
      <input type="radio" name="noveny" value="Szobai Futóka">Szobai Futóka<br>
      <input type="radio" name="noveny" value="Rákvirág">Rákvirág<br>
      <input type="radio" name="noveny" value="Zöldike">Zöldike<br>
      <input type="radio" name="noveny" value="Borostyán">Borostyán<br>
      <input type="radio" name="noveny" value="Azálea">Azálea<br>
      <input type="radio" name="noveny" value="Anyósnyelv">Anyósnyelv<br>
      <input type="radio" name="noveny" value="Tarka Sárkányfa">Tarka Sárkányfa<br>
      <input type="radio" name="noveny" value="Filodendron">Filodendron<br>
    </form>
  </div>

  <div class="right-side">
    <textarea class="velemeny" rows="7" cols="40" placeholder="Share your thoughts on the plant/flower and any experiences you've had with it."></textarea>

    <form class="textin" action="/action_page.php">
      Here will be some lengthy text that I will write here <br>
      <input type="text" name="otherplant">
    </form>
  </div>
</div>

Answer №2

After applying some modifications to your code, I was able to achieve the following result. I hope this meets your requirements.

.raddio, .right-side {
    float: left;
    width: 300px;
    margin-bottom: 5%;
    color: white;
    background: green;
    border-radius: 8px;
    border: 1px solid #003300;
    text-align: left;
    box-shadow: 0 0 2px 1px black;
    height: 350px;
}
.right-side{
    width: 205px;
    margin-left: 15px;
    border-width:0;
    background: transparent;
    box-shadow: none;
}

input[type="radio"] {
    text-align: left;
    margin-top: 10px;
    margin-bottom: 10px;
}

.velemeny {
    /* float: left; */
    box-shadow: 0 0 2px 1px black;
    width: 200px;
    height: 175px;
    border-radius: 8px;
    box-sizing: border-box;
    margin-bottom: 15px;
}

.textin {
    /* float: left; */
    border: 1px solid black;
    background-color: #003300;
    color: white;
    width: 200px;
    height: 160px;
    border-radius: 8px;
    padding: 10px;
    box-sizing: border-box;
    box-shadow: 0 0 2px 1px black;
    }
    <div class="layout">
        <form class="" action="/action_page.php">
            <div class="left-side raddio">
                <input type="radio" name="noveny" value="Nagy Flamingóvirág">Nagy Flamingóvirág<br>
                <input type="radio" name="noveny" value="Gerbera">Gerbera<br>
                <input type="radio" name="noveny" value="Szobai Futóka">Szobai Futóka<br>
                <input type="radio" name="noveny" value="Rákvirág">Rákvirág<br>
                <input type="radio" name="noveny" value="Zöldike">Zöldike<br>
                <input type="radio" name="noveny" value="Borostyán">Borostyán<br>
                <input type="radio" name="noveny" value="Azálea">Azálea<br>
                <input type="radio" name="noveny" value="Anyósnyelv">Anyósnyelv<br>
                <input type="radio" name="noveny" value="Tarka Sárkányfa">Tarka Sárkányfa<br>
                <input type="radio" name="noveny" value="Filodendron">Filodendron<br>
            </div>

            <div class="right-side">
                <textarea class="velemeny" rows="7" cols="40" placeholder="Share your opinion about the plant/flower and if you have come across it before?"></textarea>

                <div class="textin">
                    Here will be some long text that I will write here <br>
                    <input type="text" name="anotherplant">
                </div>
            </div>
        </form>

    </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

Using an image tag within a button element causes functionality issues with JavaScript on Chrome

Can anyone help me figure out why my button with an image isn't toggling a div's class in Chrome? It works fine in Firefox. Here is the codepen link for reference: https://codepen.io/luansergiomattos/pen/zydWyM This is the HTML code: <div cl ...

How can I switch the default browser in the most recent version of visual studio code?

Question: The default browser is IE, but I am looking to switch to a different browser. How can I make this change? ...

Emphasize the currently selected element in jQuery and convert its attributes into a

In an effort to enhance accessibility debugging, I've been working on a script that can identify which element has focus and display it in the console. However, I'm only interested in seeing what is printed in the HTML, not every single detail. S ...

Displaying and Concealing Elements with AngularJS and Implementing Alternating Styles

Within my collection of div elements showcasing product information, there is a need to display or hide specific fields based on the product type. While this functionality works smoothly, we now aim to enhance readability by implementing alternating row st ...

Is there a way to shift the page footer and bar down to the very bottom of the screen?

Is it possible to move the footer and footer bar to the very bottom of the page instead of just under the contents? I'm currently using the Sydney theme for WordPress and want the footer to sit across the bottom of the full-screen image. .footer-wid ...

Why isn't it working? Looking for a script that adds a class when the element is empty?

I have a script that should add the class "leftmax" to the li element with id "spect" when the div element with id "tab2" is empty, but it doesn't seem to be working. Can someone provide some assistance? <script type="text/javascript"> $(funct ...

Creating static pages using React

I am aiming to have my React application operating on the client-side through Amazon S3 (CDN), with news files being created in order to incorporate meta tags for social media sharing, particularly with Facebook. For instance, when a user shares , I envis ...

Implementing an alert box upon redirect with PHP

This question is pretty straightforward. I have a form on my index.html page and PHP code to submit that form to an external URL, then redirect back to the index: <?php Echo "<style>body{background:#3e4744}</style>"; Echo "<style>h2{ ...

TinyMCE single quote

Currently, I am utilizing the latest version of TinyMCE as my text editor. While it has many great features, there are a few persistent issues that have been causing me some confusion. One major issue is with apostrophes. For example, Hello it's me! ...

Issue encountered: Inoperable binding when employing ko.mapping with two distinct models

I've been struggling to implement a drop-down select in conjunction with a table on a page using knockout bindings. The issue arises when I try to use the mapping options in the knockout binding plugin – either the drop-down or the table behaves inc ...

What is the best way to show a block of text when hovering over an image with a smooth easing effect

How can I make a block of text appear with ease when hovering over an image of a tree? The current setup works, but the transition effect is not as smooth as I want it to be: HTML: <p id="hover-text1" class="hover-text1"> Accomplished! </p> & ...

Include a class for CSS styling in EJS using Node.js

Attention: Please be aware of the environment in this Application. The following technologies are being used: Windows NPM, Express MySQL This is the code in an ejs template called example.ejs <% if (message) { %> <p class="al ...

What is the best way to eliminate additional spacing within Bootstrap 4 cards?

I'm really struggling to figure this out. The cards in this section are not centered horizontally, even though I used bootstrap grid. They seem to be taking up extra space that isn't padding or margin-related. Any advice on how to fix this issue ...

What is the best way to extract styled HTML tags from I18N properties files using the Makara module in conjunction with Express and Kraken.js?

I'm currently utilizing Makara, an I18N module designed for Kraken.js and Express.js. Imagine a scenario where I need to format a specific word within a sentence, but its placement varies based on different languages. I want to ensure that this can b ...

Adding clickable text to dynamically generated tables using JavaScript

I've created a dynamic table populated with data from a JSON response. This table consists of 3 columns - one for Serial Number, another for Name, and the third column is meant to have two clickable text links labeled as Edit and Delete. When clickin ...

There are occasions when the Phaser sprite.kill() function fails to execute

Currently, I am developing games using Phaser and have encountered an issue with the sprite.kill() method. At times, when I invoke sprite.kill(), it appears that Phaser destroys the body for collisions/overlapping, but the visual elements (image and dragg ...

Styling a list using multiple columns with CSS

My goal is to design a columned list using only HTML and CSS. I have experimented with floats and inline-block, but it seems like inline-block is the best option for me due to these specific requirements: The layout must be in columns; The number of colu ...

Excessive content in Bootstrap Table

I am currently facing an issue with two tables placed side by side using the Bootstrap grid system. While the tables are dynamic and visually appealing, I encounter a problem when adding lengthy strings dynamically. The overflow of text within the table ca ...

Transmitting information from JavaScript to PHP server results in receiving a 500 Error

I have been exploring various code examples and techniques to transmit data from my website to the server's database. After evaluating different options, I concluded that making an ajax call to send the data would be the most efficient method. Here i ...

Switching the body's background image dynamically using javascript

I'm attempting to switch up the background image using JavaScript. Here's how I've defined the background: body { background: black; overflow-x: hidden; overflow-y: hidden; } body:before { overflow-x: hidden; overflow ...