相关疑难解决方法(0)

如何使div不大于其内容?

我的布局类似于:

<div>
    <table>
    </table>
</div>
Run Code Online (Sandbox Code Playgroud)

我希望div只扩展到我的范围table.

html css width

1960
推荐指数
33
解决办法
135万
查看次数

如何根据div内文本的大小调整div宽度

我的想法是使divs 中具有该类的每个元素.main_content的宽度等于其中文本的宽度。我该怎么办?

正如您所看到的,每个(spanh2, ph6)的宽度与 相同.main_content div。红色边框证明了这一点。

那么,如何使每个 div 的宽度适合这些 div 中的文本呢?(仅使用CSS

.main_content {
   width: 100%;
  height: 400px;
  font-weight: 800;
}

.main_content > * {
  border: 1px solid red;
  display: block;
  margin-bottom: 30px;
  text-align: center; 
}
Run Code Online (Sandbox Code Playgroud)
<div class="first_article">
  <div class="first_content">
    <div class="main_content">
       <span class="growth">Growth</span>
       <h2>5 compelling user referral campaign examples</h2>
       <p>Jumpstarts your user referral engine with these 5 approaches toreferral campaigns from popular apps.
       </p>
       <h6>Author</h6>
    </div> …
Run Code Online (Sandbox Code Playgroud)

html javascript css

5
推荐指数
1
解决办法
1057
查看次数

标签 统计

css ×2

html ×2

javascript ×1

width ×1