How to make text in HTML and CSS stay at the bottom of a div?

I am in the process of creating a website dedicated to my "Starcraft II" clan. My goal is to have the navigation bar display the text "ALLOYE" and remain fixed at the bottom of the screen. I attempted to achieve this using the following code:

vertical-align: text-bottom;

However, I noticed that the text appears to be positioned about 10 pixels above the bottom. Could this be due to any hidden borders or other factors? Below is the complete HTML markup for my project:

<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" type="text/css" href="main.css">
</head>
  <body>
     <div class="nav">
        <div class="title">
           <strong>ALLOYE</strong>
        </div>
     </div>
  </body>
</html>

Additionally, here is the CSS code in use:

body {
  margin: 0; 
  padding: 0; 
  color: #fff;
  font-family: "Segoe UI", Arial, Sans-Serif;
}
.nav {
  position: absolute;
  width: 100%;
  height: 7%;
  background: -webkit-linear-gradient(#FFB441, #FF9A00);
  background: -o-linear-gradient(#FFB441, #FF9A00);
  background: -moz-linear-gradient(#FFB441, #FF9A00);
  background: linear-gradient(#FFB441, #FF9A00);
}
.title {
  position: relative;
  vertical-align:text-bottom;
  font-size: 65px;
}

Answer №1

By applying a temporary border to both classes, you will gain insight into the situation.

If you then shift the 7% height to the .title class instead, observe the changes that occur.

Take the following steps to further analyze the effects:

  • Adjust your browser window to very short heights.
  • View the webpage in various browsers (IE, Chrome, Firefox, etc).
  • Check how it appears on your mobile phone.
  • Use the F12 key in your browser to experiment and troubleshoot.

Wishing you success with this task.

Answer №2

The issue with the overlapping elements is most likely caused by the height of the .nav being set to a percentage value (7%). To resolve this, you can change the height to a fixed pixel value instead.

You can implement something like the following code snippet:

.nav {
  position: absolute;
  width: 100%;
  height: 15px;
  background: linear-gradient(#FFB441, #FFAC2F, #FF9A00);
}

Answer №3

Here is an example of how you could achieve the desired effect:

.menu{
  position: relative;
  width: 100%;
  height: 80px;
  background: linear-gradient(#FFB441, #FFAC2F, #FF9A00);
}
.header {
  position: absolute;        
  font-size: 65px; /* Adjusting font size for whitespace */
  bottom: -15px; /* Correcting for font whitespace. Adjust as needed*/
}

In addition to this, it would be wise to follow Ruskin's advice and set a fixed height for your navigation bar.

Answer №4

Adjust the CSS by removing height: 7%; from .nav and adding it to .title:
(Revised CSS):

body {
  margin: 0; 
  padding: 0;
  color: #fff;
  font-family: "Segoe UI",Arial,Sans-Serif;
}
.nav {
  position: absolute;
  width: 100%;
  background: linear-gradient(#FFB441, #FFAC2F, #FF9A00);
}
.title {
  position: relative;
  vertical-align:text-bottom;
  font-size: 65px;
  height: 7%;
}

Access the updated layout on: http://jsfiddle.net/Wae6n/3/

Answer №5

To implement absolute positioning, make use of the bottom CSS property in the designated element (in this instance, it's <code>.nav</code>). Specify the value of the bottom property as 0%. Your CSS code should resemble the following:

.nav {
  position: absolute;
  bottom: 0px;
}

Answer №6

To start, it seems like incorporating a reset may be necessary. I noticed that there wasn't any spacing in my jsFiddle when I tested your code without making any adjustments (http://jsfiddle.net/R6dTU/).

My suggestion would be to take a different approach here. I would recommend positioning the title in this manner:

.title {
  position: absolute;
  bottom: 0;
}

In addition, using percentage heights without setting a min-height could lead to text getting cut off on some screens.

It's important to note that vertical-align: text-bottom; aligns the text to the bottom of descenders such as the tails on lowercase p's and q's. Therefore, achieving the desired effect may require using position:absolute instead.

As mentioned by @ANeves, while using a reset may not be considered the best practice solution, it could provide a quick fix. The ideal solution would involve:

  • Using a suitable tag for the header text (consider using h1 instead of a div)
  • Defining margins, padding, and line-height for this tag to ensure consistency across different browsers (which is typically addressed by using a reset)

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

problem with the clientHeight attribute in window event handlers

The component below is designed to react to changes in window resize based on the container height. However, there seems to be an issue where the containerHeight variable increases as the window size decreases, but does not decrease when I make the window ...

Convert JSON data into an HTML table using JavaScript without displaying the final result

I need help troubleshooting my JavaScript code that is supposed to populate an HTML table with data from a JSON file. However, the table remains empty and I can't figure out why. Sample JSON Data [{"User_Name":"John Doe","score":"10","team":"1"}, { ...

What is the process of integrating an HTML web component with an HTML file? Can I use innerHTML = foo("myfile.html") to achieve

Using HTML web components allows me to define their code using this method: this.innerHTML = `<h1></h1>`; However, I find it cumbersome as I do not have access to the Emmet Abbreviation feature which slows down my component creation process. ...

Parsing of CSS and Javascript is disabled within iframes

Within my node.js application, I have configured an endpoint where I can load some parsed HTML code. This is achieved through the following code: app.get('/code', function (req, res) { res.setHeader('Content-Type', 'text/html& ...

What measures can be taken to ensure that the input checkbox is not toggled by accidentally pressing

There's a checkbox input in a dropdown menu at the top of the page that is giving me some trouble. When I select an option by clicking on it, for some reason pressing the spacebar toggles it off and on. Clicking outside once doesn't correct it, I ...

What measures can I take to ensure that users cannot tamper with the PayPal code?

I've integrated a "Pay Now" button from Paypal onto my website. However, there is an issue where users can easily alter the payment amount before proceeding. Below is the code PayPal has provided: <form action="https://www.paypal.com/cgi-bin/webs ...

Create a Bootstrap jumbotron that is centered and only half of the width

I have a unique password reset method here: Jumbotron-Form-Bootstrap-My-Attempt Displayed below is the code from the image above: <div class="container"> <div class="jumbotron"> <br><br> <h2>Forget Passwo ...

Which is better: Utilizing Ajax page echo or background Ajax/direct HTML manipulation?

I am facing a dilemma and I could really use some guidance. Currently, I am in the process of developing an ordering system using PHP/Smarty/HTML/jQuery. The main functionality revolves around allowing sellers to confirm orders on the site. My goal is to ...

Is there a way to eliminate the gap beneath each row of my Tic-Tac-Toe grid in Next.js with CSS styling?

What could be causing the space under every row in my CSS? I am currently developing a tic-tac-toe application using Next.js to enhance my skills. However, I have encountered an issue with the CSS where there appears to be a small space underneath each bo ...

Highlight react-bootstrap NavItems with a underline on scroll in React

I am currently working on a website where I have implemented a react-bootstrap navbar with several Nav items. My goal is to enable smooth scrolling through the page, where each section corresponds to an underlined NavItem in the navbar or when clicked, aut ...

Pictures do not adhere to the maximum width set on their parent elements

When the max-width CSS style is set on the body tag and an image within the body surpasses this maximum width, the image does not adhere to the set limit. Instead of resizing, it simply overflows. Why does this happen? So, what is the solution to this pro ...

What is the process for executing Selenium IDE scripts in Selenium RC?

As a newcomer to using the selenium testing tool, I am seeking guidance on running selenium IDE scripts within selenium RC. I would greatly appreciate examples and screenshots to help me better understand the process. ...

Facing a selection list issue on a web application built with Flask and Vue.js

I'm trying to integrate Flask and Vue.js together, but I've encountered an issue with my select element. The following code snippet is present in my HTML file: <div class="col-sm-10"> <select class="form-select" v-mod ...

Is a single f.select impacting another f.select in the same form? (undesired)

I am facing an issue where adding a new HTML element like: <%= f.date_select :date, { id: "date-select"} %> is impacting my existing collection select: <%= f.collection_select :id, Customer.where(business_id: current_c ...

Navigating a dynamic table by looping through its generated tr elements

I am currently working with a dynamically created tr table that includes individual rows of data and a fixed total sum at the bottom. The total sum does not change dynamically. var tmp = '<tr id="mytable"> <td id="warenid">'+data1.id ...

Leveraging CSS to automatically number nested sections

Assume we have an example HTML or XML document structured like this: <body> <section> <h1>This should be numbered 1</h1> <section> <h1>This should be numbered 1.1</h1> <p>blah& ...

Using Jquery to insert content into HTML using the .html() method is not possible

I am inserting Dynamic Code into a Div via Ajax and I also need to include some Javascript, but it's not displaying in the code. Below is the code snippet: $.ajax({ url: "ajax_add_logo_parts.php", data: 'act=getPartIm ...

Creating Dynamic Videos with PHP and HTML

Trying to display the user-submitted video, but all my attempts failed for some reason: 1. echo "<video width='500px'>"; echo "<source type='video/mp4' src=$var autoplay>"; echo "</video>"; echo "<video width=& ...

Having trouble with the clear button for text input in Javascript when using Bootstrap and adding custom CSS. Any suggestions on how to fix

My code was working perfectly until I decided to add some CSS to it. You can view the code snippet by clicking on this link (I couldn't include it here due to issues with the code editor): View Gist code snippet here The code is based on Bootstrap. ...

Modify the navbar background color in bootstrap-vuejs

As per the information provided in the documentation, the instructions for setting styles for the navigation bar are as follows: <b-navbar toggleable="lg" type="dark" variant="info"> <!-- Or --> <b-navbar toggleable="lg" type="dark" variant ...