Position a form in the center of a container and showcase an additional div on the right with an indentation

My goal is to center a form within a div and have another div on the right that is slightly indented, but I'm struggling to align the elements properly.

How can I achieve this layout using CSS?

Additionally, is there a way to center the right-hand div on a new line if the content exceeds the page width?

.lander-form {
  margin: auto;
}

.lander-add {
  float: right;
  margin-right: 50px;
}

.container-lander {
  overflow: auto;
  width: 100%;
}

#OEPL_Widget_Form {
  min-width: 200px;
  max-width: 399px;
  margin: auto;
  font-weight: 300;
  background-color: #F9F9F9;
  box-shadow: 5px 5px 5px #888888;
  padding-top: 10px;
  padding-right: 20px;
  padding-bottom: 10px;
  padding-left: 20px;
  text-align: left;
  border: 3px solid #d9d9d9;
}

#OEPL_Widget_Form div {
  margin-top: 10px;
  text-align: left;
}

#OEPL_Widget_Form input,
button {
  width: 100%;
  padding: 3px 5px;
}

.OEPL_Widget_Form textarea {
  width: 100%;
  padding: 3px 5px;
  height: 5em;
  text-align: left;
}
<div class="container-lander">
  <div class="lander-form">
    <div class="widget widget_oepl_lead_widget">
      <div align='center' class='LeadFormMsg' style='color:red'></div>
      <form id='OEPL_Widget_Form' class='OEPL_Widget_Form' method='POST' enctype='multipart/form-data'>
        <div style='width: 45%; float:left'>
          <p class='small'><label>First Name <span style='color: red'>*</span> :</label><br><input type='text' /></p>
        </div>
        <div style='width: 45%; float:right'>
          <p class='small'><label>Last Name <span style='color: red'>*</span> :</label><br><input type='text' /></p>
        </div>
        <div>
        </div>
        <p class='small'><label>Your Message <span style="color: red">*</span> :</label><br><textarea cols="30" rows="5"></textarea></p>
        <p><input type='submit' name='submit' style='' value='Submit' id='WidgetFormSubmit' class=''></p>
      </form>
    </div>
  </div>
  <div class="lander-add">
    <div class="laura" id="laura-935032319"><img width="200" src='http://www.freevectors.net/files/large/10CarsVectorSet.jpg' /></div>
  </div>
</div>

Answer №1

To achieve the desired layout of having two divs side-by-side, you need to use float:left;. The two divs in question are identified as .lander-form and .lander-add. Currently, the issue lies in the fact that .lander-add is set to float:right;, which is a common mistake among beginners. Both halves of the page should actually be set to float:left; for the layout to display correctly.

I have made adjustments by setting the width of .lander-form to 65%, adjusting the margins accordingly, and setting the width of .lander-add to "auto". These modifications should ensure that the right half of the page appears below the left one when the viewing area is small or resized. You can observe the difference between the result displayed below and the full-size result page when running the updated code snippet.

.lander-form {
  margin: auto;
  float:left;
  width:65%;
  margin-bottom:20px;
  margin-right:15px;
}

.lander-add {
  float: left;
  min-width:20%;
  width:auto;
}

.container-lander {
  overflow: auto;
  width: 100%;
}

#OEPL_Widget_Form {
  min-width: 200px;
  max-width: 399px;
  margin: auto;
  font-weight: 300;
  background-color: #F9F9F9;
  box-shadow: 5px 5px 5px #888888;
  padding-top: 10px;
  padding-right: 20px;
  padding-bottom: 10px;
  padding-left: 20px;
  text-align: left;
  border: 3px solid #d9d9d9;
}

#OEPL_Widget_Form div {
  margin-top: 10px;
  text-align: left;
}

#OEPL_Widget_Form input,
button {
  width: 100%;
  padding: 3px 5px;
}

.OEPL_Widget_Form textarea {
  width: 100%;
  padding: 3px 5px;
  height: 5em;
  text-align: left;
}
<div class="container-lander">
  <div class="lander-form">
    <div class="widget widget_oepl_lead_widget">
      <div align='center' class='LeadFormMsg' style='color:red'></div>
      <form id='OEPL_Widget_Form' class='OEPL_Widget_Form' method='POST' enctype='multipart/form-data'>
        <div style='width: 45%; float:left'>
          <p class='small'><label>First Name <span style='color: red'>*</span> :</label><br><input type='text' /></p>
        </div>
        <div style='width: 45%; float:right'>
          <p class='small'><label>Last Name <span style='color: red'>*</span> :</label><br><input type='text' /></p>
        </div>
        <div>
        </div>
        <p class='small'><label>Your Message <span style="color: red">*</span> :</label><br><textarea cols="30" rows="5"></textarea></p>
        <p><input type='submit' name='submit' style='' value='Submit' id='WidgetFormSubmit' class=''></p>
      </form>
    </div>
  </div>
  <div class="lander-add">
    <div class="laura" id="laura-935032319"><img width="200" src='http://www.freevectors.net/files/large/10CarsVectorSet.jpg' /></div>
  </div>
</div>

Answer №2

To create efficient layouts, utilizing the flex property is a popular choice. You can implement this technique on your .container-lander element to organize items side by side while also vertically centering them (in addition, the layout will adjust to wrap items when space is limited):

CSS:

.container-lander {
    display: flex;
    flex-flow: row wrap;
    justify-content: space-evenly;
    align-items: center;
}

For a demonstration, check out this live example on JSFiddle.

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

On a Samsung tablet with Moodle, the body background image is set to display at the top

Encountered an issue with Sambungs tables. I have a background image set on the body. Here is how the CSS looks: html, body{ background: url('img/background.jpg') no-repeat; background-position: top; // I also tried cover, fixed, etc } The ...

Is it possible to embed HTML within standard PHP without using alternative methods?

Is it possible to embed HTML inside a PHP "if" statement? The top-rated answer in this thread on Stack Overflow discusses using alternative if style. While other answers suggest that it also works with normal if statements, the question remains: is this a ...

Dynamic class name changes in Angular.js based on JSON object

I am trying to dynamically change the class of an <li> element based on the category value I am getting, but for some reason the class name won't update. Here is the code snippet: <div id="content"> <ul id="container" ng-controller ...

Is there a way to keep the middle div at a fixed width while the left and right divs adjust their size as the screen gets smaller in a row with 3 divs?

Having 3 divs in a single row can be quite challenging. <div id="left"></div> <div id="middle"></div> <div id="right"></div> This layout requires the middle div to have a fixed width, while the left and right divs adju ...

Is the IE7 Modal Dialog Misaligned?

Update After some investigation, I discovered the root cause of the problem. In my code, I was referencing the height of the overlay, which resulted in different values in IE7 compared to other browsers. To resolve this issue, I adjusted the code to refe ...

What is the best approach to obtain an inventory of inputs from a particular viewpoint?

I am facing an issue where I have a list of products that require the quantities to be returned along with the reason for return. However, I cannot modify the referenced model as it has an impact on multiple values. Can someone guide me on how to retrieve ...

Tips for safeguarding user input data in the event of a Jeditable ajax post failure

Seeking a solution with Jeditable for retaining textarea data and keeping the form visible in case of failed ajax post due to issues like network problem or server error. Is there a way to achieve this with Jeditable? Thanks! ...

Achieving consistent width for flex items in each row

Can I ensure that all flex items have the same width? Currently, my code looks like this: .video-container { background-color: blue; min-height: 90vh; display: flex; flex-wrap: wrap; } .video { flex: 1 0 25%; } <div class="video-contain ...

Expanding the clickable area of a link using the CSS :before pseudo-element selector

I am currently working on a project involving an image slider and I am facing a challenge with the "previous" and "next" arrows. My goal is to have each arrow occupy half of the slider area, but adjusting padding or margins tends to change their position o ...

How to apply a custom CSS class to a Smarty tag in CMS Made Simple

Greetings! I am currently in the process of revamping a page using CMSmadesimple, However, I have limited knowledge when it comes to utilizing CMSms and Smartytags. The page contains various smartytags that require styling. One particular tag that needs ...

Change shapes of figure blocks using Internet Explorer (I am using IE11)

Good day! I have implemented this code to create a flip effect on the blocks of my website: .tegels { /*position:relative;*/ width:25.2%; height:37.4%; overflow:hidden; float:left; margin-top:3.5vw; margin-bottom:0px; m ...

Creating a customized tooltip without the need for calling $(document).foundation() and using modernizr

I'm facing an issue with initializing the foundation tool-tip without having to initialize everything (such as $(document).foundation()). It seems like a simple task, but I am struggling. I have two questions in mind: (1) How can I utilize new Founda ...

Bootstrap doesn't display in the dropdown menu

Struggling to get a dropdown menu to display on my page, my HTML code is: <div class="dropdown d-inline"> <div class="widget-header mr-3"> <button href="#" class="icon icon-sm rounded-circle border" data-toggle="dropdown"><i cl ...

Display a full-width card beneath each small card in every row using CSS

In a scenario where I have designed a layout consisting of 3 column/row cards across multiple rows. Each card displays basic information, and when a user clicks on any specific card, a full-width card below that row will display more detailed information. ...

Loading elements of a webpage in a consecutive order

I am currently working on implementing a content slider within my Django application. The specific slider that I am using can be found at this link. One challenge that I am facing is the need to load close to one hundred 'contentDiv' pages, and I ...

Utilize and store images based on the individual user's preferences with PlayCanvas

Currently, I am immersed in a PlayCanvas endeavor where I am trying to render specific objects with textures of my choice. The main issue arises when I come across the config.json file in the PlayCanvas build. Within this file, there is a designated path ...

Send information using AJAX within a .NET integrated browser

In our current setup, we utilize a .NET embedded browser to showcase an HTML page that is generated by applying an XSLT file to an XML file using .NET. This process results in HTML content displayed within the embedded browser through the DocumentText prop ...

What is the reason behind Flask's choice to return <embed> files for download rather than simply displaying them

When I try to render a template using Flask that includes images, the files are being downloaded instead of displayed. For example, <embed src="static/yes.svg" type="image/svg+xml"> If I place this code inside test.html and view it in Google Chrom ...

Enlargen div or unordered list according to content exceeding limits

What is the best way to ensure a div expands when it contains a lot of content? Code Example (HTML): <div class="content"> Content goes here <br /> Content goes here <br /> Content goes here <br /> Content goes her ...

Tips for positioning a div element within the body of a webpage to maintain a predetermined height and width

Currently, I am developing a single-page application using AngularJS. I have specific routes in mind where I want to introduce new HTML templates. To accomplish this, I have created a container labeled with the ID #main positioned between two navbars (he ...