Warm tip: This article is reproduced from serverfault.com, please click

p tag within a div affecting the adjacent div's position

发布于 2020-11-27 15:38:06

.navi { 
  width: 100%; 
  height: 100px; 
  background-color: red; 
} 

.navi-item { 
  width: 50px; 
  height: inherit; 
  background: blue; 
  display: inline-block; 
  margin-left: 10px; 
 }
<div class="navi">
  <div class="navi-item">
    <div>logo</div>
  </div>
  <div class="navi-item">`enter code here`
    <p class="p-tag">Home</p>
  </div>
</div>

The logo div gets pushed down when p-tag is added. But when tag in place of

tag is doing fine.

Questioner
Mahesh Guduru
Viewed
0
verunar 2020-11-28 00:01:31

HTML elements such as paragraph have default css values that might have an effect on some elements. In this case p has following css from browser -

  • clear: both
  • margin-bottom: 1em

in this case i would suggest you try to add <span> instead of <p> and see if there will be any change. From your code example, it looks like 'Home' will be a link anyway, where you would use <a> not <p>