使左对齐的div占用所有空间

时间:2018-06-12 05:00:41

标签: html css position

我想制作一份在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之后的内容不是以新行开头,而是显示在右侧。

enter image description here

2 个答案:

答案 0 :(得分:0)

.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>

答案 1 :(得分:0)

添加clearfix div,如下所示,以移除影响下一个元素的浮动。

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

.clearfix::after {
content: "";
clear: both;
display: table;
}
<div class="bold-cli">
 ABC ABC  ABC ABC  ABC ABC  ABC ABC  ABC ABC  AB ABC  ABC ABC  ABC 
</div>
<div class="clearfix">
</div>

Start from new line