Displaying a CSS span element as the topmost layer

I am struggling to get a tooltip to properly display on top of its parent element. Despite trying various combinations of z-index and overflow properties, I have not been able to achieve the desired outcome. The issue arises when hovering over the red box - the tooltip should appear on top so that it is not obscured by the parent element while also ensuring that the content does not extend beyond the boundaries, preserving the scroll functionality.

.parent {
    position: relative;
    float: left;
    margin-left: 30px;
    width: 380px;
    text-align: left;
    height: 380px;
    overflow-x: hidden;
    overflow-y: scroll;
    border: 2px solid #f4f4f4;
    border-radius: 2px;
}

.child-container {
    text-align: center;
    border-radius: 2px;
    border-color: transparent;
    font-weight: normal;
    font-size: 12px;
    width: 80%;
/*    width: calc((100% - 83px) / 3);*/
    margin: 20px 10px 10px 15px;
    vertical-align: top;
    display: inline-block;
}

.header {
    padding: 10px;
    background-color: #e6e6e6;
    border: 1pt solid #ccc;
    border-radius: 2px;
}

label {
    color: #757575;
    text-align: left;
    line-height: 1.5;
    margin-bottom: 0;
    display: block;
}

.info {
    border: 0;
    height: 15px;
    text-align: right;
    position: relative;
}

.info:hover .tooltip {
    display: block;
}

.img {
    display: inline-block;
    height: 15px;
    width: 15px;
    background: red;
}

.tooltip {
    width: 300px;
    text-align: center;
    color: white;
    background: #00c853;
    position: absolute;
    left: 50%;
    z-index: 100;
    padding: 5px;
    font-size: 14px;
    border-radius: 2px;
    display: none;
    top: 150%;
    margin-left: -150px;
}

.tooltip.top:after {
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid #00c853;
    content: '';
    position: absolute;
    left: 50%;
    bottom: -10px;
    margin-left: -10px;
    border-top-color: transparent;
    border-bottom: 10px solid #00c853;
    top: -20px;
    bottom: auto;
}
<div class="parent">
    <div class="child-container" style="display: inline-block;">
        <div class="header">MY HEADER</div>

        {/* More child elements here ... */}

    </div>
</div>

Answer №1

It seems like you're looking to adjust the positioning of your tooltip so that it doesn't overlap with the list on the left side while scrolling. Here are some CSS modifications you can apply to achieve this:

.tooltip {
    width: 250px;
    text-align: center;
    color: white;
    background: #00c853;
    position: absolute;
    left: 0;
    z-index: 100;
    padding: 5px;
    font-size: 14px;
    border-radius: 2px;
    display: none;
    top: 150%;
    margin-left: 0;
}
.tooltip.top:after {
    width: 0;
    height: 0;
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
    border-top: 7px solid #00c853;
    content: '';
    position: absolute;
    left: 11px;
    bottom: -10px;
    margin-left: -10px;
    border-top-color: transparent;
    border-bottom: 7px solid #00c853;
    top: -14px;
    bottom: auto;
}

Furthermore, consider removing the inline styling applied to <span class="tooltip top"> in the HTML markup.

You can see the updated code on jsfiddle here.

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

Differentiating between Chrome and Safari user-agent strings using CSS only (without JavaScript)

Are there specific CSS selectors that can target Safari and Chrome exclusively? When attempting to target only Safari, I initially tried the following selector, but it seems to also target Chrome: html[data-useragent*="Safari"] { [...] } ...

Creating circular and square elements with flexbox using HTML and CSS

Struggling to implement flexbox correctly using only HTML and CSS. Any tips on how to achieve this? Also, looking for guidance on making it responsive with media queries. Link to the image Appreciate any help in advance! ...

Displaying a div and ensuring it remains visible upon clicking

$(document).ready(function() { $('#input').focusin(function() { if ($(this).val() != '') { $('#div').show(); } else { $('#div').hide(); } $('#input').keyup(function() { / ...

Utilizing AngularJS to create a dynamic autocomplete feature with data sourced

I'm currently implementing an autocomplete feature using the REST Countries web service. The goal is to provide suggestions as the user starts typing in an input field, and once a country is selected, display information about it. I am considering usi ...

PHP HTML failing to recognize "mandatory" attributes

I'm facing an issue with adding validation for an empty field. When the field is left empty, the form should not be submitted. However, the "required" attributes seem to be ineffective in achieving this. Birthdate: <select name="month" r ...

JQueryMobile 1.3.2 encounters issues with popups following the installation of Chrome version 43.0.2357.65 m update

Is anyone else experiencing issues with the latest version of Chrome "43.0.2357.65 m" causing problems with JQueryMobile 1.3.2? When I try to click on a popup, it suddenly jumps to the top of the page and the scroll bar disappears. This was not an issue in ...

I have not made any changes to the <div> tag with my CSS or JavaScript coding

Click here to see the problem I am facing on JSFiddle. I am trying to create a loading screen that will slide up after a few seconds using jQuery. Although I am familiar with HTML, JavaScript, and CSS, I am still new to jQuery. I have a feeling that the so ...

When echoing SESSION in PHP, the previous value is displayed

<script language="javascript"> function handleEmergency() { if(document.getElementById('emer').checked == true) { <?php $_SESSION['total2']= $_SESSION['total1'] ...

Issues with navigation menu not showing dropdown options and impacting webpage layout (HTML/CSS)

I'm having trouble creating a drop-down navigation menu using HTML and CSS. When I add the drop-down list, my menu extends onto two lines instead of one, and the drop-down menu doesn't appear when hovering. Here is a link to the jsfiddle for refe ...

Incorporating a hyperlink within a list item for an image

Currently, I am attempting to create a clickable image within an unordered list. Although the paragraph is clickable, unfortunately, the image itself is not responding as expected. <ul> <a href="/movies/test/"><li> ...

Populating a read-only field with information from a database upon selecting an option

My goal is to select a name from an option field and then display the user's ID in a non-editable field. Essentially, when I choose a username, I want to automatically show their user ID. Below is the PHP and HTML code I currently have: <form id=" ...

Perform CSS transitions simultaneously

Hey there! I'm currently working on a button that includes a Font Awesome icon at the end of it. To display the icon, I'm using the :after pseudo-element on the button, which is working fine so far. The issue I'm facing is with the CSS tran ...

What is the best method for adding a background image to a jumbotron in my Django project?

I have been struggling with this issue for some time now. Currently, I am working on a Django project and I need to add an image as the background in the jumbotron section. home.html {% extends 'blog/base.html' %} {% load static %} {% bl ...

Incorporating a text box underneath the model image

My application currently utilizes a grid gallery that perfectly fits my needs. However, there are two specific changes I need to make in order for it to be complete for my purpose. Unfortunately, I am struggling to figure out how to implement these changes ...

The function string.charAt() is returning a value of 0

I'm attempting to output each letter of a word separately by using the variable string. Here is the code I have so far: function typewriter() { var el = document.getElementById("typewr"); var string = "Hello"; for(var i=0;i<string.le ...

Is there a way to access the chat source code without relying on selenium for assistance?

My dilemma lies in wanting to extract the user's id information from the chat interface. The specific section I am interested in within the chat area appears as follows... <div id="chat_area" class="chat_area" style="will- ...

Generate visual representations of data sorted by category using AngularJS components

I am facing an unusual issue with Highcharts and Angularjs 1.6 integration. I have implemented components to display graphs based on the chart type. Below is an example of the JSON data structure: "Widgets":[ { "Id":1, "description":"Tes ...

Is there a way to keep the background image stationary as I scroll?

As someone who is new to html and CSS, I recently tried to enhance my previous project by incorporating a background image that spans the entire screen size and remains fixed while scrolling up or down. Here is the code snippet: ''' body { ...

Exploring the foundations of web development with html and stylus

If you have experience with the roots platform, you are familiar with its default stack including jade, stylus, and coffee script. The documentation provides some information on using HTML, CSS, and pure JavaScript instead of the compiled languages, but d ...

Creating Widgets with the help of CSS3 and HTML5

I am truly fascinated by the capabilities of HTML5 and CSS3 working together, and it's common knowledge that they require a browser to function. However, I'm curious if there is a way to create Desktop Widgets or Apps using HTML5, CSS3, and Java ...