Ron Goldstein
Ron Goldstein

Reputation: 43

How divide HTML Page vertically into 4 sections

I want divide my HTML Page into 4 different vertical sections .

I want each section to have a different background color, for that I used div but it each background color does not cover the sides of each section.

** My aspire end result: I don't want to see the color red of the body background color in the html.

body {
  background-color: red;
}

.intro {
  background-color: #674AB3;
}

.edu {
  background-color: #A348A6;
}

.Skills {
  background-color: #9F63C4;
}

.end {
  background-color: #9075D8;
}
<div class="intro">

  <hr>
</div>
<div class="edu">

  <hr>
</div>
<div class="Skills">

  <hr>
</div>
<div class="end">

  <hr>
</div>

Upvotes: 3

Views: 862

Answers (8)

Hal
Hal

Reputation: 26

You could try using grid! might as well make it responsive :D

This is to have 4 sections laying one next to another, to make them stack in the vertical direction, change:

grid-template-columns: repeat(4, 1fr);

to:

grid-template-rows: repeat(4, 1fr);

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

body {
  background-color: #00000000; /* transparent color */
  display: grid;
  grid-template-columns: repeat(4, 1fr); /* 4 vertical sections */
  height: 100vh;
  margin: auto;
}

.intro {
  background-color: #674AB3;
}

.edu {
  background-color: #A348A6;
}

.Skills {
  background-color: #9F63C4;
}

.end {
  background-color: #9075D8;
}
<div class="intro">
    <p>intro</p>
</div>
<div class="edu">
    <p>edu</p>
</div>
<div class="Skills">
    <p>Skills</p>
</div>
<div class="end">
    <p>end</p>
</div>

Upvotes: 1

Elias kibret
Elias kibret

Reputation: 41

<div class="main">

    <div class="intro">
    
    </div>
    <div class="edu">
    
    </div>
    <div class="Skills">

    </div>
    <div class="end">

    </div>
.main{
    display: flex;
    grid-template-columns: repeat(4,1fr);
    width:100vw;
}
.intro {
  background-color: #674AB3;
  width: 25%;
  height: 75vh;
}

.edu {
  background-color: #A348A6;
  width: 25%;
  height: 75vh;
}

.Skills {
  background-color: #9F63C4;
  width: 25%;
  height: 75vh;
}

.end {
  background-color: #9075D8;
  width: 25%;
  height:75vh;
}

Upvotes: 0

Elias kibret
Elias kibret

Reputation: 41

    <div class="intro">
    
    </div>
    <div class="edu">
    
    </div>
    <div class="Skills">

    </div>
    <div class="end">

    </div>
</div>

body {
  background-color: red;
}
.main{
    display: flex;
    grid-template-columns: repeat(4,1fr);
    width:100vw;
}
.intro {
  background-color: #674AB3;
  width: 25%;
  height: 75vh;
}

.edu {
  background-color: #A348A6;
  width: 25%;
      height: 75vh;
}

.Skills {
  background-color: #9F63C4;
  width: 25%;
      height: 75vh;
}

.end {
  background-color: #9075D8;
  width: 25%;
      height: vh;
}

grid

Upvotes: 0

Nitin Garg
Nitin Garg

Reputation: 262

You can simmply use display: flex to the parent container which is flex-container

like

<div style="display: flex;">
  <div class="intro"><hr></div>
  <div class="edu"><hr></div>
  <div class="Skills"><hr></div>
  <div class="end"><hr></div>
</div>

Upvotes: 0

Omri Attiya
Omri Attiya

Reputation: 4037

  1. Set margin: 0 for body, it has a defualt margin.
  2. Set <hr>'s margin to 0.
  3. Set height for each div to be 25vh (vertical height).

body {
  background-color: red;
  margin: 0;
}

.intro {
  background-color: #674AB3;
  height: 25vh;
}

.edu {
  background-color: #A348A6;
  height: 25vh;
}

.Skills {
  background-color: #9F63C4;
  height: 25vh;
}

.end {
  background-color: #9075D8;
  height: 25vh;
}

hr {
  margin: 0;
}
<div class="intro">
  <hr/>
</div>
<div class="edu">
  <hr/>
</div>
<div class="Skills">
  <hr/>
</div>
<div class="end">
  <hr/>
</div>

Upvotes: 2

Crystal
Crystal

Reputation: 1992

You can try this approach as well.

body {background-color:transparent;}

.intro {
  background-color: #674AB3;
  height:100vh;
  width:100%;
}

.edu {
  background-color: #A348A6;
  height:100vh;
  width:100%;
}

.Skills {
  background-color: #9F63C4;
  height:100vh;
  width:100%;
}

.end {
  background-color: #9075D8;
  height:100vh;
  width:100%;
}

.wrapper {
  display:grid;
  height:100vh;
  width:100%;
  }
<div class="wrapper">
<div class="intro">
Hello
</div>

<div class="edu">
Hello
</div>
<div class="Skills">
Hello
</div>
<div class="end">
Hello
</div>

</div>

Upvotes: 0

Dipesh
Dipesh

Reputation: 395

.flex-container {
  display: flex;
  justify-content: center;
  align-items: center;
}

.flex-container>div {

margin:30px;
}
.flex-container hr {
   
    width: 100px;
    height: 100px;
    padding: 5px;
    margin: 10px;
    border-color: #FFF;
    box-shadow: none;
    border-width: 5px;
}

.intro {
  background-color: #674AB3;
}

.edu {
  background-color: #A348A6;
}

.Skills {
  background-color: #9F63C4;
}

.end {
  background-color: #9075D8;
}
<div class="flex-container">
  <div class="intro"><hr></div>
  <div class="edu"><hr></div>
  <div class="Skills"><hr></div>
  <div class="end"><hr></div>
</div>

Upvotes: 2

D A
D A

Reputation: 2072

Something like this?

body {
  background-color: red;
}

.intro {
  height:200px;
  background-color: #674AB3 !important;
}

.edu {
  height:200px;
  background-color: #A348A6 !important;;
}

.Skills {
  height:200px;
  background-color: #9F63C4 !important;;
}

.end {
  height:200px;
  background-color: #9075D8 !important;;
}
<div class="intro">

  <hr>
</div>
<div class="edu">

  <hr>
</div>
<div class="Skills">

  <hr>
</div>
<div class="end">

  <hr>
</div>

Upvotes: 0

Related Questions