Struggling with vertical alignment issues in a div element

Can anyone help me figure out how to vertically align a div? I've been struggling with it and can't seem to get it right. What am I missing?

body {
border: 1px solid red;
height: 500px;
}
#contactUs {
border: 1px solid blue;
vertical-align: bottom;
}
<div id = "contactUs"> Contact Us </div>

Note: Please avoid suggesting solutions involving absolute positioning.

Answer №1

The attempt to vertically align was unsuccessful as the vertical-align property is only applicable to inline and table-cell elements. (Refer to the specifications for more information.)

To align the #contactus div at the bottom of the parent block (body), you can utilize flexbox.

body {

    display: flex;               /* transform element into a flex container */
    flex-direction: column;      /* establish vertical alignment for child elements */
    justify-content: flex-end;   /* align child elements at the end of the container */

    border: 1px solid red;
    height: 500px;
}

#contactUs { border: 1px solid blue; }
<div id = "contactUs"> Contact Us </div>

For further insights on flexbox, visit:


Note that flexbox is supported by all major browsers, excluding IE 8 & 9. Some recent versions like Safari 8 and IE10 require vendor prefixes. To easily add all necessary prefixes, use this tool: Autoprefixer.

Answer №2

To ensure that the "Contact Us" text is vertically aligned, adjust the line-height of #contactUs to 500px.

line-height:500px;

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

How about trying out some dropdowns?

Following the issue I mentioned in my previous question titled Margin-Right on CSS not working, I am currently engaged in a creative endeavor to redesign my school's website homepage. The progress so far has been significant, but I now require some as ...

What is the process for transferring a file's contents to my server?

I am currently working on allowing users to import an OPML file that I parse server-side in my Rails application. However, I am facing difficulties as it appears that my server is not receiving the information correctly (neither the success nor error funct ...

Using div tags to organize content into rows

What is your interpretation of a row using div elements? Here is a simplified example in pseudocode: [DIV TAGS LEFT] [DIV TAGS CENTER] [DIV TAGS RIGHT] [INSERT CONTENT HERE] [DIV TAGS LEFT] [DIV TAGS CENTER] [DIV TAGS RIGHT] [INSERT CONTENT HERE] [ ...

Preserve Chinese characters using Spring-MVC in Java

How can I properly save Chinese characters from a form submission into the database? I have already specified the contentType in the jsp like this: <%@ page contentType="text/html;charset=UTF-8" %> I have also included this tag within the head sec ...

Retrieving custom attribute values during a drop event in Jquery drag and drop operations

I'm currently working on a moodboard creator, but I've hit a snag while trying to transfer the values from custom attributes of an image to a new div once the drop action is completed. Every time the drop is finished, it always fetches the value ...

Bug in Responsive Mega Menu Detected

Hey everyone, I've got a Mega Menu below for you to check out! <div id="menu-wrapper"> <ul class="nav"> <li><a href='#'>Brands</a> <div> <div class="nav-colu ...

Table within a table does not occupy full height within a table cell

I encountered an issue while nesting a table within a td element. The behavior differs between browsers: in Firefox, the nested table fills the entire cell from top to bottom, but in Edge and Chrome, it is centered within the td cell and does not occupy th ...

The art of sketching precise lines encircling a circular shape through the

What is the best way to use a for loop in JavaScript to draw lines around a circle, similar to those on a clock face? ...

Range slider position not being updated after user interaction

I am working on a webpage with an embedded video and a range slider that serves as a progress bar. Using Javascript, I update the value of the range slider as the video plays, allowing users to navigate through the video content. However, I have encounter ...

Offspring of div should have equal height without the top and bottom padding

Looking to ensure that the height of child divs matches the height of the parent divs. Currently, the divs expand as the page is resized. This is for search results, so there are multiple identical code blocks. function matchHeight() { $result = $(&a ...

Issues with jQuery toggle functionality have been reported specifically on the iPhone8 and other iOS devices

Hi everyone, I'm facing an issue with the header on my website. It displays a hamburger menu on small screens, and while it works perfectly on PCs and Android phones, it's unresponsive on iOS, specifically on my iPhone 8. I've tried using va ...

What is the best way to surround the initial x words within an element with a span tag?

Is there a way to style the first 10 words of a paragraph in a different color when the content is constantly changing? I can't manually add a span in the HTML. My approach involves using JavaScript to iterate through all instances of .overview__text. ...

Issue with div refresh switching from $.post to $.get using jQuery and duplicate div

I created this code to trigger the display of another div (#comments-popup) when hovering over #story-comments-text. This div then makes an $.get request for its HTML code. The first part is functioning correctly. However, I encounter an issue when makin ...

What could be causing my Font Awesome 6.1.1 icons to not show up after loading?

I'm currently enrolled in Brad Traversy's 50 Projects 50 Days course. On Day 26, which focuses on the Double Vertical Slider project, I noticed that the Font Awesome CDN being used is version 5.15.1, an outdated version. I have updated it to vers ...

Developing a Bootstrap layout that expands on larger screens but maintains a set height can pose challenges when

I am experiencing an issue with a bootstrap 4 navbar that is supposed to expand on large screens and collapse on small devices. The problem arises when I try to set the navbar height to be smaller than the default height, causing the expand feature to not ...

What is the best way to ensure a footer always remains at the bottom of the page with Telerik controls?

I'm currently working on an asp.net MVC project that utilizes the latest version of Telerik controls. The layout consists of a shared view with a header at the top, a left-side menu, and a footer at the bottom. In the main section, I use a @RenderBody ...

Correct the body when the bootstrap navbar collapses

<div class="navbar navbar-inverse navbar-fixed-top" role="navigation"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> ...

Tips for applying unique scss classes to a div based on a specific condition

Currently, I am developing a chat application where I want to showcase messages from one specific user on the right side of the screen while displaying messages from other users on the left side. <ion-item *ngFor="let message of messages | slice:0: ...

Firefox fails to apply styling to content loaded through Ajax (particularly when using AngularJS)

I've encountered a strange problem while working on my app (MVC4 + AngularJS). It seems that in Firefox (currently version 42), content loaded through an Ajax call does not always pick up the CSS styles that were loaded before. In the attached images, ...

Revamp every single hyperlink that ends in .html

I am looking to customize the URLs on my website to appear like this: www.example.html/1 www.example.html/2 www.example.html/3 instead of their current format: www.example.html/1.html www.example.html/2.html www.example.html/3.html Can anyone provide a ...