When you are writing CSS, you must have forgotten the critical situations in the design. For example, when the length of the content exceeds our expectations and we cannot explain the possibility, the page design is likely to collapse. We can't guarantee that CSS will always work as we expect, but at least we can test it with different types of content to reduce the chance of this happening.
The specific situation is as follows:
A button with a small icon on the right/left side
This is a switch button with an accordion effect. There is a small icon to the right of the button to emphasize that it is clickable. However, when the button area is not long enough, the text on the button will cover the icon. This can happen when we don't take longer content into account.
We can add enough padding value on the right side to adapt to the size of the icon
.button { padding-right: 50px; }
Notice how we increased the padding value to create a safe display area for the icon, now we can Make sure button layout is no longer broken.
(Related tutorial recommendation: CSS tutorial)
Enter placeholder
When using floating annotations in our forum mode, especially when the button is on the right side, we need sufficient testing to avoid problems caused by too long placeholders.
One solution is to add position: relative to the button, which will make the button cover the placeholder.
Long name
In this design, the image floats to the left, and there is information about the author's name on the right. What happens when the length of the information on the right is too long? There is no doubt that the layout will fall apart.
The problem here is that we only floated the image to the left, causing the author's name to move next to it, but this will only perform well if the author's name is shorter in length.
In order to make the page layout more adaptable, we need to increase the width of both elements. The more recommended way is to use flexbox, which is more suitable for such small components.
There are long links/words in the article
Sometimes the article contains some very long hyperlinks or words, which may not appear when the window is very wide causing problems. But on some smaller devices, such as phones or tablets, this can create annoying horizontal scroll bars.
We have two solutions to this problem:
(1) Using CSS word-break
.article-body p { word-break: break-all; }
word-break property does not perform well in different browsers The same, so it needs to be fully tested when using it.
(2) Add overflow and text-overflow to the outer element
.article-body p { overflow: hidden; text-overflow: ellipsis; }
This solution is more friendly for long links. For long words, I recommend using word-break.
Too long article tag
When we place an article tag on the card, we'd better determine its size only by setting its padding. When the content of the label is too long, programming the height and width may cause the layout to collapse.
You can also set a minimum width for the label. When the min-width attribute is used for the label content element wrapped in padding, the width changes dynamically and the problem is solved.
Paragraph header with fixed link
This example has a ‘view more’ link to the right of the paragraph title. There are a few different ways to write CSS, one of which is to use absolute positioning for links.
When the title is too long, it may cause some problems. A better solution is to use flexbox layout, so that when there is not enough space, the link will be automatically squeezed into the next line.
.header-2 { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; }
The above technique is called 'Alignment Move Package'.
Recommended video tutorial: css video tutorial
The above is the detailed content of How to solve the problem of too long content in css. For more information, please follow other related articles on the PHP Chinese website!

In this week's roundup: Firefox gains locksmith-like powers, Samsung's Galaxy Store starts supporting Progressive Web Apps, CSS Subgrid is shipping in Firefox

In this week's roundup: Internet Explorer finds its way into Edge, Google Search Console touts a new speed report, and Firefox gives Facebook's notification

You’re probably already at least a little familiar with CSS variables. If not, here’s a two-second overview: they are really called custom properties, you set

Building websites is programming. Writing HTML and CSS is programming. I am a programmer, and if you're here, reading CSS-Tricks, chances are you're a

Here's what I'd like you to know upfront: this is a hard problem. If you've landed here because you're hoping to be pointed at a tool you can run that tells

Picture-in-Picture made its first appearance on the web in the Safari browser with the release of macOS Sierra in 2016. It made it possible for a user to pop

Gatsby does a great job processing and handling images. For example, it helps you save time with image optimization because you don’t have to manually

I learned something about percentage-based (%) padding today that I had totally wrong in my head! I always thought that percentage padding was based on the


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

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

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool