


How to solve the problem of unnecessary background color when single line of text with background color overflows ellipsis?
Solution to the overflow of ellipsis in a single line of text, causing redundant background color
In CSS, when using text-overflow: ellipsis
to deal with single-line text overflow, if the text has a background color, the background color residue of the last character will often occur. This is because text-overflow: ellipsis
acts on the elements within the line, while the background color is applied to the text element itself, resulting in the background color being visible after truncation.
The following figure shows an example of the problem:
Here are the CSS and HTML codes for the problem:
.oneline { width: 640rpx; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text { background-color: #999999; padding: 4rpx 8rpx; margin-right: 12rpx; } }
<view class="oneline"><text wx:for="{{flavorsarr}}" wx:key="index"> {{item.label}}</text></view>
The solution is to modify the display method of text
element to inline-block
. inline-block
element can be processed as a whole block, avoiding the background color residue problem caused by simple in-line element truncation.
The modified CSS code is as follows:
.oneline { width: 640rpx; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text { display: inline-block; /* is modified to inline-block */ background-color: #999999; padding: 4rpx 8rpx; margin-right: 12rpx; } }
By setting text
element to inline-block
, text truncation will be based on the entire element, effectively avoiding the appearance of unnecessary background colors and ensuring better visual effect of text overflowing ellipsis.
The above is the detailed content of How to solve the problem of unnecessary background color when single line of text with background color overflows ellipsis?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Troubleshooting and solutions to the company's security software that causes some applications to not function properly. Many companies will deploy security software in order to ensure internal network security. ...

When developing websites using CraftCMS, you often encounter resource file caching problems, especially when you frequently update CSS and JavaScript files, old versions of files may still be cached by the browser, causing users to not see the latest changes in time. This problem not only affects the user experience, but also increases the difficulty of development and debugging. Recently, I encountered similar troubles in my project, and after some exploration, I found the plugin wiejeben/craft-laravel-mix, which perfectly solved my caching problem.

HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

Laravel 8 provides the following options for performance optimization: Cache configuration: Use Redis to cache drivers, cache facades, cache views, and page snippets. Database optimization: establish indexing, use query scope, and use Eloquent relationships. JavaScript and CSS optimization: Use version control, merge and shrink assets, use CDN. Code optimization: Use Composer installation package, use Laravel helper functions, and follow PSR standards. Monitoring and analysis: Use Laravel Scout, use Telescope, monitor application metrics.

In SpringBoot, use Redis to cache OAuth2Authorization object. In SpringBoot application, use SpringSecurityOAuth2AuthorizationServer...

Importing WordPress source code requires the following steps: Create a sub-theme for theme modification. Import the source code and overwrite the files in the sub-topic. Activate the sub-theme to make it effective. Test the changes to make sure everything works.

In IntelliJ...

When developing a new content management system (CMS), I encountered a common but difficult problem: how to quickly build a fully functional CMS without adding too much complexity. There are many ready-made CMS solutions available on the market, but they are often too large and complex to configure and can be a burden for small projects. After some exploration, I discovered the lebenlabs/simplecms library, which provides a simple and efficient solution through Composer.
