2

I'm using an article header to divide up some projects I wish to display:

.project-elem {
  background-color: greenyellow;
  padding-top: 5rem;
  padding-bottom: 5rem;
  height: 300px;
}

.projects {
  margin: 0;
  padding: .7rem;
  background-color: #DDCDE8;
  font: Asap, sans-serif;
  height: 1000px;
}

.project-n {
  background-color: green;
  text-align: center;
  width: 60%;
  float: left;
  padding: 2.5rem;
}

.img {
  background-color: blue;
  text-align: center;
  padding: 3rem;
  margin-left: 40%;
}
<div class="projects" id=#projects>
  <h2>My Projects</h2>
  <article class="project-elem">
    <div class="project-n" id="dictocounter">
      <h3>Dictation Counter</h3>
      <p>info about proj</p>
      <img src="dictocounter1.jpg" alt="Dictocounter in Action">
    </div>
    <div class="img">
      <p>heres SOME IMAGE</p>
    </div>
  </article>
  <article class="project-elem">
    <div class="project-n" id="calc">
      <h3>RPN Calculator</h3>
      <p>info about proj</p>
      <img src="calc.jpg" alt="RPN Calculator Decoding Input">
    </div>
    <div class="img">
      <p>heres SOME IMAGE</p>
    </div>
  </article>
  <article class="project-elem">
    <div class="project-n" id="markov">
      <h3>Markov Chain Text Generation</h3>
      <p>info about proj</p>
      <img src="calc.jpg" alt="Markov Chain Text Generation">
    </div>
    <div class="img">
      <p>heres SOME IMAGE</p>
    </div>
  </article>
  <article class="project-elem">
    <div class="project-n" id="audio">
      <h3>Song Similarities</h3>
      <p>info about proj</p>
      <img src="calc.jpg" alt="Audio Spectral Analysis">
    </div>
    <div class="img">
      <p>heres SOME IMAGE</p>
    </div>
  </article>
  <article class="project-elem">
    <div class="project-n" id="tree">
      <h3>DFS/BFS Search Tree</h3>
      <p>info about proj</p>
      <img src="calc.jpg" alt="Simple Trees">
    </div>
    <div class="img">
      <p>heres SOME IMAGE</p>
    </div>
  </article>
</div>

Yet, even though I pad project-elem explicitly, the actual project-elem articles are not padded (rather, smushed all together into one lime-green blob):

enter image description here

I can tell that there is no padding between the project elements because the outer division (with bkgrd color purple) cannot be seen between each of the lime-green project elements. Why is this the case, and how can I fix this?

Also, how can I make the img class vertically-even with the project-n class?

j08691
  • 204,283
  • 31
  • 260
  • 272
rjc810
  • 425
  • 1
  • 3
  • 17

3 Answers3

4

You might need margin-bottom instead of padding-bottom;

By using padding you don't seperate them, padding works kind of from-inside.

You may read about box-model here to understand this.

Rakesh K
  • 1,290
  • 1
  • 16
  • 43
1

I suggest you to use flex-box for this. It would be something like this:

html
<html>
<head>
<style>
.project-elem {
    background-color: greenyellow;
    padding-top: 5rem;
    padding-bottom: 5rem;
    height: 300px;
    display: flex;
    justify-content: space-between;
}

.projects {
    margin: 0;
    background-color: #DDCDE8;
    font: Asap, sans-serif;
    height: 1000px;
    box-sizing: border-box;
}

.project-n {
    background-color: green;
    text-align: center;
    width: 60%;
    padding: 2.5rem;
    box-sizing: border-box;
}

.img {
    background-color: blue;
    text-align: center;
    padding: 3rem;
    box-sizing: border-box;
    width: 25%;
}

</style>
</head>
<body>
<div class="projects" id=#projects>
        <h2>My Projects</h2>

        <article class="project-elem">
            <div class="project-n" id="dictocounter">
                <h3>Dictation Counter</h3>
                <p>info about proj</p>
                <img src="dictocounter1.jpg" alt="Dictocounter in Action">
            </div>
            <div class="img">
                <p>heres SOME IMAGE</p>
            </div>
        </article>

        <article class="project-elem">
            <div class="project-n" id="calc">
                <h3>RPN Calculator</h3>
                <p>info about proj</p>
                <img src="calc.jpg" alt="RPN Calculator Decoding Input">
            </div>
            <div class="img">
                <p>heres SOME IMAGE</p>
            </div>
        </article>
        
        <article class="project-elem">
            <div class="project-n" id="markov">
                <h3>Markov Chain Text Generation</h3>
                <p>info about proj</p>
                <img src="calc.jpg" alt="Markov Chain Text Generation">
            </div>
            <div class="img">
                <p>heres SOME IMAGE</p>
            </div>
        </article>

        <article class="project-elem">
            <div class="project-n" id="audio">
                <h3>Song Similarities</h3>
                <p>info about proj</p>
                <img src="calc.jpg" alt="Audio Spectral Analysis">
            </div>
            <div class="img">
                <p>heres SOME IMAGE</p>
            </div>
        </article>

        <article class="project-elem">
            <div class="project-n" id="tree">
                <h3>DFS/BFS Search Tree</h3>
                <p>info about proj</p>
                <img src="calc.jpg" alt="Simple Trees">
            </div>
            <div class="img">
                <p>heres SOME IMAGE</p>
            </div>
        </article>
    </div>
</body>
</html>
Decapitated Soul
  • 283
  • 4
  • 14
Enrico
  • 361
  • 1
  • 11
1

Since the project-elem has only padding and not margin, there is no gap between different elements with the class "project-elem"

Change padding to margin for your requirement as shown below:

.project-elem {
  background-color: greenyellow;
  margin-top: 5rem;
  margin-bottom: 5rem;
  height: 300px;
}

.projects {
  margin: 0;
  padding: .7rem;
  background-color: #DDCDE8;
  font: Asap, sans-serif;
  height: 1000px;
}

.project-n {
  background-color: green;
  text-align: center;
  width: 60%;
  float: left;
  padding: 2.5rem;
}

.img {
  background-color: blue;
  text-align: center;
  padding: 3rem;
  margin-left: 40%;
}

Understand the difference between padding and margin. You can refer this: https://stackoverflow.com/a/2189462/12774953

Barath
  • 27
  • 5