CSS删除行之间的间距

时间:2017-06-04 09:24:18

标签: html css

是否可以删除两个中心对齐文本之间的间距?

HTML:

  <div id="content2">
       <p class="t1">Discover</p>
       <p class="t1">Discover</p>
    </div>

CSS:

    #content2 {
        clear: both;
        overflow: auto;
    }

    .t1 {
      font-weight: bold;    
      font-size:60px;   
      color: black;
        text-align: center;
    }

p {
    font-size : 30px;
    padding : 0;
    margin : 30px;
    line-height : 20px;
}

Codepen:https://codepen.io/jayvicious/pen/owNJRr

我也正在适应这个主题: Remove spacing between <p>

当我增加行高时,content2p之间的间距也会增加。

我正在寻找类似的输出:

enter image description here

每次增加行高时,它也会影响第一个法律<p>content2

的间距

2 个答案:

答案 0 :(得分:2)

您可以做的最好是从p标签中删除边距/填充并调整线高。

作为示例,请查看https://codepen.io/anon/pen/bRGzNW

HTML:

<div id="content2">
   <p class="t1">testGg</p>
   <p class="t1">testgG</p>
   <p class="t1">testGg</p>
</div>

的CSS:

#content2 {
    clear: both;
    overflow: auto;
}

.t1 {
    font-weight: bold;  
    font-size:60px; 
    line-height:60px;
    color: black;
    text-align: center;
}

p {
    padding : 0;
    margin : 0;
}

答案 1 :(得分:1)

  

您可以将两个类用于段落,并使用margin-top属性。

#content2 {
	clear: both;
	overflow: auto;
}

.t1 {

  font-weight: bold; 	
  font-size:60px;	
  color: black;
  text-align: center;
  
}

p {
    font-size : 30px;
    padding : 0;
    margin : 30px;
    line-height : 20px;
}

.t {
  margin-top: -20px;
}
  <div id="content2">
       <p class="t1">test</p>
       <p class="t1 t">test</p>
</div>