Body that don't take the entire avaible space in an Electron app

Viewed 1078

I have an Electron app with personalized title bar (close and minimize button). When I show the border of all HTML elements in my window, I noticed that my body and my HTML tag don't take the entire window and I need that because I need to put border to my window. I don't know what is the problem, Thanks for your help.

I tried to put height: 100%; in CSS for HTML and body tag but that doesn't work. I also tried with margin: auto; but that doesn't work either.

Here is the screenshot of the app, first with height:100% (with a scrollbar and I don't want it) and second without.

First

Second


The CSS:

*/*, *::after, *::before*/ {
  /* ~~~~~~ Disable elements dragging ~~~~~~ */
  -webkit-user-select: none;
  -webkit-user-drag: none;
  -webkit-app-region: no-drag;

  /* ~~~~~~~~~~~~~ Reset script ~~~~~~~~~~~~ */
  cursor: default;
  margin: 0;
  padding: 0;
  border: 2px solid blue;
  font-size: 100%;
  font: inherit;
  vertical-align: baseline;
}

html,
body {
  /*height: 100%;*/
  border: 4px solid red;
  background-color: #212121;
}

#TitleBar {
  -webkit-app-region: drag;
  background-color: #1a1a1a;
}

/* ##################################################################### */
/* ############################### Images ############################## */
/* ##################################################################### */
#Icon {
  width: 4%;
  height: 4%;
}

#ControlButtons {
  float: right;
}

#Close-Btn {
  width: 30px;
  height: 30px;
}

#Min-Btn {
  width: 30px;
  height: 30px;
}

The html:

<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8" />
  <title>MyClipboard</title>
  <link rel="stylesheet" href="Styles/HomeStyle.css" />
</head>

<body>
  <div id="TitleBar">
    <img src="Images/clipboard_96px.png" id="Icon"></img>
    <div id="ControlButtons">
      <input type="image" id="Min-Btn" src="Images/minimize_window_96px.png">
      <input type="image" id="Close-Btn" src="Images/close_window_96px.png">

    </div>
  </div>
  <div id="Menu"></div>
  <div id="Content"></div>
  <script>
    require('./Control.js')
  </script>

</body>

</html>

Thanks for your response!

1 Answers

Your 100% will not include the border so it overflows and adds the scrollbar.

Add box-sizing: border-box; to your body

border-box tells the browser to account for any border and padding in the values you specify for an element's width and height. If you set an element's width to 100 pixels, that 100 pixels will include any border or padding you added, and the content box will shrink to absorb that extra width. This typically makes it much easier to size elements.

MDN

Related