Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.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
Html 如何使用两个div设置容器的宽度';s_Html_Css - Fatal编程技术网

Html 如何使用两个div设置容器的宽度';s

Html 如何使用两个div设置容器的宽度';s,html,css,Html,Css,我想为两个div制作一个“容器”,但我不知道如何设置它的宽度 HTML代码: <div id="controller"><!-- i use it to center div's --> <!-- i think set start of container here (id="container") --> <div id="first">Some Content</div> <div i

我想为两个div制作一个“容器”,但我不知道如何设置它的宽度

HTML代码:

<div id="controller"><!-- i use it to center div's -->
    <!-- i think set start of container here (id="container") -->
        <div id="first">Some Content</div>
        <div id="second">Some Content</div>
    <!-- and end here -->
</div>
如果您的问题是环绕div使用了整个可用宽度,并且您只希望它环绕两个内部div:

这是因为div的默认值是display:block

要使它只占用两个内部div的宽度,您可以将其设置为display:inline block,但有十几种方法可以做到这一点

例如:

#controller {
    width: auto;
    height: auto;
    text-align: center;
    background: yellow;
    display: inline-block;
}

或者看看我为这个例子创建的代码笔:

Set
margin:auto对于
#控制器
,请检查以下代码

#控制器{
高度:自动;
保证金:自动;
文本对齐:居中;
}
#首先{
显示:内联块;
垂直对齐:顶部;
宽度:100px;
高度:500px;
背景颜色:绿色;
}
#第二{
显示:内联块;
垂直对齐:顶部;
宽度:200px;
高度:500px;
背景色:红色;
}

一些内容
一些内容

您的问题含糊不清,请具体一点。设置宽度的目的是什么?容器应该是什么样子的?这个控制器在中心设置div关闭它,我找到了答案
#controller {
    width: auto;
    height: auto;
    text-align: center;
    background: yellow;
    display: inline-block;
}