2

Cant seem to find how to remove vertical space between two text elements, There are some similar problems on this website but doesn't seem to actually work.

HTML Code:

<p>this website is</p> <h1>Encrypted</h1>

it seems that I would have to use a position code, but when I use a position code that lets other elements get close to it, the text gets pushed to another spot on the website

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
Nikolas
  • 537
  • 1
  • 5
  • 7

2 Answers2

2

Remove white space between elements using CSS:

Horizontal being (top and bottom space)

h1, p {
margin-top: 0;
margin-bottom: 0;
line-height: /* adjust to tweak wierd fonts */;
}

Vertical being (left and right space)

.parent {
font-size: 0;
line-height: 0;
}

h1, p {
font-size: 12px;
margin: 0;
display: inline-block;
}

JSFIDDLE

CodeUK
  • 421
  • 1
  • 5
  • 13
1

Every browser has pre-set styles for elements. p and header tags have margins set. You can change this by using margin: 0;: JS Fiddle

You may also benefit from using a CSS Reset to avoid these issues.

Also, I don't imagine a scenario where the word "encrypted" in your code should be using an <h1> tag: How to properly use h1

Community
  • 1
  • 1
Derek Story
  • 9,518
  • 1
  • 24
  • 34
  • Thank you, not sure why so many disliked the post, I guess this website isn't very noob friendly – Nikolas Mar 14 '15 at 23:38
  • Its difficult to answer questions fully without more context. Typically you will want to include your CSS (or anything you have attempted) as well. And everyone loves a jsfiddle.net of the issue too. – Derek Story Mar 14 '15 at 23:41