简体   繁体   English

文字在CSS上对齐

[英]Text top align on CSS

I have created an HTML framework to display a top banner containing an image a centered title and a clock, below it, there is a stage area to display some graphs and images. 我创建了一个HTML框架来显示顶部横幅,其中包含图像,居中标题和时钟,在其下方,有一个舞台区域可以显示一些图形和图像。

The problem I am encountering is that when I increase the font size of the title in the banner, I am left with some white space above, and with increasing the font size, the text disappears (I have set the containing div to hide the overflow). 我遇到的问题是,当我增加横幅中标题的字体大小时,上面留有一些空白,并且随着字体大小的增加,文本消失了(我将包含div的值设置为隐藏溢出)。 Ideally, this spacing could be reduced with some property. 理想情况下,此间隔可以通过某些属性来减小。

I tried searching for aligning the text to the top, but unfortunately I just cannot find it! 我尝试搜索使文本与顶部对齐,但不幸的是我找不到它! The behaviour is present even when the text and its div are the only things in the document. 即使文本及其div是文档中唯一的内容,也存在该行为。

Link to the jsFiddle with the whole page here Link to the isolated div here 链接到的jsfiddle与整个页面在这里链接到隔离DIV 这里

Is there a property I am missing, or another trick to move the text upwards? 是否缺少我想要的属性,或者还有其他技巧可以将文本向上移动?

 <div id="banner" style="width:100vw;height:10vh;overflow:hidden"> <div id="bannerLeft" style="width:15vw;height:100%;overflow:hidden;float:left;background-color:red"> img </div> <div id="bannerMiddle" style="width:70vw;height:100%;overflow:hidden;float:left;background-color:blue"> <p style="text-align:center;font-size: 2.5em;">Staged Title</p> </div> <div id="bannerRight" style="width:15vw;height:100%;overflow:hidden;float:left;background-color:green"> <p id="timeNow" style="font-size: 2.5em;text-align:center"> 10:00 </p> </div> </div> <div id="stage" style="width:100vw;height:85vh;overflow: hidden;background-color:yellow"> Stage is managed with JS </div> 

The problem is the <p> tag inside the div. 问题是div中的<p>标记。 You realy don't need it here. 您真的不需要在这里。 Remove it, and add the styling to the div element: 删除它,并将样式添加到div元素中:

Staged Title 分阶段标题

Demo: 演示:

 .bannerMiddle { width: 70vw; height: 10vh; overflow: hidden; float: left; background-color: blue; text-align: center; font-size: 2em; } 
 <div class="bannerMiddle"> Staged Title </div> <br style="clear: left"><br> <div class="bannerMiddle"> <p>Staged Title (BAD)</p> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM