简体   繁体   English

并排显示CSS框

[英]Display CSS boxes side by side

css code CSS代码

 #folder {  
width: 105px;
background: #BABABA;
position: relative;
 -moz-border-radius:    10px;
-webkit-border-radius: 10px;
border-radius: 0px 10px 10px 10px;
}

This is CSS code to create boxes 这是创建框的CSS代码

php code PHP代码

<link rel="stylesheet" type="text/css" href="fold.css" /></style>
<?php 
function listFolderFiles($dir,$exclude){ 
 $ffs = scandir($dir); 
echo '<ul class="ulli">'; 
foreach($ffs as $ff){ 
    if(is_array($exclude) and !in_array($ff,$exclude)){ 
        if($ff != '.' && $ff != '..'){ 
        if(!is_dir($dir.'/'.$ff)){ 

        } else { 
        echo '<div class=wrap><div id=folder><li>'.$ff.'</div></div>';    
        } 
        if(is_dir($dir.'/'.$ff)) listFolderFiles($dir.'/'.$ff,$exclude); 
        echo '</li>'; 
        } 
    } 
} 
echo '</ul>'; 
} 

listFolderFiles('.',array('index.php','edit_page.php')); 
?>

It Displays the boxes one below the other How to display the boxes side by side 它在另一个下方显示框。如何并排显示框

For side by side div element you need to add 对于并排div元素,您需要添加

float:left

in your css class will do work for you. 在您的css类中会为您工作。

Check example : DIV TABLE 查看示例: DIV TABLE

float: left;

这将并排显示框,但是您需要在框之后的项目中添加以下属性才能正确显示。

clear: both;
#folder {display: inline-block;}

#folder {float: left}

I'd say instead of doing: 我会说而不是做:

echo '<div class=wrap><div id=folder><li>'.$ff.'</div></div>';    

try: 尝试:

echo '<li><div class=wrap><div id=folder>'.$ff.'</div></div></li>';    

Making sure your < li > tag is closing correctly and wrapping your divs (or contrary, not sure what you're trying) 确保您的< li >标记正确关闭并包装了divs (或者相反,不确定您要尝试的内容)

But your code doesn't seem really clean anyways, for example use class .folder instead of id #folder since ids should be unique by definition. 但是您的代码看起来还是不太干净,例如使用class .folder而不是id #folder因为id在定义上应该是唯一的。

But i guess you gotta start somewhere, good luck :) 但是我想你得从某个地方开始,祝你好运:)

divs are block elements by default. divs默认是块元素。

these elements consume all available width. 这些元素消耗所有可用宽度。

Even if you set a width to them, the margin will get the rest. 即使您为它们设置了宽度,边距也会得到其余部分。

You can change this behavior by any of these methods: 您可以通过以下任何一种方法来更改此行为:

  • setting the display property from display: block to display:inline or display:inline-block 从display:block设置display属性,设置为display:inline或display:inline-block
  • floating the element with float:left or float:right 用float:left或float:right浮动元素
  • position the div manually with position: absolute 手动将div的位置设置为:absolute

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

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