Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report