Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/40.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 - Fatal编程技术网

Html 浮动中的垂直中心div

Html 浮动中的垂直中心div,html,css,Html,Css,我在.container div中有两列:它们是百分比宽度和浮动的左侧。我需要这些浮动的内容是垂直和水平居中的。它们是动态高度,可能会发生变化。我希望避免使用jQuery。有人知道一个简单的方法吗 CSS: HTML: 40%——Lorem ipsum Door sit amet,奉献精英。除了在实验室工作人员方面的特殊情况外,在临时状态下的错误情况减去在实验室工作人员方面的错误情况 60%——Lorem ipsum dolor sit amet,奉献精英。德莱克特斯·韦尔多勒姆。这是一个伟

我在
.container div
中有两列:它们是
百分比
宽度和浮动的
左侧
。我需要这些浮动的内容是垂直和水平居中的。它们是动态高度,可能会发生变化。我希望避免使用jQuery。有人知道一个简单的方法吗

CSS:

HTML:


40%——Lorem ipsum Door sit amet,奉献精英。除了在实验室工作人员方面的特殊情况外,在临时状态下的错误情况减去在实验室工作人员方面的错误情况

60%——Lorem ipsum dolor sit amet,奉献精英。德莱克特斯·韦尔多勒姆。这是一个伟大的建筑设计师杜西莫斯发明者的作品,他在作品中运用了大量的艺术元素。莫迪的罪过

CSS

如果你想水平居中,它们的总数已经达到100%(40+60),所以我不完全确定你在这里要找什么。

CSS

如果你想水平居中,它们的总数已经达到100%(40+60),所以我不完全确定你在这里要找什么。

CSS

如果你想水平居中,它们的总数已经达到100%(40+60),所以我不完全确定你在这里要找什么。

CSS

如果你想水平居中,它们的总数已经达到100%(40+60),所以我不完全确定你在这里要找什么。

试试这个:

我想这就是你想要的,对吧

p {
    width: 13em;
    background-color: salmon;
    margin: 0 auto;
    margin-top: 100px;
}
试试这个:

我想这就是你想要的,对吧

p {
    width: 13em;
    background-color: salmon;
    margin: 0 auto;
    margin-top: 100px;
}
试试这个:

我想这就是你想要的,对吧

p {
    width: 13em;
    background-color: salmon;
    margin: 0 auto;
    margin-top: 100px;
}
试试这个:

我想这就是你想要的,对吧

p {
    width: 13em;
    background-color: salmon;
    margin: 0 auto;
    margin-top: 100px;
}

display:table
是一种新的趋势,可以避免
float
s,因为以后需要
清除它们:)

CSS

html, body {
    width: 100%;
    height: 100%;
    margin:0;
    padding:0;
}
.container {
    width: 600px;
    background-color: lightgrey;
    overflow: auto;
    height: 400px; /* or "100%" if container needs to be full-height*/
    display:table;        /* added*/
}
.col40 {
    width: 40%;
    height: 100%;
    background-color: green;
    display:table-cell;        /* added*/
    vertical-align:middle;        /* added*/
}
.col60 {
    width: 60%;
    background-color: blue;
    height: 100%;
    display:table-cell;        /* added*/
    vertical-align:middle;        /* added*/
}
p {
    width: 13em;
    margin:0 auto; /* added to center the content*/
    text-align:center;        /* added - optional */
    background-color: salmon;
}

display:table
是一种新的趋势,可以避免
float
s,因为以后需要
清除它们:)

CSS

html, body {
    width: 100%;
    height: 100%;
    margin:0;
    padding:0;
}
.container {
    width: 600px;
    background-color: lightgrey;
    overflow: auto;
    height: 400px; /* or "100%" if container needs to be full-height*/
    display:table;        /* added*/
}
.col40 {
    width: 40%;
    height: 100%;
    background-color: green;
    display:table-cell;        /* added*/
    vertical-align:middle;        /* added*/
}
.col60 {
    width: 60%;
    background-color: blue;
    height: 100%;
    display:table-cell;        /* added*/
    vertical-align:middle;        /* added*/
}
p {
    width: 13em;
    margin:0 auto; /* added to center the content*/
    text-align:center;        /* added - optional */
    background-color: salmon;
}

display:table
是一种新的趋势,可以避免
float
s,因为以后需要
清除它们:)

CSS

html, body {
    width: 100%;
    height: 100%;
    margin:0;
    padding:0;
}
.container {
    width: 600px;
    background-color: lightgrey;
    overflow: auto;
    height: 400px; /* or "100%" if container needs to be full-height*/
    display:table;        /* added*/
}
.col40 {
    width: 40%;
    height: 100%;
    background-color: green;
    display:table-cell;        /* added*/
    vertical-align:middle;        /* added*/
}
.col60 {
    width: 60%;
    background-color: blue;
    height: 100%;
    display:table-cell;        /* added*/
    vertical-align:middle;        /* added*/
}
p {
    width: 13em;
    margin:0 auto; /* added to center the content*/
    text-align:center;        /* added - optional */
    background-color: salmon;
}

display:table
是一种新的趋势,可以避免
float
s,因为以后需要
清除它们:)

CSS

html, body {
    width: 100%;
    height: 100%;
    margin:0;
    padding:0;
}
.container {
    width: 600px;
    background-color: lightgrey;
    overflow: auto;
    height: 400px; /* or "100%" if container needs to be full-height*/
    display:table;        /* added*/
}
.col40 {
    width: 40%;
    height: 100%;
    background-color: green;
    display:table-cell;        /* added*/
    vertical-align:middle;        /* added*/
}
.col60 {
    width: 60%;
    background-color: blue;
    height: 100%;
    display:table-cell;        /* added*/
    vertical-align:middle;        /* added*/
}
p {
    width: 13em;
    margin:0 auto; /* added to center the content*/
    text-align:center;        /* added - optional */
    background-color: salmon;
}


谢谢-有没有办法确保.container始终是浏览器窗口的100%高度?谢谢-有没有办法确保.container始终是浏览器窗口的100%高度?谢谢-有没有办法确保.container始终是浏览器窗口的100%高度?谢谢-有没有办法确保.container始终是浏览器窗口的100%高度?以下是以上解决方案的摘要:D我建议使用该解决方案。@Sven:已对您的答案进行了优化,但您的解决方案缺少水平中心部分…我已添加了该部分…无需进行比较,伙计!!:)这很好,但当我还添加“宽度:100%”时对容器来说,它似乎去除了100%的高度?@tmyie:小提琴看起来不错……如果你拿出你的小提琴,我也许可以帮你解决!!:)哦,对不起。我误解了我自己的代码。当我在列中插入图像时,它会删除100%的高度?这是上面解决方案的摘要:D我建议使用该解决方案。@Sven:已经对您的答案进行了优化,但您的解决方案缺少水平中心部分…我已经添加了…无需进行比较,伙计!!:)这很好,但当我还添加“宽度:100%”时对容器来说,它似乎去除了100%的高度?@tmyie:小提琴看起来不错……如果你拿出你的小提琴,我也许可以帮你解决!!:)哦,对不起。我误解了我自己的代码。当我在列中插入图像时,它会删除100%的高度?这是上面解决方案的摘要:D我建议使用该解决方案。@Sven:已经对您的答案进行了优化,但您的解决方案缺少水平中心部分…我已经添加了…无需进行比较,伙计!!:)这很好,但当我还添加“宽度:100%”时对容器来说,它似乎去除了100%的高度?@tmyie:小提琴看起来不错……如果你拿出你的小提琴,我也许可以帮你解决!!:)哦,对不起。我误解了我自己的代码。当我在列中插入图像时,它会删除100%的高度?这是上面解决方案的摘要:D我建议使用该解决方案。@Sven:已经对您的答案进行了优化,但您的解决方案缺少水平中心部分…我已经添加了…无需进行比较,伙计!!:)这很好,但当我还添加“宽度:100%”时对容器来说,它似乎去除了100%的高度?@tmyie:小提琴看起来不错……如果你拿出你的小提琴,我也许可以帮你解决!!:)哦,对不起。我误解了我自己的代码。当我将图像插入到列中时,它会删除100%的高度?