如何在单词下面使用底部边框,有限长度和居中?

时间:2017-06-23 23:05:19

标签: javascript html css html5 containers

this页面的底部,我试图将版权文本下的灰线设置为30%,因此它比文本短。我的问题是,当设置为小于文本长度的%时,它将文本放在2行上。我希望文字在一行。

版权箱代码:

.copyright-container{
	box-sizing: border-box;
padding-right:20px;padding-left:20px;
background-color: black;
text-align: center;
position:relative;
bottom:0;
width:100%;
height:220px;
    color: white;
}

.vert-align{
position: relative;
top: 50%;
}
.headline {
    width: 30%; 
    line-height: 1.5em;
    border-bottom:2px solid #6d6666;
    margin:0px auto; 
    color:white;
}

其他代码:

<div class="copyright-container">
		<div class="vert-align">
			<p class="headline">Copyright &copy; 2017 RyanTeaches - All Rights Reserved.</p>
		</div>
	</div>

我是html和css的新手

非常感谢, 瑞恩

3 个答案:

答案 0 :(得分:0)

你可以使用伪元素:

.headline:before {
    content: "";
    position: absolute;
    left: 43%;
    bottom: 0;
    height: 1px;
    width: 15%;
    border-bottom: 1px solid #6d6666;
}

答案 1 :(得分:0)

您无法使用分配给文本的样式属性来执行此操作。但是你可以这样做,如下图所示:

&#13;
&#13;
.headline {
    line-height: 1.5em;
    margin: 0px auto;
    color: black;
    text-align: center;
}

.headline_under {
    border-bottom: 1px solid black;
    max-width: 120px;
    margin: 0 auto;
    margin-top: 10px;
}
&#13;
<p class="headline">Copyright © 2017 RyanTeaches - All Rights Reserved.</p>
<div class="headline_under"></div>
&#13;
&#13;
&#13;

答案 2 :(得分:0)

.headline {
 
    line-height: 2.5em;
    margin:0px auto; 

}

.headline:before {
    content: "";
    position: absolute;
    left: 40%;
    bottom: 0;
    height: 1px;
    width: 20%;
    border-bottom: 2px solid #6d6666;
    color:white;
}

这个组合为我排序了!感谢你们!

我想使用一行代码将其插入到每个页面中。我不能使用PHP。我是否可以使用JS,如果是这样,我将如何编写JS?

干杯!