How can I align <a> elements at the bottom and center them at the same time?

I have successfully centered my navigation menu using the text-align property. Additionally, I aligned it to the bottom of the parent div by utilizing the position and bottom properties. However, I encountered an issue where using the position and bottom properties seemed to cancel out the text-align property. Why does this happen? http://jsfiddle.net/CQTEY/

HTML

<div class="header">
    <div class="logo">
    <img src="/images/logo.png" width="96" height="82">
    </div>    
    <div id="nav">
    <a href="#">Portfolio</a>
    <a href="#">About</a>
    <a href="#">Contact</a>
    </div>
</div>

CSS

.header {
    position:relative;
    background-color: #2C2E31;
    border-bottom: #242426 2px solid;
    height: 182px;
}
#nav {
    position:absolute;
    bottom:0;
    text-align:center; 
    text-decoration:none; 
    font-size:20px;
    font-family:raleway-regular; 
}
#nav a {
    border-bottom:#FFFFFF 2px solid; 
    color:#FFFFFF;
    text-decoration:none; 
    margin-left: 8px; 
    margin-right:8px;
}

Answer №1

Although the text-align property remains untouched, you may notice that when positioning your div#nav at the bottom of the page, it no longer stretches across the full width of the div.header and is left-aligned.

To achieve the desired layout, adjust the CSS for #nav by including the left and right properties to expand the div's width:

#nav {
    position:absolute;
    bottom: 0;
    left: 0;
    right: 0;
    text-align:center; 
    text-decoration:none; 
    font-size:20px;
    font-family:raleway-regular; 
}

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

Tips for vertically centering a popup modal within another longer popup modal

My full screen popup modal (parent-modal) is quite lengthy. Within this parent-modal, there is a secondary popup modal (child-modal). When I scroll the parent-modal and then open the child-modal, the child-modal does not appear vertically centered. ...

retain focus even after using .blur()

Currently, I am implementing a form submission using AJAX. The form consists of only one input field and the submit button is hidden. My aim is to ensure that when the user hits the enter key, the input field does not lose its focus. Here's the code s ...

Capturing and saving detailed hand-drawn artwork in high resolution

Is there a cutting-edge solution available for capturing hand-drawn sketches (from a tablet, touch screen, or iPad-like device) on a website using JavaScript and saving it on the server side? Essentially, I am looking for a mouse drawing canvas with a hig ...

Tips for effectively placing a page scope block using BEM

Here is the current structure of my header. The page component is assumed to be the root. Currently, the geometry of the social-links block is being controlled by the header__social-links mix (positioned absolutely relative to the header). How can I prop ...

interaction with leaflet popup information

My aim is to access the content within a leaflet popup. Specifically, I have inserted a form with buttons inside it that I would like to interact with. However, for now, I am simply attempting to add an event to the popup itself. $(".leaflet-popup-content ...

Confirming the authenticity of a newly added user input with the help of jQuery

Within my current project, I have implemented validation features for text boxes. When a user clicks on a text box, the border is highlighted. If they click elsewhere without entering any value, the border turns red and an alert pop-up appears. In additio ...

Unable to save the user's identification in the session

I am in the process of retrieving the user ID of a logged-in user and storing it in the session. This way, when a user submits something, I can include their user ID in the submission to the database. My login page is quite rudimentary, so any guidance wou ...

Modifying Bootstrap Grid Layouts

I need to reorganize the columns for better responsiveness as the current order is not ideal. Below is the code snippet: <div class="tab-content" id="pills-tabContent"> <div class="tab-pane fade show active" id="pills-home" role="tabpanel" ari ...

What is the best way to define line length in Bootstrap?

I have the following HTML: .line { width: 100%; height: 14px; border-bottom: 1px solid lightgrey; position: absolute; } .circle { height: 24px; width: 24px; background-color: lightgrey; border-radius: 50%; display: inline-block; } < ...

What is the best way to extract data from various HTML files using RVEST and save it into an Excel spreadsheet?

I am struggling to find a solution for my current problem as I am not fluent in R. My challenge is working with 800 html files and accessing all the h2 elements within each file. Currently, I have managed to do this with individual website URLs using the ...

Issue with the Dropdown menu in Metro UI CSS - not functioning properly

I have integrated the METRO UI CSS into my project and created a dropdown menu. The design looks great, but unfortunately, the dropdown list is not appearing as expected. To implement this feature, I followed the example provided on the following link: H ...

The Google reCaptcha reply was "Uncaught (in promise) null"

When using reCaptcha v2, I encountered an issue in the developer console showing Uncaught (in promise) null message regardless of moving the .reset() function. Here is the console output: https://i.stack.imgur.com/l24dC.png This is my code for reCaptcha ...

Displaying a Vuetify stepper alert if required fields are left blank

I received assistance with developing this Vuetify stepper code, but I have one final inquiry. I have learned that there are specific rules that can be implemented to require certain blanks to be filled out. For example, in my code, if the blanks in step 3 ...

Introducing a new div element completely disrupts the overall layout

Take a look at the code I have provided below. http://jsfiddle.net/xymgwonu/3/ Everything was working perfectly fine until I introduced a new div with the class name <div class="bubble"></div>. This caused some issues with the overall design. ...

The .gltf file depicts a more shadowy appearance compared to the initial obj model

The model I loaded appears darker compared to the model uploaded to the gltf-viewer, with a slightly different color. It is also darker than the original obj file. Despite having a similar light environment, the reason for this discrepancy remains unknown. ...

A collection of items displayed in an unordered format across two columns

I need help creating a list that displays in two columns. One column for odd numbers, the other for even numbers. Here's an example of what I'm trying to achieve: +----------------------------------------------------+ | col- ...

How can we prevent the restoration of size effects in jQuery UI versions 1.9 and above?

After implementing jQuery UI 1.9 or newer, I noticed that the size effect returns to its original state. Below is a snippet of my code: http://jsfiddle.net/mQCxY/ $(function () { $('.circle').click(function () { $(this).effect("size ...

The functionality of nth-child(odd) seems to be malfunctioning when there is a change

When I group certain elements together in one container, I like to make odd elements stand out by giving them a different background color. However, when I try to filter elements based on conditions and move unwanted elements to another class, the nth-chil ...

SyntaxError: An unidentified item was encountered at the <head> location

I have encountered an issue while loading a PHP file that utilizes ajax. Initially, the page loads without any errors. However, upon triggering the onclick event on a button, I receive the error message "Uncaught SyntaxError: Unexpected identifier" pointin ...

Styling an Angular2 Component with a jQueryUI element

My goal is to integrate a jQueryUI range slider into an Angular2 Component. doubleRange.ts: /// <reference path="../../../../../typings/jquery/jquery.d.ts" /> /// <reference path="../../../../../typings/jqueryui/jqueryui.d.ts" /> import { Com ...