Vertical alignment issue persists with floated elements

Hey there, I'm currently attempting to align 2 elements vertically.

<div>
  <h1>heading</h1>
  <nav>
    <ul>LIs...</ul>
  </nav>
</div>

I'm looking to have the h1 on the left and the nav on the right. However, vertical alignment doesn't seem to work with floated elements :( Any potential workarounds?

edit: When using the table cell solution, the size of the h1 changes. Is there a way to prevent this?

I've already attempted setting width:auto.

Answer №1

Give this a shot:

Here's the HTML:

<div class="row">
  <h1 class="cell">heading</h1>
  <nav class="cell">
    <ul>List Items...</ul>
  </nav>
</div>

And the CSS to go with it:

.row{display:table-row;}
.cell{display:table-cell;
vertical-align: middle;
border: 1px solid #CCC;}

If you want to see it in action, check out this fiddle.

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

Can I use Ems instead of pixels for Chrome developer tools?

In all my style-sheets, I opt for using ems instead of px. However, in Chrome Developer Tools, the computed styles/metrics always display in px, even for elements where I specifically used ems: (Here is a screenshot of the computed lengths for a button wi ...

Having trouble loading background color or image in three.js

I've been struggling to load a background image or color on my webpage. Despite trying various methods, including commenting out javascript files and checking the stylesheet link, nothing seems to work. Even when I load the three.js scene with javascr ...

Ways to use CSS to align a table row to the right

I've been attempting to shift the alignment of a table row that contains the navigation links for my website from left to right, but no matter what I try to modify, nothing seems to budge. I'm relatively new to studying HTML and CSS, so I would g ...

What is the best way to trigger ajax when the user clicks the back button to return to the previous webpage?

Check out my code snippet below: HTML Code <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class="body"> <div class="dropdown_div"> <select id="q_type" class="dropdown" ...

Creating a responsive website that utilizes YAML and is optimized for extremely narrow screen widths

I have noticed that my responsive design using YAML is working well for the most part. However, on screens with very small widths, the YAML grids become extremely tiny. In such cases, it would be more practical to have the right grid displayed below the le ...

Incorporate an image into a hyperlink using CSS

I am trying to enhance my URLs by adding the same image to each of them. The code I have currently is as follows: a.linkArrow { background: transparent url('../images/abc.png') no-repeat center right; padding-right: 60px; } Here is an ...

JavaScript can be used to deactivate the onclick attribute

Is there a way to deactivate one onclick event once the other has been activated? Both divs are initially hidden in the CSS. I'm new to programming, so any help is appreciated. Markup <a id="leftbutton" href="#" onclick="showDiv(this.id); return ...

Placing horizontal text over a Bootstrap 5 grid

Currently working my way through Boostrap5 while developing my website and I am extremely pleased with the progress so far. However, I have hit a snag - I want the name to appear vertically when hovering over the images on the bottom left, but for some rea ...

Functionality Described Undefined

This is the JavaScript code that I am using: document.getElementById("config2").addEventListener("click", function(){ config3(); console.log("In Function config.onclick()..."); }); function config3() { document. ...

A guide on retrieving the value of input elements using class names in jQuery

I need help fetching the values of input elements with the class "features". I am able to access all of them. alert($('.features').length); Can someone please confirm if my understanding is correct? $('.features') is an array of HTM ...

Align the content of a collapsed bootstrap row vertically

In a row, I have two columns, each containing their own row. When the page width hits the 'xs' break-point, the left column's row will stack its columns on top of each other. The right column is taller than the left column, which leaves a l ...

How to Deactivate Horizontal Scrolling Using CSS in WordPress

Hey there, I'm currently working on a WordPress blog and facing an issue. Here's the link to my problem: When I resize the browser (X-Axis) to a minimum, like when using a mobile device, I noticed that I can scroll to the right in the Content se ...

Guide to retrieving IDs of images on a canvas during drag and drop functionality

I've developed a finite state machine drawing tool that includes drag-and-drop functionality for different images, such as states and arrows. Each arrow creates a div tag for the transition, with unique ids assigned to every state, arrow, and transiti ...

Prevent a div from being displaced by the transform property once it reaches the window's border

Is it possible to prevent the viewer I created using CSS transform from moving when its borders reach the window borders? Should I consider using a different method instead? If you'd like to see the code, you can check it out here. var x=0, y=0 ...

I am trying to set a background image specifically for one page in my application, but I am struggling to make it work. As a newcomer, I am still learning how to

I've been working on the code for a login page, but I'm having trouble setting a background image for the page. I know how to set it for the whole application by modifying the app component, but when I try to do the same for this specific compone ...

Looking to replicate a Modal that I designed, but unsure which elements need altering in order to achieve this. I am hoping to create three duplicates of the Modal

This modal is functioning perfectly, and now I want to replicate the same modal three times on a single page. I require three distinct buttons on the same page to trigger these separate modals. At this point, I am unsure which attributes need modification ...

Jquery is not working as expected

I am having trouble implementing a jQuery function to show and hide select components. It doesn't seem to be working correctly. Can someone help me identify the issue? <html> <head> <meta charset='UTF-8' /> <script ...

Mastering the text overflow properties in Bootstrap's list-groupEver wished to control how

I am attempting to apply a text-overflow property to links within a bootstrap list-group. Each list item also includes a bootstrap badge floated to the right. However, when I add the text-overflow property, the link ends up going underneath the badge inste ...

Tips for managing a series of images in a line within a bootstrap form

Can someone help me troubleshoot my bootstrap row handling? Here is my code: <div class="form-group col-md-6"> <?php if($saved_image != ''): ?> <div style="width:100px; height:100px"> <img class="i ...

Preparing to load a CSS file in a Polymer element based on certain conditions

I have numerous CSS files with various animations, and I am interested in dynamically loading a CSS file in a Polymer element based on the animation attribute: Is it feasible to bind the {{animation}} value like this: <polymer-element name="yo-dialog" ...