Is there a way to implement HTML code that can automatically hide text based on the scroll size, similar to

Check out your Gmail inbox, where you'll notice 3 main columns

  1. Includes the sender's information
  2. Contains "THE_EMAIL_SUBJECT - THE_EMAIL_BODY"
  3. Showcases the date the email was sent on

I observed that when resizing the window in the Gmail web client, the text displayed in the second column automatically adjusts. It simply truncates the text to ensure that the sent on date appears to the right and the sender to the left. This feature is quite impressive, and I am interested in implementing it myself. Can anyone provide guidance on how to achieve this using HTML/CSS/JS?

Answer №1

Create a layout with the receiver fixed on the left side and the date hugging the right side of your window, all without using JavaScript!

<html>
<head>
    <title>SO</title>
    <style>
        #content
        {
            margin-right: 10px;
            width: 100%;
        }

        #receiver, #sender, #subject, #date
        {
            padding-right: 5px;
        }

        #receiver
        {
            width: 50px;
        }

        #sender
        {
            width: 50px;
        }

        #subject
        {
            width: 100%;
            overflow: hidden;
        }

        #date
        {
            width: 50px;
        }
    </style>
</head>
<body>
    <table id="content">
        <tr>
            <td>
                <div id="receiver">
                    Receiver
                </div>
            </td>
            <td>
                <div id="sender">
                    Sender
                </div>
            </td>
            <td id="subject">
                <div style="height: 20px;">
                    This is my long subject that hides itself when the window is too narrow.
                </div>
            </td>
            <td>
                <div id="date">
                    May 6
                </div>
            </td>
        </tr>
    </table>
</body>
</html>

You can adjust the width of the content as a percentage or to auto, and set margins as needed.

This design ensures that if the subject is too long, it will be hidden. Keep in mind the correct order should be sender, receiver, subject, emailContent, Date. However, you get the idea.

Answer №2

Check out this StackOverflow post that shares similarities with your question.

You can tackle your issue by implementing a table layout, specifying the width for the rightmost column (which contains the date), and allowing overflow for the other two columns.

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

css malfunctioning user interface

I'm struggling to figure out how to design a CSS toolbar. My goal is to create a 22x22 button toolbar with 4 buttons. I have this PNG image: and the following code: <style> #nav {background: url(content/images/crtoolbar.png) no-repeat;height: ...

What is the correct way to assign a property to a function's scope?

Lately, I've been delving into Typescript Decorators to address a specific issue in my application. Using a JS bridge to communicate TS code between Android and iOS, we currently define functions as follows: index.js import foo from './bar' ...

Google Map with rounded corners that have a transparent design

Trying to create a circular Google map using CSS3 border-radius, but having issues with browsers other than Firefox. Here's the code snippet: <div class="map mapCircle" style="position: relative; background-color: transparent; overflow: hidden;"&g ...

SyntaxError: Encountered an unexpected token that is not jsonp, could it be trying to parse json instead?

As a newcomer to AJAX and Javascript, I am attempting to integrate them with an API following this structure: http://localhost:8088/JobPositionForDd: { "data": [{ "_id": "529dc2dfd0bf07a41b000048", "name": "Junior Android" }, { ...

Update the text on a Button component using ReactJS

I am looking to update the text displayed on the Check All button to say Uncheck All after all the checkboxes have been checked. Below is my code. Any recommendations?” checkAllCheckBox = () => { let {todos} = this.state let newArray = [.. ...

Unique styles and scripts for a custom login portal

Just beginning with angularjs and diving into a project. Using ui.router for handling various views. Encountering an issue where I have a main page index.html, all my views load in <div ui-view=""></div>. But what if I want to incorporate a log ...

Separation between inline elements with a line break

I am faced with the challenge of placing the a tag on a new line while maintaining center alignment, without being able to modify the HTML. The display:block option extends the clickable area beyond the text. See the screenshot below for the desired outco ...

Guide to transforming View Model into JSON object in ASP.NET MVC

As a Java developer transitioning to .NET, I find myself delving into a .NET MVC2 project that requires a partial view for wrapping a widget. These JavaScript widgets come with JSON data objects that need to be populated by model data. Methods are then bou ...

What is the method for utilizing the onmouseover function to emphasize a specific part of an SVG graphic?

I am attempting to create an interactive SVG map of Europe. Each country is represented by a path element, and I want the opacity of a country to change to 0.5 when it is hovered over. Despite trying to define a JavaScript function for this purpose, noth ...

Navigate to the end of the chat window using AngularJS

Is there a way to automatically scroll to the bottom whenever a new message is received? I have code that moves the scrollbar, but it doesn't go all the way to the bottom. Can someone please help me with this? Here is my code on Plunker: http://plnk ...

Exploring the concept of String Enums through Reverse-Mapping

I was exploring the use of string enums in TypeScript and came across an issue with reversed mapping support. Here's what my enum looks like: enum Mode { Silent = "Silent", Normal = "Normal", Deleted = "Deleted" } I want to be able to pa ...

range input in firefox not functioning properly with focus method

One issue with using the input type range in HTML code is that when a focus event is triggered, it may not work properly in Firefox. Below is an example of the code: var p = document.getElementById("price"), res = document.getElementById("result"); t ...

Django's Models do not fetch data from the database directly

I have created a custom class in my models.py file to store information about articles that will be displayed on a website. from django.db import models from django.urls import reverse class Article(models.Model): """ A model representing an art ...

The drawbacks of using toJS() in React Redux: Is it really necessary in mapStateToProps()?

After reading through the Redux documentation, I came across a recommendation to not use Immutable with Redux. This advice has left me feeling confused. Why should I avoid using toJS() in the mapStateToProps function? It seems that React already uses Dee ...

What could be the reason for the `controller.$render` method not being triggered as intended?

Check out this code snippet on plnkr.co. Within the link function of the directive, calling controller.$render() was successful. However, when attempting to override the controller.$render function, it does not execute as expected. The statement console.lo ...

Use JavaScript to switch the h1 title when selecting an option from the dropdown menu

As a beginner in coding, I am struggling to find a solution using an if statement for this particular problem. Although I can achieve the desired result with HTML code and options, this time I need to use arrays and an if function. My goal is to create a ...

Using ReactJS to fetch data from a localhost PHP page

Currently, I am delving into the world of PHP and its integration with ReactJS. A peculiar issue has crossed my path, one that puzzles me as a solution seems out of reach. Displayed below is a simple form: class App extends React.Component { state ...

Leveraging Angular's capability to import files directly from the assets

I recently installed a library via npm and made some modifications to one of the modules. python.js If I delete the node_modules folder and run npm install, I am concerned that I will lose my changes. Is there a way to preserve these modifications by mov ...

What is the best way to add a trigonometric shape to a web page?

Currently, I am undertaking a project that requires the insertion of a large number of trigonometrical shapes into a webpage. To provide some context, I am working on the conversion of an ancient book into HTML format. The challenge lies in the fact that c ...

Exploring the world of HighCharts

I am trying to use Highcharts to calculate and visualize the magnitude of a complex number. Currently, my code is displaying the real and imaginary values separately on the graph. However, I seem to be facing issues with the "For loop" that I implemented ...