文本的居中显示
示例图:
css 样式
<style>
.item {
width: 150px;
height: 200px;
border: red 1px solid;
box-sizing: border-box;
float: left;
}
.first {
display: flex;
align-items: center;
justify-content: center;
}
.second {
line-height: 200px;
}
.thrid {
position: absolute;
top:50%;
left:50%;
transform: translate(-50%, -50%);
}
</style>
body体
<body>
<div class="first item">
<span>
flex 布局实现
good good study day day up
</span>
</div>
<div class="second item">
<span>
lineHeight用于单行
</span>
</div>
<div class="thrid item">
<span>
利用position 定位来实现1
good good study day day up
</span>
</div>
</body>
script
<script>
function checkHtml(htmlStr) {
var reg = /<[^>]+>/g;
return reg.test(htmlStr);
}
checkHtml('点击此<span style="color: rgb(244, 113, 31);">处进</span><span style="color: rgb(136, 136, 136);">行编</span>辑')
</script>