首页 > 解决方案 > 使左对齐的 div 占据所有空间

问题描述

我想制作一个指南以在Windows command prompt.

.bold-cli {
        float: left;
        padding: 20px;
        margin: 20px 30px;
        font-family: Arial;
        font-style: italic;
        font-weight: bold;
        background-color: black;
        color: white;
}

<div class="bold-cli">
    C:\> Rundll32 %windir%\system32\dfshim.dll CleanOnlineAppCache 
</div>

我希望div只占用足够的空间来显示命令,而不是水平拉伸,所以我添加了float: left.

问题是,这个div后面的内容不是换行,而是显示在右边。

在此处输入图像描述

标签: htmlcssposition

解决方案


.bold-cli {
  float: left;
  padding: 20px;
  margin: 20px 30px;
  font-family: Arial;
  font-style: italic;
  font-weight: bold;
  background-color: black;
  color: white;
}
<p>To fix this, start a command prompt, type the following command and then press Enter.</p>
<div class="bold-cli">
  C:\> Rundll32 %windir%\system32\dfshim.dll CleanOnlineAppCache
</div>
<span style="float:left;clear: both;">We have build a utility to run this command for you. <a href="https://stackoverflow.com/" style="color: #DB5523;">Click me</a></span>


推荐阅读