Fading text that gradually vanishes depending on the viewport width... with ellipses!

I currently have a two-item unordered list positioned absolutely to the top right of the viewport.

<header id="top-bar">
    <ul>
        <li>
            <a href="#">David Bowie</a>
        </li>
        <li>
            <a href="../includes/sign_out.php" class="signUp"     name="signUp">Sign Out</a>
        </li>
    </ul>

#top-bar {
    height:47px;
    background-color:rgb(43, 165, 43);
    border-bottom:3px solid rgb(22, 83, 22);
    font-size:0.75em;
    position:relative;
    z-index:1;
}
#top-bar ul {
    margin:0; padding:0 0.25em;
    position:absolute;
    right:0px;
}
#top-bar ul > li {
    display:inline;
    float:left;
    line-height:47px;
    position: relative;
    z-index:2;
}
#top-bar ul > li:first-child{
    margin-left:0.45em;
    background:orange; 
}

The content of the last child li remains constant. However, the first child li's content is dynamic.

When the viewport width is full, the changing content doesn't matter much. But, when the viewport size decreases, particularly on mobile screens, the text should start to hide BEHIND the enclosing div, and be replaced by (...) instead. Once a certain width is reached, the li container's size will become fixed and the hiding will cease.

I'm uncertain about how to achieve this. Can it be accomplished using only CSS? I believe Javascript might need to be used to swap out the content for ellipses.

Unfortunately, I lack extensive programming knowledge, especially in Javascript, and I am pressed for time to address this issue.

If any seasoned programmers have a solution for this, I would greatly appreciate your input.

Thank you.

Answer №1

To implement an ellipsis for truncated text, you can utilize CSS3 properties like text-overflow.

<style>
ul{
    background: #aaa;
    font: 12px sans-serif;
    padding: 10px;
}
li{
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
</style>

<ul>
    <li>
       Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
       tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
       quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
       consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
       cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
       proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    </li>
</ul>

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

When utilizing styled-jsx alongside postcss, experiencing issues with styles failing to reload or rebuild

I'm currently using postcss in conjunction with styled-jsx. In my setup, I have multiple CSS files that I'm importing using the @import directive within the _app.js file. Everything seems to work smoothly, except when I modify any of the CSS file ...

Text in Angular vanishes upon reopening

I have a code snippet where I am trying to allow the user to edit and save a paragraph displayed on a side panel of the main page. Although the code works fine, allowing users to update the text and see it reflected in the network upon saving, there seems ...

How can I access a PHP variable from an external .php file within a JavaScript script?

I have recently implemented a JavaScript code called "upload.js" for uploading files to my server: function beginUpload(){ document.getElementById('upload_form').style.visibility = 'hidden'; return true; } function endUpload(s ...

Struggling to retrieve user input from a textfield using React framework

I'm having trouble retrieving input from a text-field in react and I can't figure out why. I've tried several solutions but none of them seem to be working. I even attempted to follow the instructions on https://reactjs.org/docs/refs-and-th ...

Achieving compatibility with IE7 for utilizing "before:" and "after:" pseudo-elements along with the "box-sizing:border

My website is constructed with twitter bootstrap 3 and functions perfectly on all browsers except for IE7. IE7 seems unable to interpret pseudo classes like before:, after:, and box-sizing: border-box. Is there a solution to make IE7 understand this code ...

Make the Angular Modal scrollable except for when a specific div is being click dragged

I am working on an Ionic app that uses AngularJS. One issue I encountered is with a modal popup that can sometimes extend beyond the visible area. To address this, we applied overflow: hidden to its CSS class. However, there is a specific functionality i ...

Encountering Issue: Exceeding the number of hooks rendered in the previous render cycle

Every time I load my Nextjs page, an error message displays: "Error: Rendered more hooks than during the previous render." I attempted to fix this by adding if (!router.isReady) return null after the useEffect code. However, this caused a problem where th ...

I am facing difficulties with deploying my Next.js App on Vercel. Whenever I try to deploy, I encounter an error stating that the Command "npm run build" exited with 1

Hey there! I'm currently following a tutorial by JavaScript Mastery on Next.js (big shoutout to you, sir). I've been trying to deploy it on Vercel, but running into some deployment issues and having trouble testing out different tutorials. Here&a ...

Assist me in temporarily altering the color of menu items in a sequential manner upon the page's loading

Currently, I'm working on a website that features a subtle dark grey menu at the top of every page. The menu is built using HTML and CSS with a list structure. To highlight the corresponding menu item based on the current page, I am utilizing the ID a ...

Display the toggle button for expanding/collapsing text only when the length of the string exceeds 50 characters

Is there a way to only show a "read more/less" button in a table if the content exceeds 50 characters? The table contains a mix of content, some short announcements with about 10 characters and others with over 100. <div class="col"> <span ng-c ...

Transform Promise-based code to use async/await

I'm attempting to rephrase this code using the async \ await syntax: public loadData(id: string): void { this.loadDataAsync() .then((data: any): void => { // Perform actions with data }) .catch((ex): v ...

Retrieving radio button values in React from a different component

I am dealing with a child component that contains radio buttons, each with its own value. I have imported this child component into a parent component to manage its state from the parent component. With the child component added, I need to access all the i ...

AngularJS controller exceeding allowed complexity (SonarLint alert)

While utilizing SonarLint in Eclipse, I encountered an issue while working on an AngularJS application. Specifically, I was cleaning up a controller to improve readability when SonarLint flagged the following problem: The function has a complexity of 11 ...

Processing information received through an ajax.post request

I want to establish a connection with a Node.js server on localhost using ajax to send data. For testing purposes, I attempted to send text input to the server and log it there. Here is my Post-Function that triggers upon button click: function sendDat ...

"Adjusting the size of a jQuery dialog for optimal viewing on

I am currently working on designing an HTML page that is responsive for both mobile and desktop browsers. One issue I am encountering involves a jQuery dialog that I need to scale properly to fit the page. I believe the problem lies within these lines of ...

Executing jQuery script on dynamically loaded content

My website utilizes AJAX requests to load pages dynamically. One specific page includes a marquee script that I would like to implement. Unfortunately, due to the dynamic loading of the page, the marquee script is not functioning as expected. I have come ...

Targeting the landscape mode on screens of both iPhone 4 and iPhone 5 sizes using CSS3 Media Queries

I'm facing a problem with CSS3 media queries while developing a mobile site. The code I've written works perfectly on the landscape mode of an iPhone 5, but it's not quite right on an iPhone 4 or earlier in landscape mode. /* Default stylin ...

The information overflow occurs outside the tooltip specifically in Chrome, while functioning perfectly in IE11

As a newcomer to the CSS world, I am experimenting with adding a block-level element (div) inside an anchor tag's :hover pseudo-class popup. The div element contains a table that needs to have dynamic sizing for both the table itself and its cells (wi ...

Pattern matching: Identify text elements specifically within an HTML tag

I've been experimenting with a text highlighting script. Check out my initial attempt here. Here's the code snippet: http://jsfiddle.net/TPg9p/3/ However, I encountered a problem – it only works with simple strings and not those containing HT ...

AJAX seems to be struggling to recognize JSON data as JSON format

I am facing an issue with my AJAX call where the data received from the server is not being treated as JSON, despite setting the datatype to json: function RetrieveMateriasFromServer(callback){ var status_aux; //HTTP request for data from the given UR ...