0

I've been trying to put in a paragraph into my div and it keeps pushing down the div. When i put in a normal div it doesn't change and it gets not pushed down. What is the problem here?

I tried to display the p tag as absolute but that is not really professional and it looks ugly. Also i have put a div into the parent div and it worked. It only does that with the p tag.

.mod {
  transition-duration: 0.05s;
  display: inline-block;
  height: 600px;
  width: 337px;
  padding-left: 7px;
  padding-right: 7px;
  position: relative;
  background-color: red;
}

.modpic {
  transition-duration: 0.05s;
  height: 130px;
  width: 337px;
  background-position: center;
  background-size: 686px 430px;
  background-color: grey;
}

.namediv {
  text-align: center;
  width: 100%;
  background-color: blue;
}

.name {
  letter-spacing: 0.3px;
  color: white;
  font-size: 26px;
  font-family: 'Barlow Condensed';
}
<div class="mod">
  <div class="modpic">
  </div>
  <div class="namediv">
    <p class="name">Example</p>
  </div>
</div>

I expect that the p tag gets displayed under the "modpic" but it just messes everything up.

Paulie_D
  • 107,962
  • 13
  • 142
  • 161

2 Answers2

1

By Default Paragraph tag has margin. So do the below code change in your css.

CSS

.name {
    letter-spacing: 0.3px;
    color: white;
    font-size: 26px;
    font-family: 'Barlow Condensed';
    margin: 0;  /* Newly added */
}

#content {
    height: 350px;
    width: 100%;
    overflow-x: scroll;
    white-space: nowrap;
    display: flex; /* Newly added */
}

OUTPUT

enter image description here

Par Tha
  • 1,265
  • 7
  • 10
0

A paragraph has margin as a default property. I'd suggest you use a proper CSS Reset.

/* mini-reset */

* {
margin:0;
padding:0;
}
.mod {
  transition-duration: 0.05s;
  display: inline-block;
  height: 600px;
  width: 337px;
  padding-left: 7px;
  padding-right: 7px;
  position: relative;
  background-color: red;
}

.modpic {
  transition-duration: 0.05s;
  height: 130px;
  width: 337px;
  background-position: center;
  background-size: 686px 430px;
  background-color: grey;
}

.namediv {
  text-align: center;
  width: 100%;
  background-color: blue;
}

.name {
  letter-spacing: 0.3px;
  color: white;
  font-size: 26px;
  font-family: 'Barlow Condensed';
}
<div class="mod">
  <div class="modpic">
  </div>
  <div class="namediv">
    <p class="name">Example</p>
  </div>
</div>
Paulie_D
  • 107,962
  • 13
  • 142
  • 161