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

php Use cURL and the DOM to extract content with specified CSS styling

Unclear in the title, I want to copy all content from a specific div on an existing webpage (not owned by me). The code successfully extracts the content. Extractor code: // Get Data $curl_handle=curl_init(); curl_setopt($c ...

HTTP request form

I'm currently working on a form that utilizes XMLHttpRequest, and I've encountered an issue: Upon form submission, if the response is 0 (string), the message displayed in the #output section is "Something went wrong..." (which is correct); Howe ...

Is there a way to retrieve a numerical value from within two specific elements when web scraping?

I am new to web scraping and looking to extract the numbers located between the strong tags. Currently, I am using Python 3.8 along with BeautifulSoup for this task. <li class="price-current"> <span class="price-current-label"> </s ...

What is the best way to ensure a string of words in HTML/CSS wraps to the next line seamlessly?

As I work on creating my portfolio website using Bootstrap and custom CSS, I am running into an issue with the game titles breaking in the middle when displayed. Despite my limited proficiency in English, I tried searching for a solution without success. ...

What could be causing the closest() method in my JavaScript code to not locate the nearest class?

I've encountered an issue while dynamically creating new classes with input fields in my project. For some reason, when I try to remove a previous row, nothing happens. Can anyone help me troubleshoot this problem? Here is the JavaScript code that I ...

The content spills out of the container

I'm currently working with a div that displays scrolling text when it overflows. I am wondering if there is a way to hide the scroll bars until the text actually overflows? Additionally, is there a method to make the overflow occur only vertically and ...

I'm new to Angular and I'm wondering how to close the panel by clicking on the 'x' button and also by clicking on the screen. Can anyone help me with this

Below is the HTML code I use for my button: <button class="btn btn-outlined " ng-click="vm.showCommentBox1()">Notify All</button> <div class="comment-box custom saveAll" ng-if=""><div class="panel panel-default"> ...

Tips on toggling between slides with Bootstrap Carousel

I am in the process of designing a portfolio website and have encountered a challenge. I want to divide it into two sections - a brief introduction and a carousel for showcasing projects. While I have managed to set up both sections, I'm facing an iss ...

Customizing the layout of specific pages in NextJSIncorporating

In my Next.js project, I'm trying to set up a header and footer on every page except for the Login page. I initially created a layout.tsx file in the app directory to apply the layout to all pages, which worked fine. However, when I placed another lay ...

The perplexing illusion of the undecipherable table! Numerous mergers fail to

Attempting to combine cells 1, 2, and 3. The current code successfully merged cells 1 and 2: <td rowspan="2" colspan="2"> &nbsp;1</td> I left the second row empty to accommodate this change. <tr> </tr> However, the mergin ...

issue with manipulating URLs in Express routing

Looking for assistance with Express routing. I want users to only see localhost:3000/page2 when they go to /page2, instead of localhost:3000/page2.html I have three HTML pages - page1.html, page2.html, and page3.html. I've created a server using Expr ...

Utilizing CSS classes to style custom day templates in ng-bootstraps datepicker

Currently, I am utilizing ng-bootstraps datepicker to showcase user data on a daily basis. I have implemented a custom day template to apply specific CSS classes. <ng-template #customDay let-date> <div class="custom-day" [ngCla ...

Three divs arranged side by side with responsive design for mobile viewing

This code generates 3 divs for display. However, I am looking to optimize them for mobile devices. What steps can I take to accomplish this? Currently, the divs are oriented to the left and are not visible on a mobile device. I would like them to display ...

Using jQuery, selectively reveal and conceal multiple tbody groups by first concealing them, then revealing them based on

My goal is to initially display only the first tbody on page load, followed by showing the remaining tbody sections based on a selection in a dropdown using jQuery. Please see below for a snippet of the code. //custom JS to add $("#choice").change(func ...

Unable to Click on Selenium Element

When a link is clicked on a website, the URL remains unchanged but a popup appears on the screen containing elements that can only be accessed after running driver.switchTo().defaultContent(). To access these elements, I have used a javascript executor com ...

Automatically resize ui-select dropdown box to the left side

I've been tasked with incorporating AngularJS ui-select into my project, specifically creating a multiselect dropdown. Currently, the dropdown box automatically adjusts its width based on the length of the longest selectable text, causing it to extend ...

Exploring Angular 6: Unveiling the Secrets of Angular Specific Attributes

When working with a component, I have included the angular i18n attribute like so: <app-text i18n="meaning|description"> DeveloperText </app-text> I am trying to retrieve this property. I attempted using ElementRef to access nativeElement, bu ...

Hilarious rendering glitch with CSS in IE where the background image inexplicably contains the style "display: block."

Encountering a curious issue with how IE is interpreting my css. The defined style includes "background-image: url(/images/leftArrow.png); DISPLAY: block; cursor: pointer;" However, IE 7 & 8 seem to be merging background and display as one property (r ...

Adjust the height of the div element to match the screen height with AngularJS controller

Can someone please assist me in resolving this issue? I'm currently working on a div element that displays data (positioned on the left side of the screen). I want to add a scrollbar exclusively to this div. I managed to achieve this by using the fol ...

Using CSS nth-child to create a two-column checkers layout

I have formulated a form on my website that divides into two columns by using floats. I am interested in creating a "checkered" effect for these columns. Can anyone guide me on how to utilize nth-child to achieve this design layout? For reference, please c ...