Skip to content

Instantly share code, notes, and snippets.

@sotnikov-link
Created December 18, 2019 09:58
Show Gist options
  • Save sotnikov-link/28303944d9cf23b6d433d5ab392669f0 to your computer and use it in GitHub Desktop.
Save sotnikov-link/28303944d9cf23b6d433d5ab392669f0 to your computer and use it in GitHub Desktop.
Child inside parent with `min-height: 100%`

Child inside parent with min-height: 100%

Solution

Screencast

YouTube

Source. TypeScript React

import { memo } from 'react';
import styled, { createGlobalStyle } from 'styled-components';

export default memo(() => (
  <>
    <GlobalStyle />

    <Container>
      <Flex>
        <Content>{content}</Content>
      </Flex>
    </Container>
  </>
));

const content = 'start ' + 'hello '.repeat(500) + 'end';

const GlobalStyle = createGlobalStyle`
  body {
    font-family: Arial, Helvetica, sans-serif;
    margin: 0;
  }
`;

const Container = styled.div`
  height: 100vh;
  overflow: auto;
  background: url('/static/sites/oblika.ru/background.jpg');
  background-size: cover;
`;

const Flex = styled.div`
  display: flex;
  align-items: center;
  min-height: 100%;
  background: #00ff008a;
`;

const Content = styled.div`
  background: lightcoral;
  margin: 5em;
  border: 2em blanchedalmond solid;
  padding: 1em;
`;

Related links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment