Struggling to vertically align divs within a parent div despite only using 3 lines of code

This question builds upon an answer provided in response to a similar query. It aims to explore the specific technique outlined in "Vertical(ly) align(ing) anything with just 3 lines of CSS", especially since I'm encountering difficulties making it work.

Here's the jsfiddle link: http://jsfiddle.net/hf31ofj3/ The issue may only be visible in HTML5 browsers due to one input being a color picker, which differs in height from other input fields and causes vertical misalignment.

One approach I've attempted involves modifying the selection of elements for vertical alignment, though so far it has not yielded the desired results:

#basecfgattrs-row1 #width-input-container
#basecfgattrs-row1 #height-input-container
{
  position: relative;
  top: 50%;
  transform: translateY(-50%);
}

Answer №1

When it comes to vertical alignment, using `float` can often be problematic.

Instead, consider using display:inline-block with vertical-align:middle.

.input-col3 {
  display: inline-block;
  vertical-align: middle;
  width: 32%;
}
#basecfgattrs input {
  width: 44px;
}
#basecfgattrs-row1 {
  position: relative;
}
#basecfgattrs-row1 div {}
<div id="basecfgattrs">
  <div id="" basecfgattrs-row1 ">
    <div class="input-col3 " id="width-input-container "> 
      <label>Chart Width</label>
      <input name="width " id="width " />
    </div>
    <div class="input-col3 " id="height-input-container ">
      <label>Chart Height</label>
      <input name="height " id="height " />
    </div>
    <div class="input-col3 " id="dataSource-chart-bgColor-input-container ">
      <label>Background Color</label>
      <input name="dataSource-chart-bgColor " id="dataSource-chart-bgColor " type="color " class="colorpicker " />
    </div>
  </div>
</div>

Alternatively, you could utilize flexbox.

#basecfgattrs-row1 {
  display: flex;
}
.input-col3 {
  display: flex;
  border: 1px solid red;
  width: 32%;
  align-items: center;
}
#basecfgattrs label {
  flex: 1;
}
#basecfgattrs input {
  flex: 0 0 44px;
  margin-right: 1em;
}
<div id="basecfgattrs">
  <div id="basecfgattrs-row1">
    <div class="input-col3" id="width-input-container">
      <label>Chart Width</label>
      <input name="width" id="width" />
    </div>
    <div class="input-col3" id="height-input-container">
      <label>Chart Height</label>
      <input name="height" id="height" />
    </div>
    <div class="input-col3" id="dataSource-chart-bgColor-input-container">
      <label>Background Color</label>
      <input name="dataSource-chart-bgColor" id="dataSource-chart-bgColor" type="color" class="colorpicker" />
    </div>
  </div>
</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

Ways to prevent blank class from occupying space until filled with Javascript

I've been working on a checkout calculator using JavaScript, and here's how I'm inputting the data: <p class="car-rent-class-info h6 pb-1"></p> <p class="car-rent-pickupdropoff-info h6 pb-1"></p> <p class="car-ren ...

The linking process in AngularJS is encountering difficulties when trying to interact with

I've already looked at similar questions, and my code seems correct based on the answers provided. It's a very simple beginner code. <html ng-app=""> <head> <title>Assignment</title> <script src=" ...

Footer remains fixed and scrolls into the body when the window is resized

Having trouble with the footer's responsiveness when resizing the desktop window. It looks fine in developer tools, but in different browsers, the footer placement gets messed up and scrolls over the rest of the content. Any insights on what might be ...

`CSS alignment problems with multiple images`

Recently, I delved into the world of CSS and HTML. I created an application with pages designed using these languages. Here are the images representing my pages: and the second one is the user page, which serves as the home page. Below is a snippet of my ...

How do I incorporate pagination into a PL-SQL dynamic content table in Oracle Apex?

I've successfully created a PL-SQL dynamic content report in Oracle Apex, but I'm struggling with implementing pagination. With too many rows to display at once, adding pagination will greatly enhance the user experience. Here is a snippet of my ...

Removing the css class when an element loses focus

In order to improve user experience on my web page, I have implemented a validation check on a form before submitting it back to the server. The validation process is successful and applies a custom CSS class called ErrorControl to input fields when necess ...

Having trouble with my custom dropdown selector conflicting with Bootstrap 4 CSS

After searching for an alternative to the typical dropdown selectors, I stumbled upon a neat custom version on W3schools. However, I encountered an issue where it clashes with bootstrap. Despite including select: hide; in the CSS, the original dropdown sel ...

How can you turn off CSS3 animations for browsers that don't support them

Upon page load, a fade-in animation is applied to the main container. Although it functions properly in most browsers, it seems to have an issue in IE(9). Is there a method to identify if the user's browser does not support CSS3 animations and disabl ...

Aligning the Bootstrap 5 Accordion Button in the Center and Adding Line Breaks

I have a few queries regarding the code I am implementing using Bootstrap 5. JSFiddle How can I center align the header within the button? <button class="accordion-button collapsed text-center" type="button" data-bs-toggle=" ...

pressing the button again will yield a new outcome

I am looking to disable a button (material ui) when it is clicked for the second time by setting disabled={true}. Unfortunately, I have not been able to find any examples related to this specific scenario on StackOverflow. <Button onClick={this.s ...

Positioning elements in CSS with a rolling ball animation

Introduction I have a project in progress to develop a Bingo game. One of the current tasks involves creating a CSS animation that simulates a rolling ball effect. The objective is to make it appear as though a ball drops from a wheel and rolls from righ ...

"Enhance Your Website with Slider Swipe Effects using CSS3 and

After scouring the internet for various types of sliders, including swipe sliders, I am interested in creating a responsive swipe slider specifically for mobile phones. This would be a full page swipe slider where users can swipe left and right seamlessly. ...

Tips for updating the color scheme in your CSS file by making hue adjustments to all colors

I have a CSS file and I am looking to automatically generate multiple color variations of the file by altering the hue, similar to using the "colorize" function in GIMP. I came across a tool that does exactly what I need at , however it does not support t ...

How to align scrolling images with their scroll origin - a step by step guide

Curious to know the name of the effect where images scroll in a different orientation than the page, creating a 2D appearance. Take a look at the Google Nexus website and scroll down - do you see the effect? What is this effect called? Is it created usin ...

The jQuery keyup filter is functioning properly when the content is displayed in columns, but it is not working as expected when the

Encountering an issue where the boxes do not reset properly to a 2x4 layout after typing something into the input field (for example, "spore") and then deleting it. It seems to work when the boxes are placed into 4 columns, but when using float: left on #s ...

Image in Bootstrap not showing up on smaller devices

I am facing an issue where an image displays properly on desktop view but turns into 0x0 dimensions when viewing from a mobile device. I have been unable to determine the root cause of this problem. The website is built using Bootstrap 4 and you can observ ...

The responsiveness of Bootstrap 5 columns in Chrome inspection appears to break after reaching medium size, yet functions properly in other areas

I am currently working with cards within a grid system, but I am encountering an issue with resizing when the column size is smaller than medium in the mobile view inside the inspect section. The width does not expand to 100%, regardless of how much I try ...

What could be causing the disappearance of the border around this `<li>` element?

I am currently redesigning the Kotaku website and facing difficulties in creating a list for the footer. Below is an image illustrating my issue. The 'Popular tags' section has been created using the <ul> and <li> elements, with an & ...

Eliminating the Scrollbar from Bootstrap 4 DataTable Causes Table Width to Decrease

My tables are causing a horizontal scroll bar to appear when converted to Bootstrap data tables. Adding the "p-3" class to the table's div for padding eliminates the scroll bar but also narrows the table. Is there a solution to removing the scroll b ...

Tips on concealing the scrollbar only when a particular element is visible

I inserted the following code into my index.html file: <head> <style> body::-webkit-scrollbar { display: none; } </style> </head> This code successfully hides the scrollbar. My goal is to only h ...