Attempting to gather details adjacent to a web form using HTML and CSS

I'm currently working on an HTML page that includes a form and some information. I've created two classes in CSS - one for the form called .contactform, and another for the information called .contactinformatie.

My aim is to position the information next to the form, but unfortunately, it's not displaying as intended. Here is the current layout of my page (the information appears below the form instead of beside it):

View Image Here

Could you please provide guidance on how I can resolve this issue?

Below are snippets of my HTML code:

<div class="contactform">
<h3> Your Information: </h3>
<form action="">
     Name*<br>
    <input type="text" name="Name" value="Tom">
    <br><br>
     Email Address*<br>
    <input type="text" name="email" value="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0e7a61634e69636f6762206d6163">[email protected]</a>">
    <br><br>
     Phone Number<br>
    <input type="text" name="phone number" value="020-694-2033">
    <br><br>
     Your Inquiry<br>
    <textarea id="txtarea" rows="10" cols="70" value="How can I add a flight number?"></textarea>

    <br><br>
    <input type="submit" value="Submit">
</form>
</div>

<div class="contactinformatie">
    <p>You can reach us by phone 24 hours a day</p>  <p>020-5 160 160</p>
    <br>


    <p>Email: </p> <p><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bcc8d9cfc8fcd4cadd92d2d0">[email protected]</a></p>
    <br><br><p>Address: </p> <p>Wibautstraat 44</p>

</div>

Here's a snippet of my CSS code:

.contactinformatie {
     float:right;
     margin: auto;
     width: 48%;
     height: 50%;
 }

.contactform {
    margin-top: 80px;
    margin-left: 50px;
}

If possible, could you advise me on how to properly align the information next to the form using CSS?

Answer №1

To implement this, you can utilize the power of flexbox as shown in the code snippet below. I have enclosed your contactform and contactinformatie elements within a container and defined the styles for it. Here is how you can do it:

.container {
  display: flex;
}

.contactinformatie,
.contactform {
  width: 100%;
  height: 100%;
}
<div class="container">
  <div class="contactform">
    </h3>
    <form action="">
      Name*<br>
      <input type="text" name="Name" value="Tom">
      <br><br> Email address*<br>
      <input type="text" name="email" value="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="50243f3d10"><email protected></a>">
      <br><br> Phone number
      <br>
      <input type="text" name="phonenumber" value="020-694-2033">
      <br><br> Your question<br>
      <textarea id="txtarea" rows="10" cols="70" value="How can I add a flight number?"></textarea>

      <br><br>
      <input type="submit" value="Send">
    </form>
  </div>

  <div class="contactinformatie">
    <p>You can reach us by phone 24/7</p>
    <p>020-5 160 160</p>
    <br>


    <p>Email:</p>
    <p><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1e6a7b6d72">[email protected]</a></p>
    <br><br>
    <p>Address:</p>
    <p>Wibautstraat 44</p>

  </div>
</div>

Answer №2

To achieve the desired layout, apply float to both contactform and contactinformatie classes. It is important to remember to clear the float after these 2 elements.

.contactform, 
.contactinformatie {
  width: 50%;
  float: left;
}

Answer №3

To create a horizontal layout, ensure that all wrapping elements have 'display: inline-block' added

.contactinformation {
  display: inline-block; 
  margin: auto;
  width: 48%;
  height: 50%;
}

.contactform {
 display: inline-block;
 margin-top: 80px;
 margin-left: 50px;
 max-width: calc(100% - 48% - 50px)
}

Answer №4

The issue you're facing arises from the fact that one of your div elements is set to float, while the other does not accommodate the consequences of this styling. To resolve this, both elements should be set to float in order to achieve the desired layout.

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
}

.contactinformatie {
  padding: 50px;
  float:right;
  width: 50%;
 }

.contactform {
  padding: 50px;
  float: left;
  width: 50%;
}

To see everything in action, you can check out this codepen:

https://codepen.io/anon/pen/yRgZXG

Answer №5

.contactinformatie {
     margin-left: 50px;
     width: 48%;
     height: 50%;
 }

.contactform {
    margin-top: 80px;
    margin-left: 50px;
}
<div class="contactform">
<h3> Uw gegevens: </h3>
<form action="">
     Naam*<br>
    <input type="text" name="Naam" value="Tom">
    <br><br>
     Email adres*<br>
    <input type="text" name="email" value="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="42362d2f02252f232b2e6c212d2f">[email protected]</a>">
    <br><br>
     Telefoonnummer<br>
    <input type="text" name="telefoonnummer" value="020-694-2033">
    <br><br>
     Uw vraag<br>
    <textarea id="txtarea" rows="10" cols="70" value="Hoe kan ik een vluchtnummer toevoegen?"></textarea>

    <br><br>
    <input type="submit" value="Versturen">
</form>
</div>

<div class="contactinformatie">
    <p>U kunt 24 uur per dag telefonisch contact met ons opnemen </p>  <p>020-5 160 160</p>
    <br>
    <p>Email: </p> <p><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2450415750644c52450a4a48">[email protected]</a></p>
    <br><br><p>Adres: </p> <p>Wibautstraat 44</p>
</div>

Please review the code above.

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

Is AngularJS governed by a distinct set of guidelines for ARIA implementation?

I am currently working on updating a website to ensure compliance. The site is predominantly built using AngularJS, which I am still in the process of learning. I encountered an interesting situation where there is a label targeting a div element without a ...

What methods can I use to ensure that the columns and rows in Vue are of the same size and length

Upon examining the image, it's clear that none of the columns and rows align properly and are all varying sizes. I am relatively new to JavaScript and Vue, so any assistance would be greatly appreciated. As far as my understanding from online resource ...

The AJAX functionality seems to be malfunctioning within my JavaScript code, so I am considering skipping the AJAX

Abort the execution of the ajax function function calculateWeeks(){ var weekCount={}; $.ajax({ url:"http://localhost:8080/getWeeeks", headers: { 'Content-Type': 'application/x-www-form-urlencoded' ...

Web element not detected within Span Tag

Within my HTML, I have the following: <span class="login-link">Log in</span> The code snippet I am using is: driver.findElement(By.cssSelector("#login > span")).click(); I have tried utilizing xPath, cssSelector, and id, but none of them ...

Content on the website that adjusts to different screen sizes horizontally, while maintaining a

Currently, I am working on developing a responsive website using Bootstrap. While the layout works well when resizing the window horizontally, there is an issue with vertical resizing. I do not want the height of the elements (such as Bootstrap columns, im ...

Adjust for the region shifted using transform: translate

I'm currently working on adjusting the positioning of elements using transform: translateY in CSS. The challenge I am facing is eliminating the empty space that appears between elements after repositioning one element below another without altering th ...

Having trouble arranging the elements when swapping within a pop-up modal

When I drag and drop two divs inside a modal popup, their positions shift down during the animation. I am struggling to fix this issue. HTML Code: <title> Tile Swapping with Animation</title> <body> <button type="button" class=" ...

Use the toggle function in pure JavaScript to apply it only to the element that has been clicked

In this HTML code snippet, I am displaying data in a list format with nested subcategories. Each category is displayed as a clickable parent menu item. When clicked, the corresponding subcategories should be toggled to show or hide. <ul id="menu"&g ...

What causes slow performance in Asp .Net MVC? What specific steps occur between Application_BeginRequest and the start of processing the shared view?

I have come across several questions on this platform, all with responses suggesting to "set profiling and you got answer". However, I am unable to set profiling on my destination server. What happens between Application_BeginRequest and shared view proces ...

Is there a way to conceal :before content in the parent element by hovering over the child element?

Here is the HTML code I currently have: <li *ngFor="let menu of menus" class="{{ menu.attributes.class }} menu-items" [attr.data-title]="menu.label"> <a [routerLink]="[menu.url||'/']" [queryParams]="menu.refParameter3 ? menu.refPara ...

Guide to placing an image in a designated position

I am looking to achieve the following scenario: Whenever a user uploads an image, it should appear in one of the smaller boxes on the right. Subsequent image uploads by clicking on the big box should populate the other small boxes on the right. Please refe ...

Transform JavaScript code into HTML using jQuery.`

I have a piece of HTML and JavaScript code. The JavaScript code is currently in jQuery, but I want to convert it to vanilla JavaScript: // Vanilla JavaScript code document.querySelectorAll('.hello[type="checkbox"]').forEach(item => { item ...

Utilizing SCSS to customize specific dimensions

Currently, I am diving deeper into the world of scss and finding myself a bit perplexed by certain aspects. I'm hoping for some guidance from knowledgeable individuals. One issue I am facing involves defining different font sizes for various headings ...

Creating a dynamic menu with JQuery

I'm working on a form that contains two hidden parameters that need to be passed to the LoadView function. <form name="frm1" action="http://localhost/tddd27/index.php/AddProduct/LoadView"> <input type="text" name="ID" value="<?php echo $ ...

Unique button for custom "CODE" in Froala

Looking to create a custom button with functionality similar to bold (B) but for source code (Src). I have attempted the following, however it is not fully functional: $("#elm1").editable({ inlineMode: false, minHeight: 300, buttons: ["src"], c ...

"Exploring the Impact of Font Style on Text Color in Gtk3 Text

After creating a CSS provider using gtk_css_provider_new and loading it with gtk_css_provider_load_from_data, the style data "textview { color: red; font: 30px serif; }" is applied to a gtk_text_view using gtk_style_context_add_provider. However, the resul ...

The icons from Materialize CSS are not displaying properly in the Safari web browser

It has come to my attention that the icons in Materialized CSS are not displaying properly in Safari (v5.1.7). Despite conducting thorough research on this issue, I have been unable to find any documentation regarding browser compatibility with Safari. Can ...

Angularjs: Adding Negative and Positive Numbers

How can I extract negative numbers and positive numbers separately from JSON data obtained from the server using the $http.get method? One of the fields in the data is called Credits, which contains both negative and positive values. Can anyone help me wit ...

Generating div elements of varying colors using a combination of Jinja templating and JavaScript loop

Utilizing jinja and javascript in my template, I am creating multiple rows of 100 boxes where the color of each box depends on the data associated with that row. For instance, if a row in my dataset looks like this: year men women 1988 60 40 The co ...

Contrast between action="" and action="#" attributes in HTML

There are two ways I've come across for setting a form's action attribute. #1. Using an empty string as the action attribute value: action="" #2. Specifying a hash symbol (#) as the action attribute value: action="#" What distingishes these ...