css three columns evenly spaced in the center

I am currently using bootstrap, CSS, and HTML to design a responsive webpage with three columns in a row. The layout consists of a textbox on the left, a button in the center, and a table on the right.

So far, I have made three separate attempts at achieving this: (to view the code for the first attempt, open jsfiddle and search for: <!-- output box 0 -->)

https://jsfiddle.net/martinradio/adqLpxn5/57/

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

I am specifically focused on fixing attempt 1 as it provides the best responsiveness when resizing the page to be very thin

  • Attempt 1 I tried replicating this example, although the boxes are centered, I am struggling to adjust the width of the middle 'copy' box. I attempted setting the style of the middle box to a width of 10%, but encountered some difficulties.

  • Attempt 2 I utilized raw bootstrap col and row elements to create one row with three columns. While adjusting the width of the left box was simple, styling the middle copy button proved to be more challenging.

  • Attempt 3 In my original code, I managed to finalize the design of all three boxes according to my vision, however, making them responsive has been an issue.

All three attempts represent my efforts in mastering a css task: developing a responsive row comprised of three columns - col1 with a width of 45%, col2 with a width of 10%, and col3 with a width of 45%

Answer №1

I didn't have enough time to review all your attempts, so I focused on attempt number 2.

Let's discuss why this layout isn't functioning as required with the 3 columns positioned side by side:

  • In Column 1, the textarea, everything seems fine (although setting cols="2" is unnecessary since you're already defining its width). The textarea has the default browser styling of display:inline, but it behaves like display:inline-block due to some unknown factor considering its width.
  • In Column 2, the button, there are no issues (it displays as display:inline-block thanks to Bootstrap).
  • In Column 3, the div, the default display is block provided by the browser. This causes a problem in aligning it to the right of Column 2. You need to set display: inline-block. Furthermore, the width is currently set at 200% while the requirement is 45%, so this adjustment must be made accordingly.

The Challenge of Inline Rendering & White Space in HTML Source Code

Even after fixing Column 3 as mentioned above, the columns may still not appear side by side. Instead, Column 3 might remain on a separate line despite their total widths adding up to 100%.

Why does this happen?

The issue lies in the white space between the columns in your original HTML code. Within a block context created by the containing div, any white space > 0 (including new lines) between inline tags will result in the browser inserting a single "space".

For instance:

<div>
   <div style="display:inline-block">[one]</div>
   <div style="display:inline-block">[two]</div>
</div>

...would render as:

[one] [two]
     ^
     observe the space in between

This occurs due to the new line and subsequent spaces between the closing tag of div (one) and the opening tag of div (two), introducing extra white space between the two inline-block elements in the HTML source.

Solutions to Address This Issue

Two recommended approaches:

  1. The straightforward solution: Eliminate the white space between the elements in the HTML markup.
    Ensure that the opening tag of each column immediately follows the closing tag of the preceding column.
  2. Alternatively, apply font-size: 0 to the container element and specify font-size: <some-size> for each individual column.
    This method effectively reduces the "space" between the columns to zero width.

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

The SVG format quickly displays new and larger datasets on line charts without any transition effects

My goal is to create a line chart with animated transitions similar to this demo, but without the dots. I am attempting to integrate this functionality into a react component where the update method can be triggered by another component, allowing the d3 op ...

Send the contents of a `<ul>` element to the server using AJAX for form submission

Can someone assist me in submitting a serialized <ul> list through an AJAX post form request? I need help with this process. Below is my current code snippet. HTML: <form id="update_fruit_form" method="post" action="/update_fruits" accept-charse ...

Tips on integrating Angular's ui-grid with an array of strings

I have utilized Angular ui-grid to display an array of json objects received in the response. However, my current scenario involves getting an array of string values instead. How should I configure the grid for this situation? $http.get(url) .success(func ...

The Holy Alliance of Laravel and Vue

I am facing issues with user authentication using Laravel Sanctum. I have set up everything properly, with Vite and Vue 3 as the frontend. The problem arises when I attempt to login with Laravel's default auth - it works fine. However, when I make a r ...

set ajax url dynamically according to the selected option value

My form features a select box with three distinct choices <select id="tool" name="tool"> <option value="option1">Option1</option> <option value="option2">Option2</option> <option value="option3">Option3</ ...

The configuration error occurred for the `get` action due to an unexpected response. Instead of an object, an array was received

Despite numerous attempts, I am struggling to find a solution that works for me. In my Courses controller, I am using the Students service and Staff service to access my staff and student objects. My goal is to retrieve the staffs and students objects in o ...

Center-aligned Bootstrap column with a width of 50% and centered vertically

I am looking to have images and videos displayed side by side on my webpage. The code below functions properly, however there is an issue with the alignment. While the horizontal center alignment is correct, the video and images are not centered vertically ...

The Jquery Index() method often results in a return value of -

I have developed a function in JavaScript that creates HTML content. Within the test(test1) function, I am checking if test1.Test__c is null and changing the color accordingly. The line ".table-striped > tbody > tr.testcss" is responsible for changin ...

numerous ajax requests and array variables

I find myself in an interesting situation with my application, where I need to handle a couple of scenarios. Firstly, I have to fetch data from two different sources using AJAX calls. Secondly, I need to compare and manipulate this data. If the values matc ...

Is there a way to generate inline block elements that occupy the full 100% width? Furthermore, can the second element contain an additional element that is revealed upon

Currently, I am working on a project that involves displaying images with text overlays. The text overlays are designed as inline blocks with varying background colors. One issue I encountered is that there is unwanted whitespace between the background co ...

Enhance your web app with NextJS and Firebase authentication

Currently, I am in the process of setting up a small Next.js application to work with a Firebase database (including storage). One issue I encountered is that the Firebase app instance is located in the server components because I was concerned about send ...

Explanation: The information box does not appear when the mouse hovers over it

Welcome to the gallery showcasing a unique calendar design with tooltip functionality. This calendar features a special hover effect for New Year's Day on January 1st, displaying a tooltip text upon interaction. Feel free to explore the code below to ...

Incorporate dynamic classes into an HTML list using PHP

I'm struggling to assign consecutive classes to each list item in a list with the 'nav' class. My goal is to give each list item a class of 'nthChild-x', where x corresponds to its position in the list. I'm pretty new to PHP, ...

The width of the Bootstrap shadow container is not optimized for large viewports

Having recently started using bootstrap (less than six hours of documentation/development time), I encountered an issue where the width of my shadow container extends too far on smaller screen sizes. Any screen size above 991px leaves unwanted white space ...

Is a Page Refresh Required to Reload Routes in ReactJS?

I have created menu links labeled Home, About, What I Do, and Experience for my portfolio site using BrowserRouter. However, when I click on these links, the components do not load properly on the page; they only render correctly after a page refresh. This ...

Folding animation using CSS3 and vertex manipulation

Looking to create a folding animation on a squared div with vertex? While there are examples online using Flash, I'm seeking guidance on how to achieve a similar effect using CSS3 and HTML5. Any tips or resources would be greatly appreciated. Thank y ...

Issue encountered while appending new rows to the tbody of a table

I'm encountering an issue with the append function within a for loop in my code. The string being passed to the function isn't parsing correctly and results in an error. How can I go about resolving this problem? Thanks! function getDetailPopUp ...

Avoid making GET requests when clicking on a link

[UPDATE] I need help troubleshooting an issue with my ajax request. Here is the code snippet that I am working on: <a href="" class="undo_feedback">Undo</a> When I click on the link, it triggers an ajax POST request, but I encounter an error ...

Pre-requisites verification in TypeScript

I have a typescript class with various methods for checking variable types. How can I determine which method to use at the beginning of the doProcess() for processing the input? class MyClass { public static arr : any[] = []; // main method public stati ...

The issue with the before selector causing the button label to overlap on top of the button remains

Check out the code snippet When hovering over the button, the "Sign Up!" label disappears. I tried adding color: rgba(32,32,32,1); to both the .button element and the ::before selector as a backup, but the label still won't display on top of the butt ...