Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problem that margin-right has no effect in css

Shulou Source: shulou.com Published: 2022-06-03 08:14:23 09月13日 Update

This article mainly explains "how to solve the problem that margin-right has no effect in css". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to solve the problem that margin-right has no effect in css".

The CSS code and HTML code are as follows:

.style1 {

Width:400px

Height:440px

Background-color:red

Border:5px solid silver

Margin-top:20%

Margin-right:30%

}

The code is as follows:

Copy his code and change it to another picture. I made a test, which really didn't work.

Is it possible that top will hide the effect of right? Or is it about the order? These ideas turned out to be wrong. Combined with w3school's faint memory of margin-right and himself: browsers are left-aligned by default. When inspired, margin-right actually works, but it doesn't work by default, that is, the standard stream. What if you deviate from the standard stream? With this in mind, I immediately added one to the css file: float:right;, and then you can see the effect of margin-right during the test.

It is not possible to use float:left, which is similar to the default.

PS: about the reason why the right attribute is invalid: the right attribute is valid only if the position is absolute, while the default position value is the static,right attribute. It is recommended that you do not use the right attribute without using right.

Thank you for reading, the above is the content of "how to solve the problem of no effect of margin-right in css". After the study of this article, I believe you have a deeper understanding of how to solve the problem of no effect of margin-right in css, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Effect problem code attribute situation learning no content standard effective almost for one reason just only pictures that is suggestions ideas ideas Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Redmi Xiaomi Shulou Tech Info Apple