Reputation: 23
I am attempting to create a simple webpage using React. I want to have a fixed navbar at the top of the screen and then content below it. My general structure is one in which there is a single div in the body, which is where the React application is "injected". The application itself consists of a top-level "app" div, and various child components.
<html>
<head>
<title>Sample App</title>
</head>
<body>
<div id="react">
</div>
</body>
<script src="/build/bundle.js"></script>
</html>
The issue Im having is that the div with the id 'react' is not filling the entire body of the html page. Therefore any content I have inside of my application div overflows outside of the 'react' div.
This code pen illustrates my problem: http://codepen.io/anon/pen/xGNejM
You can see at the bottom of the page that the lime background applied to the html tag is bleeding through. It is as if the body tag is not filling the whole screen. I thought setting height to 100% on html and body would handle this, but apparently not.
Upvotes: 2
Views: 3471
Reputation: 43880
Try an implicit measurement on the body:
body { height: 100vh; width: 100vw; }
vh
and vw
viewport height
and viewport width
are like ems
on steroids.
UPDATE
http://arcx.s3.amazonaws.com/test.html
So according to what I've gathered, you need the content to be displayed from the #react > #app
and the #react > #app
itself must expand according to it's content #child
. I did a couple of things:
position: relative
height: 100%
with height: 100vh
html,body
and added position: fixed
footer#foot
at the bottom with position:relative
so there's padding at the bottom to prevent the content #child
from being cutoff from the display.overflow: scroll
(I chose scroll
over auto
I don't like jumping scrollbars) to the #child
but I didn't need to apply overflow: hidden
to anything since I made the other components "static".The content is editable, so type and hit enter key 100,000 times and it'll still expand without cutoffs or text jumping over borders. When you inject content inside, you might need a <br
> or \n
at the end for good measure.
Upvotes: 0