我有一个带有文字的响应方块。我希望广场保持所有尺寸的比例,除非里面的文字溢出,否则我希望广场更高。
现在,文本只是隐藏的。
http://jsfiddle.net/38Tnx/2253/
<div class='square-box'>
<div class='square-content'>
<div>
<span>text</span>
</div>
</div>
</div>
.square-box{
position: relative;
width: 50%;
overflow: hidden;
background: #4679BD;
}
.square-box:before{
content: "";
display: block;
padding-top: 100%;
}
.square-content{
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
color: white;
}
.square-content div {
display: table;
width: 100%;
height: 100%;
}
.square-content span {
display: table-cell;
text-align: center;
vertical-align: middle;
color: white
}
最佳答案
将您的.square-box
css替换为以下代码
.square-box{
position: relative;
width: 50vw;
height: 50vw;
overflow: hidden;
background: #4679BD;
}
JSFIDDLE DEMO