Align a div in the center with another div positioned to its left and floated

I am in the process of creating a footer with three components: a logo aligned to the left, a centered navigation menu, and a set of social icons on the right. I have encountered an issue where when I float the logo to the left, the list items within my navigation menu are unexpectedly pushed to the right. Despite centering the unordered list on the page and ensuring there is no padding or margin on the list items, they continue to shift. Below is the code snippet along with screenshots for reference.

HTML

        <p class="copyright footerLogo">
        OUR COMPANY LOGO</p>

        <div class="footerNavbar">


          <ul>
            <li><a href="default.asp">Services</a></li>
            <li><a href="news.asp">Client Work</a></li>
            <li><a href="contact.asp">Contact</a></li>
            <li><a href="about.asp">Hire Us</a></li>
          </ul>

        </div>

        <div class="socialIcons">
            <ul>
                <li>
                    <a href="http://facebook.com">
                        <i class="fa fa-facebook-official fa-2x"></i>
                    </a>
                </li>
                <li>
                    <a href="http://twitter.com">
                        <i class="fa fa-twitter-square fa-2x"></i>
                    </a>
                </li>
                <li>
                    <a href="http://linkedin.com">
                        <i class="fa fa-linkedin-square fa-2x"></i>
                    </a>
                </li>
            </ul>
        </div>
</footer>

CSS

footer {
  text-align: center;
  height: 5em;
  background: transparent; }

footer .footerLogo {
  float: left;
  padding-left: 2em;
  padding-top: 1em; }

footer .footerNavbar {
  width: 60%;
  margin: 0 auto; }

footer .footerNavbar ul {
  padding: 0; }

footer .footerNavbar ul li {
  text-align: center;
  display: inline-block; }

footer .socialIcons {
  float: right;
  padding-right: 2em; }

footer .socialIcons ul li {
  display: inline-block; }

The unordered list is centered:

Without float left property, list items are properly centered:

Answer №1

Here is a revised version for you to consider. Do you like this format?

I made some improvements to the code and temporarily added background color to each of the footer elements (it makes it easier to identify any issues that way)

footer {
  height: 5em;
}

footer .footerLogo {
  float: left;
  width: 20%;
  background-color: red;
}

footer .footerNavbar {
  float: left;
  width: 60%;
  text-align: center;
  background-color: lime;
}

footer .footerNavbar ul {
  padding: 0;
}

footer .footerNavbar ul li {
  text-align: center;
  display: inline-block; }

footer .socialIcons {
  float: left;
  width: 20%;
  text-align: center;
  background-color: yellow;
}

footer .socialIcons ul li {
  display: inline-block;
}
<footer>
       <div class="copyright footerLogo">
        COMPANY LOGO</div>

        <div class="footerNavbar">


          <ul>
            <li><a href="default.asp">Services</a></li>
            <li><a href="news.asp">Client Work</a></li>
            <li><a href="contact.asp">Contact</a></li>
            <li><a href="about.asp">Hire Us</a></li>
          </ul>

        </div>

        <div class="socialIcons">
            <ul>
                <li>
                    <a href="http://facebook.com">
                        <i class="fa fa-facebook-official fa-2x">1</i>
                    </a>
                </li>
                <li>
                    <a href="http://twitter.com">
                        <i class="fa fa-twitter-square fa-2x">2</i>
                    </a>
                </li>
                <li>
                    <a href="http://linkedin.com">
                        <i class="fa fa-linkedin-square fa-2x">3</i>
                    </a>
                </li>
            </ul>
        </div>
</footer>

Answer №2

Create a main container div to hold all 3 components.

Components on the left side:

position:absolute;
left:0;

Components on the right side:

position:absolute;
right:0;

Relative positioning within the parent container:

#parent {
position:relative;
}

Answer №3

  1. For better assistance, could you please provide a link to your jsfiddle?

  2. You may want to consider utilizing the clear property in your CSS.

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

Avoiding text from overflowing a DIV when the parent DIV's width is specified as a percentage

After extensively searching through over 20 similar posts, I have not been able to find a solution that works for my specific issue. The layout of some content I'm working with resembles the example provided here: Check out the Fiddle Example In th ...

populating a HTML image tag 'src' attribute with data extracted from API javascript code

Hey there! I'm currently working on integrating an image element from the openweatherAPI that corresponds to the weather icon retrieved from the JSON data when a user inputs a city. This means displaying images like scattered clouds or clear skies bas ...

Data bindings encapsulated within nested curly braces

I am currently utilizing Angular2 in my application. Within my html file, I have a *ngFor loop set up like so: <div *ngFor="let element of array"> {{element.id}} </div> Next, I have an array containing objects structured as follows: some ...

Converting XML hierarchy into a flat HTML table using XSLT

Looking for a way to transform hierarchical XML into an HTML table? Here's the challenge: <node text="a" value="1"> <node text="gga" value="5"> <node text="dh" value="9"> <node text="tyfg" value="4"> < ...

My attempts to decrease the volume of an HTML5/CSS3 Audio element have been unsuccessful

Hey there! I'm currently working on my very first webpage and recently added an audio element that is functioning perfectly. The only issue I'm encountering is trying to position the element at the bottom of my page. I've already attempted ...

Enhancing File Uploads with Vuetify

For my Vue.js project, I am attempting to upload a file using Vuetify and then store that uploaded file in my data object. This is the HTML code: <input id="file-upload" type="file" @change="onFileChange"> Within my methods section, I have the fol ...

Button for toggling the mobile navbar in Bootstrap

Is there a way to adjust the position of the navbar-toggle button http://prntscr.com/5sldgb within the navbar after changing its height? Here is the HTML code: <div class="navbar navbar-default"> <div class="container"> ...

Tips for personalizing react-show-more text length with Material-UI Icons

In my SharePoint Framework webpart using React, I am currently utilizing the show more text controller. However, I am interested in replacing the "Show More" and "Show Less" string links with the ExpandMore and ExpandLess Material UI icons. Is there a way ...

Icons in Semantic-UI: Facing Difficulty in Accessing ("CORS Request Not HTTP"

Here's an example I'm working on: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Understanding - Main</title> <link rel="stylesheet" type="text/css" href="../semantic/dist/semanti ...

Converted my Flask code into a specialized software package, encountering a perplexing TemplotNotFound error

After reorganizing my Flask code into a Python package structure, I am facing an issue where none of the HTML templates can be found when I run the code. Let me outline the simplified structure of my current Flask package. The run.py file is responsible f ...

How to Choose a Radio Button from a Group using Selenium WebDriver and Java

My goal is to be able to choose a specific radio button from a set of radio buttons grouped by the name attribute: <div> <input type="radio" name="exampleInputRadio" id="optionRadio1" value="1"> <input type="radio" name="exampleInpu ...

Insert text within the switch component using Material-UI

Looking to customize Material UI's Switch component with text inside? Check out the image below for an idea of what I'm going for. https://i.stack.imgur.com/KadRZ.png Take a look at my code snippet: import React from 'react'; import S ...

What factors influence the timing of Chrome's spell-check feature for a particular word?

Currently, I am troubleshooting a bug in our code that is related to text input behavior. The issue at hand is that in one field, when you start typing on Chrome, the word does not get red underlined until you press space. However, in another field, Chrom ...

How can I incorporate a custom color into a preset navbar on an HTML webpage?

<div class="navbar-header"> <button aria-controls="navbar" aria-expanded="false" data-target="#navbar" data-toggle="collapse" style="color: blue;" class="navbar-toggle collapsed" type="button"> <i class="fa fa-reo ...

Having difficulty centering an image in HTML?

I've been struggling to get the image (logo) centered on the top bar! I've tried using align-self: center;, display:block;, but nothing seems to work. It feels like I'm missing something here! Click here for the codesandbox link to view the ...

Mobile Apps Plagued by Frozen Preloader Gif Images

Working with jQueryMobile(1.3.1) and Phonegap(2.7.0) for developing Android and iPhone applications has presented me with a challenge regarding the Preloader Image. I am currently using a Gif image as my preloader. The custom function I am using for the p ...

By incorporating JavaScript, clicking on an image will trigger a shift in the position of a different element

Just starting out with JavaScript and experimenting with creating an event where clicking on an image triggers the movement of another hidden image. The hidden image is positioned off-screen to the left, while there is a table of images in the center of th ...

Unable to interact with a button element of type="button" using Selenium, but successful with elements of type

In my attempt to interact with the webpage, I am specifically focusing on this button: <button class="button-text-like marg-l-0 float-l desktop-only remove-button" data-bind="click: $root.removeCartItem" type="button"> <i class="gicon-cross">& ...

Creating a table with merged (colspan or rowspan) cells in HTML

Looking for assistance in creating an HTML table with a specific structure. Any help is appreciated! Thank you! https://i.stack.imgur.com/GVfhs.png Edit : [[Added the headers to table]].We need to develop this table within an Angular 9 application using T ...

Customizing the appearance of all Angular components with styles.scss

Is there a way to create a universal style in styles.scss that can be applied to all Component selectors (e.g. app-componentA, app-componentB ...)? I understand that I could manually add the style to each selector, but I am concerned that it may be forgot ...