垂直和水平div定心和高效css
对于网页设计来说,这是一个非常新的概念,我认为创建一个带有页眉、段落和粘性页脚的网站的基本模型是一个好主意,以确保我已经掌握了一些基本知识:) 我想知道如何将.paragration div垂直和水平居中,以及我应该注意的代码是否存在任何明显的问题或效率低下。我只是想确保我能在不养成坏习惯的情况下编写基本布局 所以我最终得到了这个css:垂直和水平div定心和高效css,css,header,alignment,footer,centering,Css,Header,Alignment,Footer,Centering,对于网页设计来说,这是一个非常新的概念,我认为创建一个带有页眉、段落和粘性页脚的网站的基本模型是一个好主意,以确保我已经掌握了一些基本知识:) 我想知道如何将.paragration div垂直和水平居中,以及我应该注意的代码是否存在任何明显的问题或效率低下。我只是想确保我能在不养成坏习惯的情况下编写基本布局 所以我最终得到了这个css: .head { margin: auto; height: 100%; width: 100%; background-color: #000; color:
.head {
margin: auto;
height: 100%;
width: 100%;
background-color: #000;
color:white;
text-align:center;}
body {
background-color:#99C;
}
.h1 {
font-size:50px;
font-family:Georgia, "Times New Roman", Times, serif;
padding:30px;
}
.paragraph {
color:#FFF;
text-align:center;
background-color:#333;
width:35%;
margin:auto;
margin-top:165px;
padding:10px;
}
* {
margin: 0;
}
html, body {
height: 100%;
}
.wrapper {
min-height: 100%;
/* equal to footer height */
margin-bottom: -70px;
}
.wrapper:after {
content: "";
display: block;
}
.site-footer, .wrapper:after {
/* .push must be the same height as footer */
height: 70px;
}
.site-footer {
background: orange;
text-align:center;
font-family:Arial, Helvetica, sans-serif;
font-size:40px;
line-height:70px;
}
下面是它的外观:
提前感谢
Adam H如果出于某种原因需要更改页眉/页脚高度,该怎么办? 您需要在CSS中修改多个规则,以保持您想要的布局 这里的布局与您想要的相同,没有固定任何高度,使用纯CSS。 HTML:
<div class="Container">
<div class="Header">
<p>I'm in the header</p>
<p>my height is not fixed</p>
</div>
<div class="HeightTaker">
<div class="Wrapper Container Inverse">
<div>
<div class="Footer">
<p>I'm in the footer</p>
<p>my height is not fixed</p>
</div>
</div>
<div class="HeightTaker">
<div class="Wrapper">
<div class="Content">
<div>
<p>I'm in the content</p>
<p>I always span the rest of the page.</p>
<p>If my content is bigger than my available space, I will scroll</p>
<p>This Layout has been tested on: IE10, FireFox, Chrome, Safari, Opera using Pure CSS only</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
*
{
margin: 0;
padding: 0;
}
html, body, .Container
{
height: 100%;
}
.Container:before
{
content: '';
height: 100%;
float: left;
}
.HeightTaker
{
position: relative;
z-index: 1;
}
.HeightTaker:after
{
content: '';
clear: both;
display: block;
}
.Wrapper
{
position: absolute;
width: 100%;
height: 100%;
}
.Inverse, .Inverse > *
{
-moz-transform: rotateX(180deg);
-ms-transform: rotateX(180deg);
-o-transform: rotate(180deg);
-webkit-transform: rotateX(180deg);
transform: rotateX(180deg);
}
.Header
{
/*for demonstration only*/
background-color: #bf5b5b;
}
.Content
{
height: 100%;
overflow: auto;
text-align: center;
font-size: 0;
/*for demonstration only*/
background-color: #90adc1;
}
.Content:after
{
content: '';
display: inline-block;
height: 100%;
vertical-align: middle;
}
.Content > div
{
font-size: medium;
display: inline-block;
vertical-align: middle;
}
.Footer
{
/*for demonstration only*/
background-color: #b5a8b7;
}
注意:我的方法唯一的缺点是,我必须在内容之前构造页脚(在HTML中)。那么你的问题是什么?这张图片没有显示问题。我相信你会得到一些有用的答案,但我想补充一下。。就高效代码而言,每个网站的代码都有所不同。这是应该学习的主要技能,更改代码以适应各种情况。浏览器支持是一个需要考虑的大问题,并确保代码在您希望用户使用的浏览器上正常工作。祝你好运和快乐!主要是我想知道如何在正文中垂直居中段落div,我在这里和其他地方查看了其他帖子,我有点惊讶,我能找到的唯一解决方案是在你想要居中的段落周围添加额外的容器div。对我来说似乎很疯狂,但无论如何谢谢你的帮助!啊,好吧,这很有趣,我有点搞砸了,看看发生了什么,我将在早上继续(我在英国,这里像凌晨1点)。只是想知道,如果没有“.Inverse、.Inverse>*”webkits等,页脚会出现在内容上方,但我不知道为什么。这项技术的作用是什么?仅当您尝试拉伸容器中的最后一个元素时,才可以拉伸内容以获取其父元素的所有可用高度。因此,我必须使中间的div位于HTML中容器的最后一个,然后使用CSS在视图中反转它。