Hide the text if there is not enough space to show it fully

Currently working on a website where quotes are featured within a specific section. I am seeking a solution for ensuring that if the text cannot be fully displayed within the div (leading to words being cut off), the entire div becomes invisible. I would prefer not to utilize methods such as overflow: scroll;. Any suggestions on how this issue can be resolved? :)

Answer №1

ScrollWidth refers to the width of elements that have content which is not currently visible.

On the other hand, offsetWidth specifically pertains to the width of visible content only.


If there is a variation between the scrollWidth and offsetWidth, it indicates overflow!

if (divQuote.scrollWidth > divQuote.offsetWidth) {
      // Add display none to divQuote using CSS
      // or implement your own logic for handling overflowing content
}

Additional resources:
scrollWidth: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollWidth
offsetWidth: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetWidth

https://i.sstatic.net/2DNF9.png

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 background image is not visible

.imagem-cortada { width: 100%; background-image: url("imagens/Vector 9.png"); } The HTML: <section class="imagem-cortada conteudo-principal"><!--inicio sobre nos--> <div class="container"> ...

What is the best way to align two paragraphs horizontally next to each other?

My issue involves two div containers wrapped by a parent div. Inside each child div is a paragraph with a header. When I attempt to align these paragraphs (including the headers) next to each other in the same row, they do not stay together. Instead, they ...

Utilize the Static Path in Django with Template Filters

To easily version my css file using a simple template variable, I update the version in my settings and it automatically applies to all files. Here's how I accomplish this: Template Filter @register.filter def settings_value(name): return getatt ...

Ways to control image width without distorting the image dimensions

Can anyone help me with writing an img tag for images of varying sizes? I'm looking to scale down larger images to fit the container at width: 100%, but I do not want smaller images to be scaled up. I want them to maintain their natural size when view ...

Adjust the transparency of a distant div element by using CSS checkboxes without any JavaScript

I'm faced with the challenge of manipulating the opacity or animating an array of items that are all contained within a single div. In addition to altering the opacity of each individual item, I also want to change the opacity of the entire div and it ...

Looking to incorporate three additional fields by clicking on the "add more" button

I am currently working on a PHP and Bootstrap script designed to collect website addresses. Initially, there is a single field that gathers website names linked to "address1" in the MySQL database. I have expanded the database to include two additional fie ...

Top-notch loading icon using jquery

Recently, I embarked on the journey of learning Javascript and jQuery simultaneously, and to my surprise, it feels quite manageable. As I delve deeper into creating functions, I am currently working on displaying a loading image. While I initially used on ...

Dynamic JavaScript animation to retrieve the position of an element on-the-fly

I am currently exploring the world of animation in JavaScript and I have a few practical questions. In my script, I am attempting to "launch" a "rocket" upon clicking a "button". What I've observed is that although my function calculates values as int ...

Default Link Color Being Utilized by Blog Title

My website was created using a theme (HTML, CSS, JavaScript), but the Blog Title is stuck with the default link color. I've attempted several methods to change the Title color without success. What's the solution for changing the Title color? ...

Utilize Bootstrap 4 classes on multiple td elements within a table

Is there a way to efficiently apply multiple Twitter Bootstrap 4.5 classes to various td tags without repetition or using jQuery? I am looking to streamline the code in order to reduce the amount of data within the HTML document. For example, if there are ...

The issue at hand is that one of the JavaScript buttons is functioning properly, while the other is not playing the video as intended. What steps can

I've been working on a script for my school project website that should make buttons play videos, but I'm running into an issue where it only works for the first button (btn). Programming isn't my strong suit, and I put this together based o ...

The div father's width is not fully occupied by col-xl-12

Can you explain why inew2 and inew3 do not have a width of 100% of their parent div? https://i.sstatic.net/a4GEa.jpg html, body{ width: 100%; height: 100%; margin: 0px; padding: 0px; } .ibrands{ height: 120px; background-color: blue; } @media only scre ...

Scrolling to the next wrap class in jQuery is not functioning properly with the chatbox and ScrollTop

I have created a chat box using jQuery. However, I am facing an issue where when I click the button multiple times, the scroll returns to the top. My objective is for the scroll to move to the next wrap class when the button is clicked. Here is a snippet ...

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 ...

Creating a border with a unique and specific image

Is there a way to use an image as the border for my div elements? The key requirement is that the border must be positioned outside the box without affecting its size. It's important to note that all div items have the same width, but varying heights ...

Using CSS to style HTML elements with spaces

Apologies if this question can easily be answered with a Google search, but I am having trouble finding the right keywords to use. While I have a decent grasp of CSS, I feel like there is still much more potential to explore and improve my code efficiency. ...

How do I alter the color of a Vue 3 font awesome icon?

I am currently using Vue version 3.2.1 and have followed the official Font Awesome documentation for Vue 3 found at https://github.com/FortAwesome/vue-fontawesome. I also referenced a helpful video tutorial: https://www.youtube.com/watch?v=MoDIpTuRWfM Des ...

Tips for inserting a line break in a script

Hello, I need some assistance with creating a typewriter effect using JS, CSS, and HTML. Everything seems to be working fine except when I try to add a new line of text, it doesn't display properly. var str = "<p>I want to put text here then ...

How come the dark grey in CSS appears to be lighter than the standard grey hue?

JSBIN DEMO Could this be a mistake or is it a bug? Shouldn't the dark gray shade be darker than the default grey one? HTML <div class="lightgrey">Light Grey</div> <div class="grey">Grey</div> <div class="darkgrey">Dar ...

What is the best way to position the <h:panelGrid> itself at a location other than the center?

Whenever I utilize this code snippet <h:panelGrid id="myGrid" columns="1" rendered="#{myBean.showResults}" width="50%" border="1" style="text-align: center;"> The panelGrid items will be centered HOWEVER, I desire to center the h:panelGrid it ...