Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CSS/HTML如何将两个块相邻放置_Html_Css - Fatal编程技术网

CSS/HTML如何将两个块相邻放置

CSS/HTML如何将两个块相邻放置,html,css,Html,Css,我想知道我怎么能把这两个街区放在一起,“新闻”和“热门项目”,我试了好几次,但都没有成功 HTML <div class="topMsg"> <h2> News</h2> <a>lorem</a> </div> <div class="popMsg"> <h2>Popular Projects</h2> <h3>Skin Selector<

我想知道我怎么能把这两个街区放在一起,“新闻”和“热门项目”,我试了好几次,但都没有成功

HTML

<div class="topMsg">
    <h2> News</h2>
    <a>lorem</a>
</div>
<div class="popMsg">
    <h2>Popular Projects</h2>
    <h3>Skin Selector</h3>
    <a> Elorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsum</a>
</div>

如果有足够的空间让它们彼此相邻(边距/填充也算空间!),你可以简单地
float:left它们。

您可以显示:内联块;to.topMsg和popMsg

 .topMsg{

    width:400px;
    margin:100px 50px;
    text-align:justify;
        display:inline-block;
   }

 .popMsg{

    width:250px;
    margin:100px 50px;
    text-align:justify;
        display:inline-block;
   }

将此CSS代码添加到元素:

.popMsg{ float:left; }

基本上,DIV元素位于
display:block

您只需要更改“.popMsg”和“.topMsg”div的显示


在CSS的末尾放置以下行:

    div.topMsg { float:left; }
    div.popMsg { float:right; }
    div.footer { clear:both; }

现在它是你想要的左和右

这个点应该是什么意思?
.topMsg.popMsg{float:left;}
浮动,
display:table cell
display:inline block
,flexbox:有很多方法可以定位它们,如果你搜索一个liitleFirst CSS代码,就会得到很多答案:只要一个元素浮动,无论您尝试设置的值是什么,display的计算值都将是block per definition。只要尝试使用不同的值,就可以看到它没有效果。CSS2.1 REC(除了table和inline table、run in和none)我用于为浮点元素设置display:inline。它纠正了IE6中出现的“双边距错误”(我仍然在IE6上有客户端…),然后使用条件注释、类或至少一个hack。第二个CSS代码在IE6中如何工作?你说得对。第二个CSS代码不适用于IE6(我想还有IE7)。
.popMsg, .topMsg{
   display:inline; 
   float:left;
}
.popMsg, .topMsg{
   display:inline-block;
}
    div.topMsg { float:left; }
    div.popMsg { float:right; }
    div.footer { clear:both; }