繁体   English   中英

清除这两个选项后,margin-top无效

[英]margin-top doesn't work after clear both

您好,我正在创建一个如下所示的聊天UI:

img http://gyazo.com/96a27ffed5203d3b435fe41d8832e1ca.png

如您所见,每个消息都是li元素,现在头像和消息div都向左浮动 现在,如果我不添加clear: both; li元素上,这些元素将在一行中一个接一个地运行。 因此,在清除所有内容之后,当我执行margin-top ,要在消息元素之间创建一些填充,除非添加500px的空白或其他内容,否则它不会执行任何操作。

<section id="chat-area">
  <section id="users-in-chat">
    <ul>
      <li><img src="images/avatar-big.png"/></li>
    </ul>
  </section>
  <section id="chat-messages">
    <ul>
      <li><img src="images/avatar-big.png" class="message-avatar"/>
        <div class="message"><span>So yeah I am good how are you? I am currently in this shit and i should finish it asap so ill t alk to you laterSo yeah I am good how are you? I am currently in this shit and i should finish it asap so ill t alk to you later</span></div>
      </li>
      <li><img src="images/avatar-big.png" class="message-avatar"/>
        <div class="message"><span>So yeah I am good how are yoly in this shit and i shou later</span></div>
      </li>
    </ul>
  </section>
</section>

和CSS:

#chat-messages ul {
    list-style: none;
    padding: 20px;
}

#chat-messages ul li {
    clear: both;
    margin-top: 15px;
}

#chat-messages ul li:first-child {
    margin-top: 0;
}

.message-avatar {
    -webkit-border-radius: 20px 20px 20px 20px;
    border-radius: 20px 20px 20px 20px;

    float: left;
}

.message {

    margin-left: 15px;

    padding: 15px;
    max-width: 70%;
    background-color: rgba(144, 195, 245, 0.3);
    -webkit-border-radius: 0 20px 20px 20px;
    border-radius: 0 20px 20px 20px;

    float: left;
}

我在那里做错了什么?

尝试这个:

 #chat-messages ul li { clear: both; margin-top: 15px; float: left; } 

#chat-messages ul li {
clear: both;
margin-top: 15px;
overflow:hidden;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM