css top does not work because the value of the "position" attribute is "static", so setting the "top" attribute will not have any effect. The solution is to ensure that the value of the position attribute is absolute or relative. That’s it.
The operating environment of this article: Windows7 system, HTML5&&CSS3 version, Dell G3 computer.
Solution to the ineffective top attribute in CSS:
In CSS positioning, sometimes when using the top attribute for offset, it is found that the top attribute does not work. Why is this? How to deal with it? The following article will introduce it to you, I hope it will be helpful to you.
First let’s learn about some top attributes:
The top attribute in css specifies the top edge of the element. This property defines the offset between the top margin boundary of a positioned element and the top boundary of its containing block.
Why does the top attribute not work? How to solve it?
The top attribute refers to the distance to the left or top of the nearest parent element whose position attribute is relative or absolute, so when the value of the "position" attribute is "static", then set "top" properties will have no effect.
Solution to the problem that the top attribute does not work: Make sure the value of the position attribute is absolute or relative.
【Recommended learning:css video tutorial】
The above is the detailed content of What to do if css top doesn't work. For more information, please follow other related articles on the PHP Chinese website!