Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.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位置,具有响应性_Html_Css_Responsive Design_Positioning - Fatal编程技术网

Html 对中div位置,具有响应性

Html 对中div位置,具有响应性,html,css,responsive-design,positioning,Html,Css,Responsive Design,Positioning,我有一个宽80%的div,还有一个宽20%。 第一个div有另一个与之相关的div,它将居中于上,我尝试添加left:50但不起作用 <div class="content"> <div class="circle"></div> </div> 下面是一个关于的示例,您需要将left设置为计算(50%-30px)将使圆水平居中 +----------------------+--------------------+ | 30p

我有一个宽80%的div,还有一个宽20%。 第一个div有另一个与之相关的div,它将居中于上,我尝试添加
left:50但不起作用

<div class="content">
   <div class="circle"></div>
</div>


下面是一个关于的示例,您需要将
left
设置为
计算(50%-30px)
将使
圆水平居中

+----------------------+--------------------+
|     30px -------·    ·                    |
|                  \ o · o                  |
|                 o |  ·    o               |
|                o<--->·     o              |
|                o     ·     o              |
|                ·o    ·    o·              |
|                ·   o · o   ·              |
|                ·     ·     ·              |
|                ·<---60px-->·              |
|                ·     ·                    |
|<--50% - 30px-->·     ·                    |
|                      ·                    |
|                      ·                    |
|<---------50%-------->·                    |
|                      ·                    |
+----------------------+--------------------+

要使
.circle
水平和垂直居中,请将
顶部:calc(50%-30px)
添加到
.circle


您需要将
left
设置为
calc(50%-30px)
将使
圆水平居中

+----------------------+--------------------+
|     30px -------·    ·                    |
|                  \ o · o                  |
|                 o |  ·    o               |
|                o<--->·     o              |
|                o     ·     o              |
|                ·o    ·    o·              |
|                ·   o · o   ·              |
|                ·     ·     ·              |
|                ·<---60px-->·              |
|                ·     ·                    |
|<--50% - 30px-->·     ·                    |
|                      ·                    |
|                      ·                    |
|<---------50%-------->·                    |
|                      ·                    |
+----------------------+--------------------+

要使
.circle
水平和垂直居中,请将
顶部:calc(50%-30px)
添加到
.circle


将第二个div设置为对左右边距使用带有“auto”的相对定位应该会起作用:

.circle {
    width: 60px;
    height: 60px;
    position: relative;
    top: -15px;
    margin: 0 auto;
    background-color: #aaa;
    border-radius: 50%;
}

将第二个div设置为对左右边距使用“auto”的相对定位应该会起作用:

.circle {
    width: 60px;
    height: 60px;
    position: relative;
    top: -15px;
    margin: 0 auto;
    background-color: #aaa;
    border-radius: 50%;
}

设置
负数
左边距
宽度的一半。圆圈

.circle {
    width: 60px;
    height: 60px;
    position: absolute;
    top: -15px;
    left: 50%;
    margin-left:-30px;
    right: 50%;
    background-color: #aaa;
    border-radius: 50%;
}

演示-

负片
左边距
设置为
宽度的一半。圆圈

.circle {
    width: 60px;
    height: 60px;
    position: absolute;
    top: -15px;
    left: 50%;
    margin-left:-30px;
    right: 50%;
    background-color: #aaa;
    border-radius: 50%;
}

演示-

制作
。圈出
内联块
,并给它适当的边距

.container {
    text-align:center;
}
.circle {
    margin:-15px auto 0 auto;
    display:inline-block;
}

制作
。圈出
内联块
,并给它适当的边距

.container {
    text-align:center;
}
.circle {
    margin:-15px auto 0 auto;
    display:inline-block;
}

为什么是30px?什么意思?@user3003810-它是
.circle
/
2
)的(
width
)-->
60/2=30
谢谢你的详细回答:)@user3003810-不客气。@user3003810-很乐意帮忙:)为什么是30px?什么意思?@user3003810-它是
.circle
/
2
)的(
width
)-->
60/2=30
谢谢你的详细回答:)@user3003810-不客气。@user3003810-很高兴帮助:)