Home  >  Article  >  Web Front-end  >  How to solve the problem of float:right right-aligned elements in CSS that wrap and are not on the same line

How to solve the problem of float:right right-aligned elements in CSS that wrap and are not on the same line

不言
不言Original
2018-06-21 17:35:233103browse

This article mainly introduces how to solve the problem that float:right right-aligned elements in CSS will wrap and are not on the same line. It has a certain reference value. Now I share it with you. Friends in need can refer to it

When using float to set right-aligned display, we usually encounter that the right-aligned elements will wrap, so that the left and right elements are not on the same line. Here are two solutions for you to solve similar situations. Friends can refer to

In CSS, usually we need to display an element on the left or right. At this time, we can set it according to float. When setting the right-aligned display, we usually encounter, right-aligned The elements will wrap, so the left and right elements will not be on the same line. We can solve this problem in the following ways:

The first solution: Swap the left and right elements, For example, just put the date in front of the title and reverse it.

The second solution: Add float:left to the left side as well.

CSS float definition and usage

The float attribute defines in which direction the element floats. Historically this property has always been applied to images, causing the text to wrap around the image, but in CSS, any element can be floated. A floated element creates a block-level box, regardless of what type of element it is.

If you float non-replaced elements, specify an explicit width; otherwise, they will be as narrow as possible.

Float is often followed by the attribute values ​​left, right, and none
Float: none Do not use floating
Float:left Float to the left
Float:right Float to the right

The above is the entire content of this article. I hope it will be helpful to everyone's learning. Please pay attention to more related content. PHP Chinese website!

Related recommendations:

How to use the css attribute nth-child(n) to match and select the nth child element

How to Solve the problem that when Firefox uses offsetHeight to obtain the height of a div, it is 0

The above is the detailed content of How to solve the problem of float:right right-aligned elements in CSS that wrap and are not on the same line. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn