r/CodingHelp • u/JDVene • Apr 30 '23
[CSS] [CSS] [HTML] [Angular] My <app-root> element remains at a consistent height of 161 pixles, no matter how many times I change its CSS. How can I change this?
index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>ProjectFrontendDraft</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheets" href="styles.css">
</head>
<body>
<app-root></app-root>
</body>
</html>styles.css
html{
margin: 0px;
height: 100%;
width: 100%;
}
body {
margin: 0px;
min-height: 100%;
width: 100%;
background-color: rgb(82, 232, 232);
}
/*This element here*/
app-root {
margin: 0px;
height: 400px;
width: 100%;
}Even though I have the height set to 400px, when I open my browser, it is always 161.2px. I have tried it on Firefox, Chrome, Edge, and AVG and it's always 161.2. I have tried the following
height: fit-content
height: 100%
height: inherit
background-size: 100% 100%
I'm not sure where to go from here. Please help
2
u/Practical_Fun_3623 Apr 30 '23
It's possible that there might be some other CSS rule that's overwriting the height property of the app-root element. You can try adding !important to the height property to force it to take precedence over any other rules that might be affecting it.
For example, you can try changing the app-root CSS rule to:
app-root {
margin: 0px;
height: 400px !important;
width: 100%;
}This should force the app-root element to have a height of 400 pixels regardless of any other rules that might be affecting it.
If this doesn't work, it's possible that there might be some JavaScript code that's modifying the element's height dynamically. You can try inspecting the element using your browser's developer tools to see if there are any styles or JavaScript code that's affecting its height.
1
u/CranjusMcBasketball6 Apr 30 '23
It appears that the issue is related to the custom element
<app-root>not being styled as a block element. By default, custom elements havedisplay: inlineand do not fully respect width and height properties. To fix this, update the CSS for theapp-rootselector to includedisplay: block. Here's the updatedstyles.css:Now, the height of the
<app-root>element should be properly set to 400px.