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

Steps for serving audio files in a Spring Boot application

Can someone advise on the best location to place my audio folder in order to reference it as src="audio/audio_name" within an HTML audio tag? I attempted placing it in the resources folder, but when using src="http://localhost:9191/resource ...

Implementing a feature in a Django blog to showcase the most recent post on every page when using a

Currently facing an issue with displaying the latest posts on my Django blog. Despite implementing a paginator, I am unable to showcase the latest posts on every page. views.py def post_list(request): post_list = Post.objects.all() page = request ...

A sporadic glitch in IE10 appears while attempting to translate text with a border-radius feature

I need some advice regarding a rendering issue I am experiencing in IE10. I have created an animated-flip effect that works perfectly in all the browsers I need it to. However, during testing, I noticed random border-like lines appearing for no apparent re ...

The Ion-button seems to be malfunctioning

I am interested in using special buttons for my ionic 1 project, specifically the ion-button feature outlined on this page: Ionic Buttons. I attempted to create a Round Button and an Outline + Round Button: <h2 class="sub-header" style="color:#4 ...

JS seems to kick in only after a couple of page refreshes

I'm facing an issue with my 3 columns that should have equal heights. I've implemented some JavaScript to achieve this, which you can see in action through the DEMO link below. <script> $(document).foundation(); </script> <scri ...

Issue with Bootstrap 4 Multi Select Functionality in Modal Not Functioning

Having trouble getting a bootstrap multi-select dropdown to work inside a Bootstrap modal. When the modal opens, the following CSS is affecting the dropdown: select.bs-select-hidden, .bootstrap-select > select.bs-select-hidden, select.selectpicker { ...

Incorporate a smooth transition effect to a dynamically resizing div button

In my current setup, I have 3 buttons that can toggle between different visible divs. In the future, I may add more buttons to switch between additional divs. At the moment, the first div is active (display set to block), while all other divs are hidden ( ...

Ways to retrieve the data within the tinymce text editor for seamless submission through a form

I am a beginner with TinyMCE and I am working on integrating the editor into my Laravel project. So far, I have managed to get it up and running, but I am struggling with retrieving the content from the editor and passing it to the controller for database ...

I am struggling to apply custom CSS styles to the scrollbar within a Card component using MUI react

import React from "react"; import Card from "@mui/material/Card"; import CardActions from "@mui/material/CardActions"; import CardContent from "@mui/material/CardContent"; import CardMedia from "@mui/material/Ca ...

`Loading CSS and JS files in node.js: A step-by-step guide`

I've searched through numerous similar questions without success, so I'm reaching out for help. My folder structure looks like this: Source Code Frontend Graphs.html Graphs.css Temperature.js Server_Backend server.js I aim ...

Is there a way to dismiss a modal window from the parent?

How can I close a modal window from its parent? This task seems quite challenging to accomplish. Essentially, I am opening a non-modal window. In some cases, the user may open a modal window from this non-modal window. If I close the non-modal window, I al ...

Is it feasible to execute exe files within a ReactJS environment?

Hey there! I've created a Game Launcher using ReactJS for my Unity game and was wondering if it's feasible to start the game (an exe file) simply by clicking on the play button. Can anyone please advise me on this? ...

Transmit data from Raspberry Pi to Apache Server with strong security measures

Utilizing a Raspberry Pi to collect temperature data and store it in a file Running on a virtual machine, the server uses Apache to host a website (comprised of HTML, PHP, and JavaScript) displaying a graph based on this data I am seeking a secure method ...

What's the best way to get rid of the one-pixel gap between these elements on high-resolution displays like

http://jsfiddle.net/36ykrp9x/5/ HTML <div class="container"> <button>O</button><button>O</button> </div> CSS .container { width: 100%; background-color: rgb(120, 200, 200); text-align: center; } butt ...

Purchased a website design - should I go with a table structure or CSS layout?

Recently, I decided to hire a new web designer for one of my projects. After multiple attempts, he finally delivered a beautifully designed webpage by sending me 20 poorly sliced images from Photoshop and an entire HTML file with table structure. When I r ...

Which is more effective: Layering multiple canvases in the DOM or consolidating all drawing on a single canvas?

In my previous projects, I have had experience working with layered canvases. While some of my colleagues swear by this approach, I find myself skeptical about its effectiveness. My primary concerns are: If multiple canvases are layered and one undergoes ...

Looking for a way to efficiently add multiple value inputs to a JSON object using jQuery or JavaScript?

Here is the HTML input tag code I am working with: <form id="info"> <input id="A" name="A" type="hidden" nodetye="parent" value="A"> <input id="A1" name="A1" type="text" nodetype="child" value="a1val"> <input id="A2" name ...

Learn the process of seamlessly playing multiple video files in an HTML format

I am working with multiple video files and I need them to play continuously. The goal is to seamlessly transition from one video to the next without any interruptions on the screen. Below is my current code snippet: -HTML <button onclick="playVi ...

Struggling with getting Bootstrap Affix-bottom to scroll back up?

Despite reading various answers, I am still struggling to configure the settings correctly. The columns header is not resuming scrolling upwards as expected. Below is my PHP code snippet: <div id="columnsHeader" class="affix" data-offset-top="800" da ...

updating the row of an html table with elements from a javascript object

I am faced with the task of dynamically adding rows to a table based on the number of elements in my JavaScript object. The object consists of keys and arrays of values. userobject={ ID: [1,2,3] IP_Address: ["12.21.12 ...