如何使块元素调整到其内部的大小? [英] How to make a block element adjust to the size of what is inside it?
本文介绍了如何使块元素调整到其内部的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有这个HTML:
If I have this HTML:
<li class="name">hi</li>
<li class="name">hello</li>
<li class="name">wheeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee!</li>
此CSS:
li.name{
border: 1px solid #A38870;
background-color: #FA682D;
list-style: none;
margin: 15px;
padding: 5px;
}
背景在整个页面上延伸,如这个。
The background extends all the way across the page like this.
如何让背景调整为大小此(无需显式设置每个列表元素的宽度)的文本?
How can I make the background adjust to the size of the text like this (without explicitly setting the width for each list element)?
推荐答案
display: table;
在 li.name
css类。
这篇关于如何使块元素调整到其内部的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文