InterviewSolution
| 1. |
What will be the output of the following code having 4 divs having unique color and text and enclosed by single layout container class? |
|
Answer» /* Answer */ #outer { width: 300px; height: 300px; background-color: BLACK; position: relative; } #inner { width: 100px; height: 100px; background-color: red; position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); } OUTPUT: We have a relative position to the outer div tag and absolute position for the inner div tag. In ORDER to PLACE the inner div in the middle. We used the top and left at 50%. Using top and left the box position starts from the middle of the top and left which not exactly in the center. So, in order to keep the inner div exactly at the center, we need to use transform, which helps US to place the inner div exactly at the center of the outer div. |
|