Designing a structure with three fieldset components

I'm currently trying to design a page layout that includes three fieldsets. My goal is to have the first one span across 100% of the width, with the other two positioned side by side below it at 50% width each.

However, I am struggling to achieve this layout. I've set the widths of the two fieldsets to 50% and used display: inline-block;, but they are still being displayed on separate lines.

Here's my code:

ul {
list-style: none;
}
a {
text-decoration: none;
}
#inline {
width :50%;
padding : 0;
margin : 0;
display : inline;
}

input[type=submit]#loc{
margin-left: 75px;
display:inline-block;
}

td {
padding: 10px;
}

label{
    display: inline-block;
    float: left;
    clear: left;
    width: 250px;
    text-align: right;
}
.input input {
  display: inline-block;
  float: left;
}
.inputAdd input {
  display: inline-block;
  float: right;
}
<div class="container">
<div class="main">
 <fieldset class= "spanField">
<legend>Spanned Field</legend>
<form method="post" action="index.php" onsubmit="validation();">
<label>Input 1&nbsp;</label>
<input  type="text" size="20">
<label>Input 2&nbsp;</label>
<input  type="text" size="20">
<input type="submit" value="Add" />
<table style ="display:inline;">
<tr>
<td></td><td>Input</td><td>Input</td>
</tr>
<tr>
<td><button>X</button></td><td>Input 1</td><td>911 1</td>
</tr>
<tr>
<td><button>X</button></td><td>Input 2</td><td>911 2</td>
</tr>
</table>
</form>
 </fieldset><br />
 <fieldset id = "inline" class ="inputAdd">
<legend>Half field</legend>
<form method="post" action="index.php" onsubmit="validation();">
<table>
<tr>
<td></td><td>Input</td>
</tr>
<tr>
<td><button>X</button></td><td>Input 1</td>
</tr>
<tr>
<td><button>X</button></td><td>Input 2</td>
</tr>
</table>
<div style ="float:right;">
<select >
<option>Option 1</option>
</select>
<input type="submit" value="Add" />
</div>
</form>
 </fieldset>
 <fieldset id="inline" class ="input">
<legend>Half Field</legend>
<form method="post" action="index.php" onsubmit="validation();">
<label>Add input&nbsp;</label>
<input  type="text" size="20">
<input type="submit"  value="Add" />
</form>
<table>
<tr>
<td></td><td>Input</td>
</tr>
<tr>
<td><button>X</button></td><td>Input 1</td>
</tr>
</table>
 </fieldset>
</form>

Answer №1

One issue is that the border is included in the width calculation of the elements, causing them to be slightly wider than 50%.

To resolve this, you can use the box-sizing CSS property set to border-box:

 box-sizing: border-box;

You can find more information on various box-sizing properties on the W3Schools website. You'll also need to float the elements using float: left.

Additionally, it appears that you have assigned the same ID to two elements. IDs should be unique, so consider using a class instead:

.inline {
  width: 50%;
  padding: 0;
  margin: 0;
  display: inline;
  box-sizing: border-box;
  float: left;
}

In your HTML code, make sure to update the element with the correct class name:

<fieldset class="inputAdd inline">

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

Creating a flexible image layout within a container with relative positioning

I attempted to create a basic slideshow with images sliding from right to left as an animation: let slides = document.querySelectorAll('.img-container'); let l = slides.length; let i = 0; setInterval(function(){ i = (i + 1) % l; if(i == 0){ f ...

Creating a visual that when clicked, reveals an enlarged version at a different location

Is there a way to make an image appear in a different location on the page when it's hovered over? I've searched online but couldn't find a solution using just HTML and CSS. Does anyone know how to achieve this effect? Image not hovered: ht ...

Using jQuery to create a dynamic fullscreen background image that responds to mouse movement

I am currently working on creating a dynamic full screen background that responds to the movement of the mouse. The idea is that as you move the mouse around, the background image will shift accordingly. For instance, if you were to move the mouse to the ...

Tips on correctly determining font size

I'm attempting to style a span element with a specific height (in this case, 23px). However, the browser is automatically adding some extra pixels to the element. There are no additional styles like padding or margin affecting it, just the size of th ...

HTML - Custom styled <select> element

My goal is to fully customize the style of a component and hide the selector image. All graphical styles such as borders and shadows have been defined in a previous table. Now, I want to remove all styling from the selection menu, including the icon used t ...

Activate jquery to initiate the login modal

I am having trouble getting the login modal to appear using jQuery. I can't seem to figure out why it's not popping up. You can check a similar question here and I followed the answer but still no luck. <script> $(document).ready( ...

Ways to eliminate line breaks and <br> tags in text using only CSS to create a button that trunc

I am currently working on incorporating a truncated text button using only CSS. The issue I'm facing is that the "show more" button doesn't ignore the line breaks or any other relevant HTML within the teaser and text body. This is causing too muc ...

Using setInterval() does not automatically fetch JSON data at a specified interval for me

Attempting to constantly update the latitude and longitude coordinates from a dynamic API has proven to be a challenge. Despite utilizing jQuery with a set interval of 1000 milliseconds, the data retrieval from the API does not occur as expected. While i ...

Flexbox: Distribute remaining space evenly while allowing content to wrap

Is there a method to instruct flexbox items to occupy the available space while wrapping as soon as they become smaller than their content? However, some items have a fixed width percentage. HTML <div class="grid"> <div class="grid__item"> ...

Adding design elements to HTML 5 components

Are there any potential downsides to applying CSS to the <section>, <header>, <article>, and <footer> elements? I vaguely remember reading somewhere that these elements should not be styled, but I can't seem to locate the sourc ...

Enter the ISO code for the country in an HTML form to submit

I'm currently working on a form that requires users to select a country from a list. I came across a website that provides a comprehensive list of countries in HTML format. However, the site displays the full country name but sends the ISO code to the ...

I am unable to determine the origin or background of my sidebar

I am having an issue with styling a sidebar using HTML and CSS. The problem I am facing is with setting the background-color property. Despite my efforts to customize the style, the background remains transparent and shows the color of the page beneath it. ...

The toggle feature of the Bootstrap responsive navbar is not functioning properly

I am currently implementing Twitter Bootstrap in a Rails project, but I'm encountering issues with the responsive navbar. When I resize the screen, the menu toggle button appears along with the navbar options open below it. Upon further shrinking, the ...

The size of Bootstrap 3 columns adjusts dynamically based on the width of the window as the page is being

I am facing an issue with the layout of my bootstrap site when resizing the 3 horizontal columns based on the window size upon page load. Currently, I have a script that adjusts the height of each column to match the tallest one so they appear uniform whe ...

jQuery Drag Drop Sorting Feature Fails to Work when Moving Items from List to Table Cell

I need assistance with creating a sortable list that can have its items dragged into a table cell, where the items can then be sorted within that cell. The process involves: Dragging a list item into the table cell. Sorting the list item in the secon ...

Adjusting the text color of cells in a table based on their values using Ruby on Rails

I have a cell within a table that is formatted like this: <td><%= play_result.timestamp.strftime("%H:%M:%S") + ' ' + play_result.status + ':' + ' ' + '[' + play_result.host + ']' + ' ' ...

Sample Source Code for Jssor Slider

Is there a way to replicate the slider effect shown in this example using Jssor Slider without any available sample code or source? I would greatly appreciate any assistance with achieving this. Thank you ...

What is the correct way to utilize ng-if/ng-show/ng-hide to hide or show HTML elements within the app.run function

I am currently working on developing an app that loads views correctly. HTML: <body> <loading outerWidth='1000' outerHeight='1000' display='isReady'></loading> <div class='wrapper' ng-sho ...

Tips for obtaining the accurate HTML code format using Angular 2's input feature:

I am looking to retrieve all the code with an input as [input] and a tag as #tag. When attempting to obtain HTML code with jQuery using console.log($("#content")[0].outerHTML);, this is an example of how the code looks: <div dnd-droppable [dropZones]= ...

Obtain the VW/VH coordinates from an onclick action in JavaScript

With this code snippet, you'll be able to retrieve the x and y coordinates of a click in pixels: document.getElementById("game").addEventListener("click", function(event) { console.log(event.clientX, event.clientY); }); However ...