Display the entire paragraph when hovering over it

Is there a way to make the entire paragraph appear on hover instead of just showing parts of it? I am building a website on Weebly for a school project and my knowledge is limited.

I tried using the following code, but it only displays some of the content. Ideally, I would like all the words in the paragraph to be visible when hovering over it.

.tooltip {
  position: relative;
  display: inline-block;
  border-bottom: 1px dotted black;
}

.tooltip .tooltiptext {
  visibility: hidden;
  width: 120px;
  background-color: black;
  color: #fff;
  text-align: center;
  border-radius: 6px;
  padding: 5px 0;
  position: absolute;
  z-index: 1;
  overflow-wrap: break-word;
}

.tooltip .tooltiptext {
  width: 120px;
  bottom: 100%;
  left: 50%;
  margin-left: -60px;
}

.tooltip:hover .tooltiptext {
  visibility: visible;
}
<center>
  <br><br>
  <div class="tooltip">Word
    <span class="tooltiptext">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent cursus, leo sit amet maximus finibus, quam justo interdum dolor, ac auctor mi elit eu nisi. Praesent vel facilisis mi. Nulla non ligula eget nunc euismod consectetur porta a elit. Pellentesque sodales ipsum nibh, at pretium mi vehicula luctus. Morbi dapibus felis vitae dolor ultrices dapibus. Sed vestibulum a augue id ultricies. Etiam mi diam, hendrerit a quam id, convallis molestie urna. Nullam facilisis elit sit amet lobortis malesuada. Donec lacinia ante turpis, id laoreet risus egestas scelerisque. Aliquam at iaculis nisl. Donec nec venenatis neque. In mollis mauris laoreet pellentesque efficitur. Proin feugiat elit sit amet lacus commodo luctus. Donec rhoncus ipsum vel nibh feugiat, eget feugiat justo volutpat. Aenean et nunc nunc.</span>
  </div>
</center>

Answer №1

Your text may appear cut off at the top due to the CSS property bottom:100%;. This fixes the bottom of the text container to the top of the tooltip, and if there isn't enough space above the tooltip, the text may extend beyond the HTML page because of its absolute positioning. Ensure that there is ample room above the tooltip, or adjust the content position so it has enough visible space. Below is a revised code snippet where top:0; is used instead. Additionally, the deprecated <center> tag has been removed, and some styling has been applied to the body:

<html>

<head>
  <style>
    body {
      min-height: 100dvh;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    
    .tooltip {
      position: relative;
      display: inline-block;
      border-bottom: 1px dotted black;
    }
    
    .tooltip .tooltiptext {
      visibility: hidden;
      width: 120px;
      background-color: black;
      color: #fff;
      text-align: center;
      border-radius: 6px;
      padding: 5px 0;
      position: absolute;
      z-index: 1;
      top: 0;
    }
    
    .tooltip:hover .tooltiptext {
      visibility: visible;
    }
  </style>
</head>

<body>
  <div class="tooltip">Word
    <span class="tooltiptext">Lorem ipsum dolor sit amet, consectetur adipiscing elit.Lorem ipsum dolor sit amet, consectetur adipiscing elit.Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span>
  </div>
</body>

</html>

Answer №2

The issue with the code is that the tooltip text overflows and does not display correctly. To fix this, consider applying the following CSS styles:

.tooltip {
  white-space: nowrap; /* Ensure text does not wrap */
}

.tooltip .tooltiptext {
  white-space: normal; /* Allow text wrapping in the tooltip */
}

By adding white-space: nowrap; to the .tooltip class, you prevent text from wrapping inside the tooltip box. This ensures the entire paragraph is visible when hovered over.

By including white-space: normal; in the .tooltip .tooltiptext class, you enable text wrapping if it exceeds the container width.

Here is an updated version of the code with these additional CSS rules:

<style>
.tooltip {
  position: relative;
  display: inline-block;
  border-bottom: 1px dotted black;
  white-space: nowrap; /* Prevent text wrapping */
}

.tooltip .tooltiptext {
  visibility: hidden;
  width: 120px;
  background-color: black;
  color: #fff;
  text-align: center;
  border-radius: 6px;
  padding: 5px 0;
  position: absolute;
  z-index: 1;
  overflow-wrap: break-word;
  white-space: normal; /* Allow text wrapping within the tooltip */
}

.tooltip .tooltiptext {
  width: 120px;
  bottom: 100%;
  left: 50%;
  margin-left: -60px;
}

.tooltip:hover .tooltiptext {
  visibility: visible;
}
</style>

<center>
  <br><br>
  <div class="tooltip">Word
    <span class="tooltiptext">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent cursus, leo sit amet maxim...</span>
  </div>
</center>
After making these adjustments, the tooltip text should display properly on hover, ensuring the entirety of the paragraph is visible within the tooltip container.

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

incorrect sequence of div elements appearing vertically

I'm having trouble organizing the header, page title, and navigation bar on my webpage. Despite my attempts to structure them correctly, they are not displaying in the desired order as shown below: https://i.stack.imgur.com/A3rQe.jpg The issue arises ...

The size of the elements inside a div should be proportional to its parent div

I am struggling with sizing elements within a div. I have set the max-width to 40% and max-height to 25%, and inside is an image that I want to be 80% of its parent div. Here is the code snippet for reference: <div className="inputbox-container&qu ...

Please refer to the appropriate manual for your MySQL server version to find the correct syntax for the following statement: `'' , , '', '', '', '', '', '', NOW())' at line 2`

I encountered an error and since I am new to programming, I would appreciate any corrections. Thank you! <? $customername = $_REQUEST["customername"]; //$customername = strtoupper($customername); //$customername = trim($customername); $address1=$_RE ...

Create a design where the logo seems to be suspended from the navigation bar using bootstrap

My goal is to achieve a navigation bar similar to the one shown in this image: Using Bootstrap 3, the code below is what I have implemented for my navigation: <nav class="navbar navbar-default navbar-fixed-top"> <div class="container"> <di ...

What is the best way to retrieve both the start and end date values from a React date range picker component

I have integrated a date range picker npm package called react-date-range into my code. On my screen, there is an "Apply Dates" button. When this button is clicked, I want to retrieve the selected date range value. How can I achieve this onclick event? ...

Persistent header feature in AdminLTE 3: Easily navigate while scrolling

I am looking to make the elements in the red box on the left side of the page fixed so that as users scroll, they remain at the top of the page. I have attempted to use both the fixed and sticky properties, but neither seem to be working for me. Here is a ...

CSS tip: Create a trendy design by adding a slanted border to the last

I need help creating a unique menu list with a white border design. The borders should all be straight by default, except for the last border which must be slanted. ul { background-color: #183650; } li { list-style: none; display: inline-block; b ...

Is there a challenge in setting up a tag search bar similar to Stack Overflow's?

First and foremost, I apologize for the awkwardly phrased question. The issue at hand is that when the tags exceed the container size, the search option becomes hidden. My goal is to have the search bar adjust dynamically, moving everything back inside the ...

How can I ensure that all the text is always in lowercase in my Angular project?

Is there a way to ensure that when a user enters text into an input field to search for a chip, the text is always converted to lowercase before being processed? Currently, it seems possible for a user to create multiple chips with variations in capitaliza ...

"Selecting elements using the nth-of-type CSS selector alongside other

Dealing with a grid layout that includes spacers between certain items, I attempted to use the :nth-of-type selector in CSS to style only the first column of items and not apply those styles to the right side. However, it seems that the CSS gets confused w ...

What is the best way to manage a session using JavaScript?

Currently developing a website that initially hides all elements except for the password box upon loading. Once the user enters the correct password, all webpage elements are revealed. Seeking a solution to keep the elements visible on reload by utilizing ...

Why did my compilation process fail to include the style files despite compiling all other files successfully?

As English is not my first language, I kindly ask for your understanding with any typing mistakes. I have created a workspace with the image depicted here; Afterwards, I executed "tsc -p ." to compile my files; You can view the generated files here Unf ...

Events Unavailable for Viewing - Full Calendar - Database Error Encountered

I am currently developing a calendar application. While I have managed to successfully display the calendar and add events, I am facing an issue with displaying events on the monthly view. Here is a snippet of the HTML code being used: <head> &l ...

Guide to customizing the CSS styles of various components within a Material UI Dialog

Let's take a look at this snippet for creating a Material Dialog in code: <Dialog open={this.props.open} onClose={this.props.closeAtParent} PaperProps={{ style: { minHeight: '75vh', minWidth: '75vw', ...

Dynamic class name changes in Angular.js based on JSON object

I am trying to dynamically change the class of an <li> element based on the category value I am getting, but for some reason the class name won't update. Here is the code snippet: <div id="content"> <ul id="container" ng-controller ...

Guide to importing external CSS styles into Angular 2 using the require method

I'm facing an issue with loading an external css file in different environment files. My setup includes two environments: development and production. Loading the css file locally works fine in development mode, but not in production mode. environment ...

Ways to eliminate a css class with jquery based on a specific screen dimension

There is a div element that includes a specific class. My goal is to remove this class when the window is resized to fit a mobile view-port. <div class="box"></div> ...

The first-child and last-child selectors are not working properly in the CSS

In the family of elements, the first child should proudly show off the image icon for home while the last child remains humble without any background imagery: Check out the evidence here: http://jsfiddle.net/gUqC2/ The issue at hand is that the first chi ...

Customize a theme component only when it is a child of another component

I am trying to customize the CSS of MuiButton only when it is nested inside a MuiDialog. https://i.stack.imgur.com/13doLm.png In regular CSS, you could achieve this with: .MuiDialog-root .MuiButton-root { border: 5px solid blue; } However, I am strug ...

Updating SVG colors using VueJS

I'm struggling to change the color of an existing static SVG image. Here's the code I have: <img class="icon-shop" src="@/assets/icon-shop.svg"/> <style> .icon-shop { width: 32px; fill: orange; stroke: oran ...