html - How to prevent child div moving when adding text to parent? -


i have basic html showing safe zones used in broadcast. however, when add text divs have set up, throws alignment out of place.

code:

<!doctype html> <html>     <head>     <title></title>     <link rel="stylesheet" type="text/css" href="browserclock.css"> </head> <body>     <div id="safeaction">safe action area         <div id="safetext">safe text area         </div>     </div> </body> </html>  html {     width: 1920px;     height: 1080px;     margin: 0;     padding: 0;     background-color: black; } body {     margin: 0;     width: 100%;     height: 100%;     background-position: 0 0; } #safeaction {     width: 1786px;     height: 1003px;     margin: 37px 66px 37px 66px;     border: 1px dashed white; } #safetext {     width: 1728px;     height: 971px;     margin: 16px 28px 16px 28px;     border: 1px dotted white; } 

without text, lines per ebu standard pixel spacing. text not.

this happening because inner div id safetext positioned relative other contents of div in. fix this, set position of safetext absolute , use top set the distance top of inner div top of outer div (in case 16px) instead of top-margin. finally, give body relative positioning determined parent.

jsfiddle

body {     margin: 0;     width: 100%;     height: 100%;     background-position: 0 0;     position: relative; } #safeaction {     width: 1786px;     height: 1003px;     margin: 37px 66px 37px 66px;     border: 1px dashed white; } #safetext {     width: 1728px;     height: 971px;     margin: 0px 28px 16px 28px;     border: 1px dotted white;     top: 16px;     position: absolute; } 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -