-4

I have two divs side by side. Div1 width is 200px and Div2 should fill the screen. To do this, I use jQuery and detect the screen with and then substuct 200 from it. But if I use this way, jQuery slows down the browser. So I'm searching a better way rather than using jQuery. What is the best way to do this?

Update :
I forgot to write that float did not fixed my solution.

Thank you I'm going to check the answers.

Bengi Besçeli
  • 3,638
  • 12
  • 53
  • 87

2 Answers2

1

float solution

body { margin: 0; }

#a {
  background-color: lime;
  width: 200px;
  float: left;
  height: 100vh
}

#b {
  background-color: blue;
  margin-left: 200px;
  height: 100vh;
}
<div id="a"></div>
<div id="b"></div>

css grid

body {
  margin: 0;
}

.gridcontainer {
  display: grid;
  grid-template-columns: 200px 1fr;
  height: 100vh;
}

#a {
  background-color: lime;
  height: 100vh;
}

#b {
  background-color: blue;
  height: 100vh;
}
<div class="gridcontainer">
  <div id="a"></div>
  <div id="b"></div>
</div>

flexbox

body {
  margin: 0;
}

.flexcontainer {
  display: flex;
}

#a {
  background-color: lime;
  width: 200px;
  height: 100vh;
}

#b {
  background-color: blue;
  height: 100vh;
  width: calc(100% - 200px);
}
<div class="flexcontainer">
  <div id="a"></div>
  <div id="b"></div>
</div>

inline-block solution

body {
  margin: 0;
}

.inlineblockcontainer {
  font-size: 0;
}

.inlineblockcontainer>div {
  display: inline-block;
}

#a {
  background-color: lime;
  font-size: 16px;
  width: 200px;
  height: 100vh;
}

#b {
  background-color: blue;
  font-size: 16px;
  height: 100vh;
  width: calc(100% - 200px);
}
<div class="inlineblockcontainer">
  <div id="a"></div>
  <div id="b"></div>
</div>
connexo
  • 53,704
  • 14
  • 91
  • 128
-1

html,
body,
#container {
  height: 100%;
}

#left {
  width: 200px;
  float: left;
  min-height: 100%;
  background-color: blue;
}

#right {
  width: 100%;
  min-height: 100%;
  background-color: red;
}
<div id="container">
  <div id="left"></div>
  <div id="right"></div>
</div>

https://jsfiddle.net/832ahuqc/6/

Tim Diekmann
  • 7,755
  • 11
  • 41
  • 69
deanna
  • 31
  • 2