首页 > 解决方案 > HTML格式的问题

问题描述

字体大小会发生变化,headertext但不会居中。刚刚开始学习 HTML,所以这可能是一个新手错误。任何建议表示赞赏,谢谢!

.main {
  margin-left: 220px; /* Same as the width of the sidenav */
  margin-top: 20px; /* Same as the width of the sidenav */
  font-size: 20px; /* Increased text to enable scrolling */
}
    
.main headertext {
  font-size: 45px;
  text-align: center;
}
<div class="main">		
  <headertext>ExampleTitle</headertext>
  <p>Welcome to my website.</p>
</div>

标签: htmlcss

解决方案


headertext不是有效的 HTML 元素。将其更改为diva 类,headertext我认为可以解决您的问题,如下所示:

.main {
    margin-left: 220px;
    margin-top: 20px;
    font-size: 20px;
}

.main .headertext {
    font-size: 45px;
    text-align: center;
}
<div class="main">      
        <div class="headertext"> ExampleTitle </div>
        <p> Welcome to my website.</p>
</div>


推荐阅读