Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parts of div border being cut off

I have a container element that is holding a few other elements, but depending on the screen size parts of them are inexplicably cut off at various portions. You can observe the behaviour on my code sandbox link, when the HTML page is adjusted in width (by clicking and dragging it). How can I ensure that only the main container border is rendered, and that the child elements do not have any impact?

border

https://codesandbox.io/s/focused-tree-ms4f2

import React from "react";
import styled from "styled-components";

const StyledTextBox = styled.div`
  height: 15vh;
  width: 30vw;
  display: flex;
  flex-direction: column;
  margin: 0 auto;
  border: 1px solid black;
  background-color: #fff;
  > * {
    box-sizing: border-box;
  }
`;

const InputBox = styled.span`
  height: 35%;
  width: 100%;
  display: flex;
  border: none;
  outline: none;
`;



const UserInput = styled.input`
  height: 100%;
  width: 90%;
  border: none;
  outline: none;
`;

const SolutionBox = styled.div`
  height: 35%;
  width: 100%;
  border: none;
  outline: none;
`;

const StyledKeyboard = styled.span`
    height: 30%;
    width: 100%;
    position: relative;
    background-color: #DCDCDC;
    box-sizing: border-box;
    display: flex;
`

export default function App() {
  return (
    <StyledTextBox>
      <InputBox>
        <UserInput />
      </InputBox>
      <SolutionBox/>
      <StyledKeyboard/>
    </StyledTextBox>
  );
}
like image 262
Perplexityy Avatar asked Mar 23 '20 12:03

Perplexityy


People also ask

How do I remove part of a border in CSS?

We can specify the no border property using CSS border: none, border-width : 0, border : 0 properties. Approach 1: We will give border-color, border-style properties to both headings, for showing text with border and no-border. For no border heading, we will use the border-width : 0 which will result in no border.

What CSS property goes outside of a border?

The outline CSS shorthand property allows drawing a line around the element, outside the border. It is used to set all the properties of the outline in a single declaration.

Is padding inside the border?

Padding is used to create space around an element's content, inside of any defined borders.

Is Border part of element width?

Here, the dimensions of the element are calculated as: width = width of the content, and height = height of the content. (Borders and padding are not included in the calculation.)


1 Answers

Like the other commenters, I can quite make out the error you are reporting, but it sounded to me like a box-sizing issue. When reviewing the rendered DOM via https://k7ywy.codesandbox.io/ we can see box-sizing:border-box is not being applied to the wrapper element or the internal elements, but it is fixed in the snippet you pasted in the question.

I noticed a few things I'd question.

  1. Why not apply box-sizing to everything? Usually when dealing with width:100%; and padding/border/margin, it makes life so much easier!
    In my example I removed it from the JS and applied it using the CSS file.

  2. Why are you using display:flex in multiple places but not assinging any other flex-related properties?
    Try removing that from const InputBox = styled.span and const StyledKeyboard = styled.span

Does that fix it for you? Sandbox example. Rendered output.

like image 161
Jason Lydon Avatar answered Sep 23 '22 18:09

Jason Lydon