How can I position the label at the top?

Visit this jsfiddle link

Is it possible to align the label on top and select at the bottom within the given HTML structure as shown in the picture?

<div class="col">
<label for="foo">Select:</label>
<select id="foo" name="select">
   <option value="1">1</option>
   <option value="2">2</option>
</select>
</div>
<div class="col">
<label for="bar">Select any of the following:</label>
<select id="bar" name="select">
   <option value="11">11</option>
   <option value="22">22</option>
</select>
</div>

I have managed to align the label to the top and select to the bottom when in two separate div blocks using vertical-align property. However, I am curious to know if there is a way to achieve this without modifying the existing HTML code.

Answer №1

To ensure both columns have equal height, utilize Display: Table-cell:

div.col {
  display: table-cell;
    border: 1px solid blue;
    font-size: 300%;
    width: 300px;
    position: relative;
    padding-bottom: 40px; /* Space for the 'select'*/
}

select {
    position: absolute;
    bottom: 0;
    left: 0;
}

Here is a live demonstration in Chrome: http://jsfiddle.net/cM6Yp/

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

Trouble with Materialize CSS: Form elements displaying incorrectly

I attempted to implement a login form within a modal, following the example provided here (https://codepen.io/skcals/pen/bxdpaN). However, when I applied the same code to my own website, this is how it appeared: Has anyone else encountered this issue? And ...

What could be causing the Bootstrap Navbar toggle icon button to not display navigation items when clicked?

Bootstrap has been a reliable tool for my projects until I encountered an issue in an Angular project. The navbar toggler icon button is visible, but clicking on it does not display the navigation items. <div> <nav class="navbar navbar-ex ...

Using JavaScript to Sort and Filter HTML <optgroup> Elements

I am encountering an issue with an HTML <select> element that contains <optgroup> elements with <option> elements nested within them. Here is an example of the structure: <select> <optgroup label="label1">Label 1 <op ...

In Internet Explorer, regardless of how much scrolling occurs, the document.body.scrollTop property will consistently be

While moving the mouse, I'm showing the value of document.body.scrollTop in the status bar. However, I have noticed that this value is consistently 0 in Internet Explorer. Why is it always 0 in IE? Is there an alternative method to determine how far t ...

Is there a way to ensure that an image stays pinned to the bottom of the screen, regardless of the device or screen

Looking for a solution to keep an image centered at the bottom of a website page regardless of screen size? I've tried different recommendations from Stack Overflow without success. position:fixed; bottom:0px; left:50%; Still struggling to make it wo ...

Using ReactJS to create cross-browser inline styling with flexbox

I'm currently working on a React web application that relies heavily on inline styling. My goal is to ensure compatibility with the latest versions of major browsers (Safari, Chrome, Firefox, IE) while utilizing flexbox for layout. The issue I encou ...

Discovering the point of exit for a mouse from an image

Visit this website to see the effect in action: I am curious about how the image scrolls into and out of the direction where the mouse enters and leaves. Can you explain how this is achieved? ...

Guide to setting a background image on a div when hovering using jQuery

I'm having trouble adding a background image to this specific div element: <div class="logo-main"></div> Here is the script I've been using, but it doesn't seem to be working as expected: <script type='text/javascript& ...

What is the best way to ensure that child elements within a container div are centered when scrolling left and right?

When attempting to handle the 'scroll' event, I noticed that the callback function only records the position of the div as the last position. I am looking for a way to determine if the div is in the center, which is my target. const slide = ...

Is it possible to create a blurred effect on an image while preserving the clarity of text within

I have been attempting to create an effect where the image blurs and then reveals text. However, I have encountered issues where the image either blurs completely or behaves strangely. My code is behaving oddly, almost like it's giving a signal. (I&a ...

"Discover the magic of creating a navigation menu with jQuery toggle - let me show

Recently, I managed to create a side navigation using the target function in CSS3. However, I am curious about how I can achieve the same result using jQuery without disrupting the layout. Any assistance would be greatly appreciated. Here is the code sni ...

What is the best way to implement a sidebar closing animation?

Utilizing both react and tailwindcss, I successfully crafted a sidebar menu that elegantly appears from left to right when the user clicks on the hamburger icon. However, my attempts to create a reverse animation as the sidebar disappears from right to lef ...

Tips for placing an image in the bottom right corner of a frame

My goal on the Roman Numismatics page is to place the yellow 'bid' button at the lower right corner of each frame. Current code <p><a href="<?= $product->page_url() ?>"><img border="0" alt="Bid&qu ...

Unusual occurrence: unexpected positioning issue with iOS and Chrome (Windows)

My website looks perfect on Firefox, but unfortunately, it's not displaying correctly on Safari (iOS) and some Chrome devices. The Menu-Bar, which should be position fixed, is not showing properly. I'm not sure what the issue is. Screenshots: ...

Creating a div that spans the entire height from top to bottom

Currently, I am faced with the following scenario: <div id=area> <div id=box> </div> </div> <div id=footer> </div> The "area" div is situated in the center and has a width of 700px with shadows on both the right and ...

Troubleshooting a peculiar CSS margin problem exclusively in Internet Explorer

I am currently utilizing a grid system to create a responsive layout for a single webpage on our company's official site (lexisnexis.stacklaw.com.au). However, I have encountered some CSS problems when displaying the page in Internet Explorer. The [+ ...

I am having trouble with my :hover selector being interrupted by text, what steps should I take to resolve this

My issue revolves around an image with a hover effect that changes the box shadow color. However, there is text on the image that also changes when clicked, creating a problem where the area occupied by the text prevents the box shadow from displaying prop ...

Creating equal spacing between divs and the edges of the container

I need to arrange a set of divs equidistant from each other. My goal is to have the maximum number of divs fit side by side with equal spacing between them and the container edge. While I almost achieved this with the code below (credit to another post), ...

What are the implications of implementing this particular CSS code?

One common thing I come across on websites is this snippet of code: body:before { content: ""; width: 0; height: 100%; float: left; margin-top: -31700px; } What happens when this CSS is implemented? ...

Ensure that two elements containing content of varying width are equal in width

I am facing a challenge with a container that contains two child elements (previous and next links). These links have labels of different lengths, but I need them both to have the same width on the page. Ideally, each link should be as wide as the widest e ...