Guide to positioning social media icons and their tooltip within a navbar using Bootstrap4

I am struggling to align the social icons and their tooltips with the rest of my navbar. The issue is that the icons are not centered within the square, and their tooltips do not align correctly under the yellow box (although in other parts of the code, such as under the image and name, the tooltips are perfectly centered and aligned under the yellow box). Additionally, I am unsure how to create distance between them.

Apologies for the messy code, as I am new to HTML and CSS.

I utilized Bootstrap 4 for the navbar yellow box and Font Awesome for the social icons. https://i.sstatic.net/NwAlj.png https://i.sstatic.net/yztlp.png

I have omitted sections regarding the logo and title.

.container {
    display: flex; /* allows me to align all elements */
    margin: 15;
    padding: 20;
}
.social {
    position: relative;
    display: inline-block;
  }

/* Align list items */
.social ul{
    display: flex;
}

/* Remove list item bullets */
.social ul li{
    list-style: none; 
    display: inline-block;
}


/* Tooltip styling */
span.tooltiptext{
    visibility: hidden;
    width: 120px;
    background-color:#803c25;
    color:#fff;
    text-align: center;
    border-radius: 6px;
  

    /* Tooltip positioning */
    position: absolute;
    z-index: 1;
    top: 100%;
    margin-left: -79px;
    
    /* Tooltip blur effect */
    opacity: 0;
    transition: 0.3s;
}

/* Tooltip pointer position */
span.tooltiptext::after {
    content: " ";
    position: absolute;
    bottom: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color:transparent transparent #803c25 transparent;
  }

.social ul li:hover span.tooltiptext{
    visibility: visible;
    opacity: 1;
}

/* Social Media Icons */

.fa {
    padding: 20px;
    font-size: 30px;
    width: 30px;
    text-align: center;
    text-decoration: none;
  }
  

.fa-facebook {
  background: #3B5998;
  color: white;
  text-decoration: none
}

.fa-tripadvisor {
    background: #00af87;
    color: white;
    text-decoration: none
  }
<!-- Bootstrap script for navbar background -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>

    

    <!-- Navbar-->
    <link href="nav.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<body>
        <header>
            <nav class="navbar navbar-expand-sm bg-warning navbar-dark">
                <div class="container">

                <div class="logo">
                        <a href="gestione.html">
                            <img src="./Immagini/logo.PNG">
                            <span class="tooltiptext"> Login Admin</span>
                        </a>
                </div>

                <div class="nome">
                    <a href="index.html">Il Brigante</a>
                    <span class="tooltiptext">Home</span>
                </div>

                <div class="social">
                    
                    <ul>
                        <li>
                            <a class="fa fa-facebook" target="_blank"></a>

                            <span class="tooltiptext"> Seguici su facebook</span>
                        </li>

                        <li>
                            <a class="fa fa-tripadvisor"target="_blank">
                                </a>

                            <span class="tooltiptext"> Guarda le nostre recensioni</span>
                        </li>

                    </ul>
                </div>
            </div>
            </nav>
        </header>
    </body>

Answer №1

Your code needs some improvement to make it more stable.

Remember, you can overwrite the Bootstrap CSS, but not by directly adding CSS in the bootstrap classes.

I made some modifications and added some CSS to your code:

I removed margin-left: -79px; from your tooltip as it may cause issues in the future.

I added position: relative to your .social ul li and adjusted the positioning of your tooltip using

left: 50%; transform: translateX(-50%);
for centering purposes.

I applied d-flex justify-content-center classes to your icons to center them within a block.

.container {
  display: flex;
  /* Allows alignment of all elements */
  margin: 15;
  padding: 20;
}

.social {
  position: relative;
  display: inline-block;
}


/* Align list elements */

.social ul {
  display: flex;
}


/* Remove bullet points */

.social ul li {
  list-style: none;
  display: inline-block;
  position: relative;
}


/* Tooltip styling */

span.tooltiptext {
  visibility: hidden;
  width: 120px;
  background-color: #803c25;
  color: #fff;
  text-align: center;
  border-radius: 6px;
  position: absolute;
  z-index: 1;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  opacity: 0;
  transition: 0.3s;
}


/* Tooltip pointer position */

span.tooltiptext::after {
  content: " ";
  position: absolute;
  bottom: 100%;
  left: 50%;
  margin-left: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: transparent transparent #803c25 transparent;
}

.social ul li:hover span.tooltiptext {
  visibility: visible;
  opacity: 1;
}


/* Social icons styling */

.fa {
  padding: 20px;
  font-size: 30px;
  width: 30px;
  text-align: center;
  text-decoration: none;
}

.fa-facebook {
  background: #3B5998;
  color: white;
  text-decoration: none
}

.fa-tripadvisor {
  background: #00af87;
  color: white;
  text-decoration: none
}
<!-- Bootstrap script for navbar background -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>

<!-- Navbar styling -->
<link href="nav.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/fontawesome.min.css">

<body>
  <header>
    <nav class="navbar navbar-expand-sm bg-warning navbar-dark">
      <div class="container">

        <div class="logo">
          <a href="gestione.html">
            <img src="./Images/logo.PNG">
            <span class="tooltiptext"> Admin Login</span>
          </a>
        </div>

        <div class="name">
          <a href="index.html">The Brigand</a>
          <span class="tooltiptext">Home</span>
        </div>

        <div class="social">

          <ul>
            <li>
              <a class="fa fa-facebook d-flex justify-content-center" target="_blank"></a>

              <span class="tooltiptext"> Follow us on Facebook</span>
            </li>

            <li>
              <a class="fa fa-tripadvisor d-flex justify-content-center" target="_blank">
              </a>

              <span class="tooltiptext"> Check out our reviews</span>
            </li>

          </ul>
        </div>
      </div>
    </nav>
  </header>
</body>

Answer №2

To style the "a" tag, you will need to include the following CSS:

    .container {
        display: flex; /* aligns all elements */
        margin: 15;
        padding: 20;
    }
    .social {
        position: relative;
        display: inline-block;
      }

    /* Align list items */
    .social ul{
        display: flex;
    }

    /* Remove bullet points */
.social ul li{
list-style: none; 
display: inline-block;
list-style-type: none;
}
.social ul li a{
display: flex;
align-items: center;
justify-content: center;
}

    /* Tooltip text when hovering over an area */
    span.tooltiptext{
        /* Text styling */
        visibility: hidden;
        width: 120px;
        background-color:#803c25;
        color:#fff;
        text-align: center;
        border-radius: 6px;
      

        /* Placement of the tooltip */
        position: absolute;
        z-index: 1;
        top: 100%;
        margin-left: -79px;
        
        /* Blur effect */
        opacity: 0;
        transition: 0.3s;
    }

/* Positioning of the tooltip pointer */
span.tooltiptext::after {
    content: " ";
    position: absolute;
    bottom: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color:transparent transparent #803c25 transparent;
  }

.social ul li:hover span.tooltiptext{
    visibility: visible;
    opacity: 1;
}

/* Social Media Icons */

.fa {
    padding: 20px;
    font-size: 30px;
    width: 30px;
    text-align: center;
    text-decoration: none;
  }
  

.fa-facebook {
  background: #3B5998;
  color: white;
  text-decoration: none
}

.fa-tripadvisor {
    background: #00af87;
    color: white;
    text-decoration: none
  }
<!-- Bootstrap script for navbar background-->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>

    

    <!-- Navbar-->
    <link href="nav.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<body>
        <header>
            <nav class="navbar navbar-expand-sm bg-warning navbar-dark">
                <div class="container">

                <div class="logo">
                        <a href="gestione.html">
                            <img src="./Immagini/logo.PNG">
                            <span class="tooltiptext"> Login Admin</span>
                        </a>
                </div>

                <div class="nome">
                    <a href="index.html">Il Brigante</a>
                    <span class="tooltiptext">Home</span>
                </div>

                <div class="social">
                    
                    <ul>
                        <li>
                            <a class="fa fa-facebook" target="_blank"></a>

                            <span class="tooltiptext"> Follow us on Facebook</span>
                        </li>

                        <li>
                            <a class="fa fa-tripadvisor" target="_blank">
                                </a>

                            <span class="tooltiptext"> Check out our reviews</span>
                        </li>

                    </ul>
                </div>
            </div>
            </nav>
        </header>
    </body>

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

The Android smartphone is experiencing issues with the responsive design not aligning properly on the

I'm encountering difficulties with creating a Viewport that functions properly on an android smartphone. My website is fully responsive, scaling down to 480 pixels wide. At this point, a min-width of 480px is set on the body tag. Initially, my viewp ...

The height of the div is set to zero within the $(document).ready() function

From what I understand, when we write JQuery code inside $(document).ready(), the code will only be executed after the DOM has finished rendering. I encountered an issue where I was trying to calculate the height of a div inside $(document).ready() but it ...

Modifying a Nested Component with react-icons

As I work on creating a rating component that utilizes react-icons to display icons, I have encountered an interesting challenge. Currently, I am using the FaStarhalf icon which represents a pre-filled half star that can be flipped to give the appearance o ...

Personalize the bootstrap-vue styling within your Nuxt project

Currently, I am working on a nuxt project and utilizing bootstrap-vue as a styling module for my components. I am unsatisfied with the default styles provided and wish to incorporate some customization. Specifically, I aim to modify the appearance of the ...

When the margin-left changes, SVG begins to flicker and shake in a marquee effect

I've been experimenting with a marquee effect using vanilla JS. The effect is working, but I'm encountering some shaking issues with SVG and images as they move. <div class="marquee"> <h1>Nepal <svg version="1.1&qu ...

Having trouble looping through Html5 canvas with JavaScript in Rails?

I am working on a rails project where I have a model called microposts: class Micropost < ActiveRecord::Base attr_accessible :content, :avatar belongs_to :user mount_uploader :avatar, ImageUploader To display the microposts, I created a partial ...

"Angular File Upload Made Easy with Drag-and-Drop Functionality and Cleverly Positioned

Encountering an issue with Angular File upload in conjunction with relatively positioned elements. The drop target is set to 100% width and height, absolutely positioned. While dragging a file over any non-relatively positioned element, the overlay functio ...

Utilizing Bootstrap 4 to arrange each card in its own row

On small screens, I want Bootstrap to display 1 card per row, 2 cards per row on medium screens, and 3 cards per row on large screens. I'm using <div class="col-sm-12 col-md-6 col-lg-4"> and it's working for medium and large screens, but o ...

Ways to enable file/result downloads on a website using HTML

Could you please take a look at this repository: https://github.com/imsikka/ArtGallery I am looking to create a downloadable result using a download button. I can create the button, but I am unsure of how to make the file actually downloadable. Do I need ...

The official sign-in buttons for Facebook, Google, and Twitter are all neatly aligned on the same row with a sleek and

https://i.sstatic.net/bXOMb.pngHello, I am currently working on integrating social media sign up functionality into my Oracle Apex login page. To achieve this, I am utilizing JavaScript APIs for various social media applications. However, I'm facing a ...

The HTML image link is adorned with a tiny blue checkmark underneath

My a tag with an image inside seems to be extending below the image, resulting in a small blue tic mark on the bottom right side. I've attempted different CSS solutions such as setting border to none, but nothing has resolved the issue. Any assistance ...

Focusing on a particular iframe

I am currently using the "Music" theme from Organic Theme on my WordPress site and have inserted this code to prevent SoundCloud and MixCloud oEmbeds from stretching the page width: iframe, embed { height: 100%; width: 100%; } Although the fitvid ...

Issues with retrieving $_POST values from a select form in PHP

When the button is clicked, I am sending a AJAX request to my PHP page using POST method with the selected data from a SELECT element. However, I am facing an issue where my PHP IF statements are not evaluating as true. It always defaults to the ELSE condi ...

Show a concealed dropdown menu within a CSS grid column utilizing clip-path styling

Working on a Django admin header that makes use of CSS grid to create two columns. I have added a JavaScript dropdown effect to the user icon for displaying options like "Change Password" and "Log Out". However, encountering an issue where the dropdown rem ...

In terms of professional design, which is the better choice - Bootstrap or Foundation?

Greetings! I am in the process of creating a website with a professional design. I'm trying to decide between using Bootstrap 3 or Foundation 5 for my CSS framework. Which one do you recommend for designing purposes? Is there another CSS framework t ...

Continuously I am being informed that the value is null

Check out this code snippet: var Ribbon = /** @class */ (function () { function Ribbon(svg) { // Code here... } Ribbon.prototype.init = function() { // Initialization code here... }; Ribbon.prototype.updateR ...

Angular components are not inheriting the Bootstrap row class as expected

Within my codebase, there are numerous controls declared in the following manner. <div class="row"> <div class="col-sm-12"> <div>Caption</div> <input type="text" class="form-control"> </div> </div> In ...

Differences between Firefox and Webkit browsers when it comes to scrolling - How side navigation, text truncation, and

Scrollbar appearance is causing an issue across different browsers. The truncated text in my side-navigation component is not displaying correctly on Firefox and IE browsers. View this fiddle on both Chrome and Firefox: https://jsfiddle.net/d84b9m49/10/ ...

Navigation bar text fails to display

Just starting out and trying to create a basic navigation bar, but I can't seem to get the links to show up. All that displays are the logo image and the hamburger icon. How can I make the links visible on the nav bar? Appreciate any help! <!DOCTYP ...

Is it necessary to include CDN @imports when optimizing CSS files in a Require.js/Backbone app using r.js?

In my CSS file, I've included an external font from Google Font using the @import rule. styles.css /* You can use @import. r.js will handle merging them during the build process */ @import "../vendor/bootstrap/css/bootstrap.css"; //this has been inc ...