0

i am trying to place a title above some words but my title has a white space underneath, my css is

.title{
  grid-template-areas:"image" "title"
}

.title_word{
   grid-area: title;
}

.title_img{
  grid-area: img;
}
<div class="title">
<p class="title_word">hello</p>
<img src="https://live.staticflickr.com/5549/10549969363_76ccf43946_b.jpg" alt="not working" class="title_img">
</div>

as you can see, this works but in firefox and chrome it is giving me lots of white space

4 Answers4

0

If you want to delete the whitespace underneath add:

margin-bottom: 0;

to your

.title

In the end it should look like this.

.title {
    grid-template-areas:"image" "title"
    margin-bottom: 0;
}
Petar Vasilev
  • 4,281
  • 5
  • 40
  • 74
Luca Adrian
  • 75
  • 1
  • 7
0

Before I start tinkering with CSS - I add an * selector, which removes default margins and padding.

* {
  margin: 0;
  padding: 0;
}

.title{
  grid-template-areas:"image" "title"
}

.title_word{
   grid-area: title;
}

.title_img{
  grid-area: img;
}
<div class="title">
<p class="title_word">hello</p>
<img src="https://live.staticflickr.com/5549/10549969363_76ccf43946_b.jpg" alt="not working" class="title_img">
</div>
Eduards
  • 1,734
  • 2
  • 12
  • 37
0

Adding margin-bottom: 0 to the title class will do the job. the reason for that is because margins are used to create space around elements, outside of the defined borders so setting it to 0 will eliminate that extra gap.

the <p> tag has a default css property of margin-block-end: 1em; which is causing that extra gap you see.

.title{
  grid-template-areas:"image" "title"
}

.title_word{
   grid-area: title;
   margin-bottom: 0;
}

.title_img{
  grid-area: img;
}
<div class="title">
<p class="title_word">hello</p>
<img src="https://live.staticflickr.com/5549/10549969363_76ccf43946_b.jpg" alt="not working" class="title_img">
</div>
Ran Turner
  • 14,906
  • 5
  • 47
  • 53
-1

This is likely because of the margin that html things tend to have. try a margin: 0; or a margin-bottom: 0; if that doesn't work, try the same with the border: 0; and padding: 0; as that's what makes up the whole block.

Dharman
  • 30,962
  • 25
  • 85
  • 135