2

What I am trying to achieve is this:

mockup.

However, I'm having trouble to do the last block/rectangle(red). Because it doesn't belong to the rows I created for the other blocks. I have tried to float right with no success.

How do I implement the last red block/rectangle?

I'm using Flexbox for the container.

Current code:

.container {
  display: flex;
  flex-wrap: wrap;
}

#wrapper {
  margin-right: auto;
  margin-left: auto;
  width: 1520px;
}

.row {
  flex-direction: row;
}

.column {
  flex-direction: column;
}

#dateAndTime {
  width: 450px;
  height: 270px;
  background-color: #0dab76;
  margin-right: 40px;
}

.bottom {
  margin-top: 40px;
}

#forecast {
  width: 450px;
  height: 270px;
  background-color: #143642;
}

#news {
  background-color: #a8201a;
  width: 230px;
  height: 100px;
  margin-left: 40px;
}

#title {
  background-color: #ec9a29;
  width: 650px;
  height: 270px;
  margin-left: 40px;
}

#none {
  background-color: #0f8b8d;
  width: 250px;
  height: 270px;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <title>Dashboard</title>
</head>

<body>
  <div id="wrapper">
    <div class="container row">
      <div id="dateAndTime"></div>
      <div id="forecast"></div>
      <div></div>
    </div>
    <div class="container row bottom">
      <div id="none"></div>
      <div id="title"></div>
    </div>
  </div>
</body>

</html>
Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
TomasLife
  • 53
  • 7
  • 1
    Not ideal with flexbox considering the structure.. Consider CSS-Grid – Paulie_D Jul 11 '18 at 14:40
  • For flexbox, this isn't two rows, it's two columns....start there. – Paulie_D Jul 11 '18 at 14:44
  • @Paulie_D but the blocks have different sizes, wouldn't that be a problem? – TomasLife Jul 11 '18 at 14:46
  • Each flexbox container can have either rows or columns, not both. A flex element can't span several rows/columns. A possible solution for your case could be a nested flexbox structure, the outer container with 2 items (the right orange sidebar and everything else), the inner container with 2 rows of 2 items in each. – Ilya Streltsyn Jul 11 '18 at 14:47
  • How would I set the size of the blocks using a grid? – TomasLife Jul 11 '18 at 15:02

2 Answers2

1

As a general rule, you need two columns...the structure is important.

Adjust as required.

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

::before,
::after {
  box-sizing: inherit;
}

.container {
  display: flex;
  flex-wrap: wrap;
}

#wrapper {
  width: 416px;
  display: flex;
}

.left {
  flex: 2;
  display: flex;
  justify-content: space-between;
  margin-right: 4px;
}

.right {
  flex: 1;
  background: red;
}

#dateAndTime {
  width: 135px;
  height: 81px;
  background-color: #0dab76;
  margin-bottom: 4px;
}

#forecast {
  width: 135px;
  height: 81px;
  background-color: #143642;
}

#news {
  background-color: #a8201a;
  width: 69px;
  height: 30px;
}

#title {
  background-color: #ec9a29;
  width: 195px;
  height: 81px;
}

#none {
  background-color: #0f8b8d;
  width: 75px;
  height: 81px;
}
<div id="wrapper">
  <div class="container left">
    <div id="dateAndTime"></div>
    <div id="forecast"></div>
    <div id="none"></div>
    <div id="title"></div>
  </div>
  <div class="right"></div>
</div>
Paulie_D
  • 107,962
  • 13
  • 142
  • 161
0

You can add one more wrapper, and create two columns, like so:

#main-wrapper {
  display: flex;
}

#red {
  width: 200px;
  height: calc(270px * 2 + 40px);
  background-color: red;
}

/* http://meyerweb.com/eric/tools/css/reset/
   v2.0 | 20110126
   License: none (public domain)
*/

html,
body,
div,
span,
applet,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
abbr,
acronym,
address,
big,
cite,
code,
del,
dfn,
em,
img,
ins,
kbd,
q,
s,
samp,
small,
strike,
strong,
sub,
sup,
tt,
var,
b,
u,
i,
center,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
article,
aside,
canvas,
details,
embed,
figure,
figcaption,
footer,
header,
hgroup,
menu,
nav,
output,
ruby,
section,
summary,
time,
mark,
audio,
video {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 100%;
  font: inherit;
  vertical-align: baseline;
}


/* HTML5 display-role reset for older browsers */

article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section {
  display: block;
}

body {
  line-height: 1;
}

ol,
ul {
  list-style: none;
}

blockquote,
q {
  quotes: none;
}

blockquote:before,
blockquote:after,
q:before,
q:after {
  content: '';
  content: none;
}

table {
  border-collapse: collapse;
  border-spacing: 0;
}

body {
  padding-top: 130px;
}

.container {
  display: flex;
  flex-wrap: wrap;
}

#wrapper {
  margin-right: auto;
  margin-left: auto;
  width: 940px;
}

.row {
  flex-direction: row;
}

.column {
  flex-direction: column;
}

#dateAndTime {
  width: 450px;
  height: 270px;
  background-color: #0dab76;
  margin-right: 40px;
}

.bottom {
  margin-top: 40px;
}

#forecast {
  width: 450px;
  height: 270px;
  background-color: #143642;
}

#news {
  background-color: #a8201a;
  width: 230px;
  height: 100px;
  margin-left: 40px;
}

#title {
  background-color: #ec9a29;
  width: 650px;
  height: 270px;
  margin-left: 40px;
}

#none {
  background-color: #0f8b8d;
  width: 250px;
  height: 270px;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <title>Dashboard</title>
</head>

<body>
  <div id="main-wrapper">
    <div id="wrapper">
      <div class="container row">
        <div id="dateAndTime"></div>
        <div id="forecast"></div>
        <div></div>
      </div>
      <div class="container row bottom">
        <div id="none"></div>
        <div id="title"></div>
      </div>
    </div>
    <div id="red"></div>
  </div>
</body>

</html>

But it's really better to use CSS-Grid in this case. More info about CSS-Grid you can find on css-tricks.com

Maxim Mazurok
  • 3,856
  • 2
  • 22
  • 37