To reveal truncated words one at a time for each item, simply hover your mouse over the text field to see the complete text appear

The content on the pages can be partially displayed by unfolding or closing the remaining content in html/JS through this link (the page already has an unfold or close function in a box). Now, I want to display the partial titles of the contents in the boxes, pictures, and list.html on the page.

The long green words in the red box are the titles of the contents. Each title is too long to read at once, so I want to display them one line for each object, and when the mouse pointer hovers over the text fields, the full text will be displayed.

If I use the code as provided below, the unfold or close function of the box will not work, and hovering over the text fields will not display the full text, only part of it.

https://i.sstatic.net/CGzT9.png

<style type="text/css">
#box1,#box2,#box3,#box4,#box5,#box6{padding:12px;border:0px solid green;}
.collapsed-content {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.expanded-content {
  display: block;
}

p{
display:inline-block;
overflow: hidden;
text-overflow:ellipsis;
white-space: nowrap;
max-width: 100px;

}

p:hover{
overflow:visible;
}

</style>
<script type="text/javascript">
function openShutManager(oSourceObj,oTargetObj,shutAble,oOpenTip,oShutTip){
var sourceObj = typeof oSourceObj == "string" ? document.getElementById(oSourceObj) : oSourceObj;
var targetObj = typeof oTargetObj == "string" ? document.getElementById(oTargetObj) : oTargetObj;

  //targetObj.classList.toggle("expanded-content");
  targetObj.classList.toggle("collapsed-content");
  if(targetObj.classList.contains("collapsed-content")){
    sourceObj.innerHTML = oShutTip;
  } else {
    sourceObj.innerHTML = oOpenTip;
  }
}
</script>


  <div class="card">
    <div class="card-header">
      <div class="row">
        <div class="col-10">
          <strong>List of Courses Studied</strong>
        </div>
      </div>
    </div>
   <div class="list-group list-group-flush list-group-formset">
      <div class="col-10 collapsed-content" id="box3" style="word-break: break-all;">
      {% for c in course %}
      <p class="hide"><a href="{% url 'supervisors:course_change' c.pk %}">{{ c }}</p></a>
      &nbsp;&nbsp;&nbsp;
      {% endfor %}
      </div>
    </div>
    <div><button onclick="openShutManager(this,'box3',false,'Click to Close','Click to Open')">Click to Open</button></div>
      <div class="card-footer">
       </div>
  </div>

Answer №1

There is no green text visible. If you want the bold text to be shortened when not hovered over, you can achieve this effect using CSS only:

.card-header .col-10 {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.card-header .col-10:hover {
    overflow: initial;
    white-space: initial;
    text-overflow: initial;
}
<div class="card">
    <div class="card-header">
      <div class="row">
        <div class="col-10">
          <strong>chinese text chinese text chinese text chinese text chinese text chinese text chinese text chinese text chinese text chinese text chinese text chinese text chinese text </strong>
        </div>
      </div>
    </div>
   <div class="list-group list-group-flush list-group-formset">
      <div class="col-10 collapsed-content" id="box3" style="word-break: break-all;">
      {% for c in course %}
      <a href="{% url 'supervisors:course_change' c.pk %}">{{ c }}</a>
      &nbsp;&nbsp;&nbsp;
      {% endfor %}
      </div>
    </div>
    <div><button onclick="openShutManager(this,'box3',false,'点击关闭','点击展开')">点击展开</button></div>
      <div class="card-footer">
       </div>
  </div>

Answer №2

Alright, here's another response:

Consider this scenario:

p{
display: inline-block;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
max-width: 100px;

}

p:hover{
overflow: visible;
}
<html>
<head>
</head>
<body>

<div class="hide">
<p>qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq</p>
</div>

</body>
</html>

You can adjust the max width to show only one line. I hope this helps!

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

Classes aren't displaying properly for elements inside

Is there a way to display the header only in a small size using the col-sm-* class of the div inside a container? It seems like the col-sm-* class is not working correctly and not floating them properly. <link href="https://maxcdn.bootstrapcdn.com/b ...

Applying CSS dynamically to a mat-cell in Angular 6

In my material table, I need to apply specific CSS classes based on the content of the cell. https://i.sstatic.net/YN6EO.png These are the CSS classes that I am using .status-code{ flex: 0 0 10% !important; width: 10% !important; } .status-code- ...

Passing the title of a page as data to a component in Next.js

I am currently working on setting a custom title for each page within my next.js project. Here is an example of a simple Layout: const MainLayout = props => { return ( <Layout style={{ minHeight: "100vh" }}> <Head> < ...

Create an array using modern ES6 imports syntax

I am currently in the process of transitioning Node javascript code to typescript, necessitating a shift from using require() to import. Below is the initial javascript: const stuff = [ require("./elsewhere/part1"), require("./elsew ...

What is the best way to invoke a single ajax function across multiple pages with varying URLs?

Hello everyone! I am attempting to streamline my ajax post function and use it across the entire site with different URLs on each page. Below is my original function and how it currently operates: <button type="button" class="submit" ...

Currently, I am experimenting with creating interactive tabs by utilizing jQuery

Does anyone have suggestions on how to create clickable tags using JavaScript without causing everything to disappear when clicking on the tabs? Here is the HTML code: <div id="contentwrap" class="round"> <h1>About Eclipse</h1> ...

Transforming a dynamic background image into dynamic HTML elements

Having trouble parsing a background image to HTML elements. The images are retrieved from a database and the HTML elements are dynamically created. However, the image is not displaying. I attempted to include JavaScript in the while loop but encountered ...

Using form.submit() alongside preventDefault() will not yield the desired outcome

My login form needs to either close the lightbox or update the error box based on the success of the login attempt. I suspect the issue lies with the onclick="formhash(this.form, this.form.password);" which is a JavaScript function that hashes a passwor ...

JSF RichFaces dropdown menu for selecting locales with flag icons

After searching for a solution for quite some time, I have yet to find a suitable answer. I am currently working on a JSF web application using the RichFaces library. The application supports multiple locales, allowing users to change them by selecting fro ...

Interact with PHP by utilizing Jquery to update or remove data using the PUT

I'm running into an issue while trying to utilize Jquery.ajax() with PUT and DELETE methods. I am sending data with the request, but on the PHP side, when I print the request, it shows up empty. $.ajax({ url: 'ajax.php', type: 'DELETE& ...

Image element for Material UI CardMedia

There is a component in Material UI called CardMedia that allows for media content within a Card. The Mui website showcases an example using the img tag with CardMedia. https://mui.com/material-ui/react-card/#complex-interaction I am interested in using ...

Updating a database seamlessly via a dropdown menu without having to refresh the entire webpage

Before we proceed, please take a look at the following code: $(document).ready(function() { $("#alternatecolor [type=button]").each(function() { $(this).on('click', function() { btnObj = $(this); rowId = $(this).attr("rowId") ...

CSS: Achieving vertical centering without specifying a fixed height using line-height. Is it possible?

Using line-height to vertically center text within an inline-element is a technique I often employ. Here's a demo I created: body, section { width: 100%; } section { background-color: lightGrey; } #wrap { margin: 30px auto; width: 100%; ...

How to change the divider color in Angular Material table's header row

Currently struggling with customizing the divider appearance in the Angular Material table. Despite trying various approaches in the Chrome dev tools, I am unable to modify the color and thickness of the divider after the header row. It seems that the bord ...

Javascript/jQuery for enlarging and shrinking a div

Struggling with a function I'm implementing for a website. My goal is to move and expand a div upon button click, with the text on the button changing to "close". When the close button is clicked, the div should return to its original position. I&apo ...

Firing a jQuery Event Upon the Loading of a New Page in an iFrame

I am attempting to create a function on the parent element that will activate when an iframe changes its page (most likely due to a user clicking a link). Here is the HTML code: <iframe name="posts" id="posts" src="edit.php"> And here is the JavaS ...

Initiating a video by floating over a container

This code snippet allows me to trigger videos to play when hovered over individually: //play video on hover $(document).on('mouseover', 'video', function() { $(this).get(0).play(); }); //pause video on mouse leave $(document).on(&ap ...

Customized Bootstrap Dropdown with the ability to add text dynamically

I am working on a Bootstrap dropdown menu that allows users to generate expressions by clicking on the menu items. For example, when the "Action" item is clicked, it should insert {{Action}} into the textbox. The user can then type something like "Hello" a ...

What is the best approach for promoting reusability in Angular: creating a new CSS class or a new component?

I have a div with a set of CSS properties that are essential to my application. These properties will be reused across multiple pages and components. <div style="display: flex; flex-direction: column; height: 100%"> //inner html will vary based on c ...

Learn to move elements dynamically using jQuery's click function!

Looking to implement a tab section similar to the one shown in the example. Currently able to toggle tabs open, but unsure how to re-position the element upon second click to close the tab. Here is a link to an example of the desired tab functionality: can ...