When we write CSS styles, when two boxes are nested together, the top of the inside box is placed on the top of the outside box, as shown in the figure below:
At this time, if the properties like margin-top are set for the inner box, there will be no space between the top of the inner box and the outer box, but the outer box is pushed down, as if margin-top property is set for the outer box.
set margin-top property for the inner box, as shown in the figure below:
<style>
* {
margin: 0;
padding: 0;
}
.wrap {
width: 200px;
height: 200px;
background-color: red;
}
.wrap .box {
width: 100px;
height: 100px;
background-color: blue;
margin-top: 50px;
}
</style>
<body>
<div class="wrap">
<div class="box"></div>
</div>
</body>
so the simplest way is to add a property to the outer box :
overflow: hidden;
The results are as follows:
Read More:
- CSS: several ways to center the box vertically and horizontally
- CSS remove the blue box after button click
- How to center the box horizontally and vertically in HTML
- Three methods of how to remove the flashback of running result box in VS
- The problem of black box flash away in vs2019 debugging
- Error debug in box2d createfixture Error:R6025 pure Virtual function call solution
- Three solutions to flash back of program running result box under vs
- The solution to frequently pop up “cannot find a valid baseurl for repo” error prompt box in CentOS 6.7
- Error box (2)
- Vacuum box installation CentOS encountered the pit
- Vboxnetadp6.sys file required for virtual box error
- Eclipse software Java solution: editor does not contain a main type error box
- Vant weapp uses the dialog pop-up box to prompt for path error
- Ubutnu’s idea input method candidate box can’t follow the cursor
- Vue element UI uses this. $notify is not a function problem resolution using the notification box
- JS prompt cannot read property ‘style’ of undefined
- Property ‘style’ does not exist on type ‘element‘
- Box mount Cody_ How to listen to Pandora in Cody
- Latex sets page margin, page size, page margin and geometry macro package
- When installing / uninstalling SQL, a black box of command prompt will pop up, and then it will flash without response