如何阻止css覆盖文本

时间:2017-04-17 20:49:38

标签: html css css3 text overlay

也许这是一个非常愚蠢的问题,但是当我试图扩大字体大小时,如何阻止css覆盖呢?

@import url(https://fonts.googleapis.com/css?family=Fjalla+One);

html{
  height: 100%;
}

body{
  font-family: 'Fjalla One', sans-serif;
  background: #2C3E50;  /* fallback for old browsers */
  background: -webkit-linear-gradient(to top, #4CA1AF, #2C3E50);  /* Chrome 10-25, Safari 5.1-6 */
  background: linear-gradient(to top, #4CA1AF, #2C3E50); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */


}

.container{
  margin: auto;
}


h1{
  text-transform: uppercase;
  font-size: 60px;
  line-height: 47px;
  letter-spacing: 2px;
  text-shadow: #533d4a 1px 1px, #533d4a 2px 2px, #533d4a 3px 3px, #533d4a 4px 4px;
  text-align: center;
}

.title{
  transform: translateX(-50%) rotate(-5deg);
  display: block;
  margin-left:50%;
}
<body>
<!--Titel-->
  <section class="container">
  <h1>
    <br />
    <span class="title" >
       <label style="color:#e55643;">Burger</label><label style="color:#2b9f5e;">school</label>
    </span>
    <span class="title" style="color:#f1c83c;">afspraken</span>
  </h1>
</section>
</body>

感谢您提前寻求帮助。我刚刚开始,也许这是一个非常愚蠢的问题..

3 个答案:

答案 0 :(得分:3)

您还必须调整line-height,例如将其设置为font-size60px。如果line-height对于给定的font-size而言较小,则文本会重叠。

&#13;
&#13;
@import url(https://fonts.googleapis.com/css?family=Fjalla+One);
html {
  height: 100%;
}

body {
  font-family: 'Fjalla One', sans-serif;
  background: #2C3E50;
  /* fallback for old browsers */
  background: -webkit-linear-gradient(to top, #4CA1AF, #2C3E50);
  /* Chrome 10-25, Safari 5.1-6 */
  background: linear-gradient(to top, #4CA1AF, #2C3E50);
  /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
}

.container {
  margin: auto;
}

h1 {
  text-transform: uppercase;
  font-size: 60px;
  line-height: 60px;
  letter-spacing: 2px;
  text-shadow: #533d4a 1px 1px, #533d4a 2px 2px, #533d4a 3px 3px, #533d4a 4px 4px;
  text-align: center;
}

.title {
  transform: translateX(-50%) rotate(-5deg);
  display: block;
  margin-left: 50%;
}
&#13;
<section class="container">
  <h1>
    <span class="title">
       <label style="color:#e55643;">Burger</label><label style="color:#2b9f5e;">school</label>
    </span>
    <span class="title" style="color:#f1c83c;">afspraken</span>
  </h1>
</section>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

在您的代码中,您设置了line-height : 47px;,但是您尝试将字体大小设置为比行高更大。

font-size: 60px;
line-height: 47px;  <!--This is what causing the problem, increase it as much as you increase the font size-->

例如:

font-size: 60px;
line-height: 60px; <!--It will do the job-->

答案 2 :(得分:1)

更改line-height:47px;并将其等于 font-size