CSS格式的麻烦

时间:2014-02-04 23:10:32

标签: html css notepad++ sections

我不知道我的生活中发现CSS代码有什么问题,我不能让主<p>中的字体为20px并且无法正确地将页脚放在页脚中心。我只允许编辑css文件。

Html文件: http://www.mediafire.com/view/68bcokhw6tb086g/redball.htm

CSS文件: http://www.mediafire.com/view/9rk9dracsz47sn7/pizza.css

CSS代码:

/*
New Perspectives on HTML and CSS
Tutorial 4
Case Problem 2

Pizza Style Sheet
Author: Joesph Aguilar
Date: 01/31/2014  

Filename:         pizza.css
Supporting Files: 

*/

 /* Display Block Elements */
header, section, aside, footer, nav{
 display: block;
}

/* Padding and Margin Style */
*{
 padding: 0px;
 margin: 0px;
 }

/* Body Style */
body{
 background-color: red;
 font-family: Verdana, Geneva, sans-serif;
}

/* Container Style */
#container{
 width: 1000px;
 margin-top: 0px;
 margin-bottom: 0px;
 margin-left: auto;
 margin-right: auto;
 border-left: 1px solid black;
 border-right: 1px solid black;
 background: white url('redbar.png') repeat-y left top;
}

/*Header Style */
header{
 background-color: white;
 height: 100px;
}

/* Horizontal Nav Style */
nav.horizontal{
 background-color: white;
 height: 70px;
 width: 100%;
}
nav.horizontal li{
 background-color: white;
 font-size: 16px;
 height: 50px;
 line-height: 50px;
 width: 180px;
 display: block;
 float: left;
 margin-left: 5px;
 margin-right: 5px;
 text-align: center;
}
nav.horizontal li a{
 display: block;
 background-color: red;
 color: white;
 border-radius: 30px / 25px;
 -moz-border-radius: 30px / 25px;
 -webkit-border-radius: 30px / 25px;
 text-decoration: none;
}
nav.horizontal li a:hover{
 background-color: (255, 101, 101);
 color: black;
}

/* Vertical Nav Style */
nav.vertical{
 clear: left;
 float: left;
 width: 200px;
}
 nav.vertical li{
 list-style-type: none;
 text-indent: 20px;
 margin-top: 20px;
 margin-bottom: 20px;
}
nav.vertical li a{
 color: white;
 text-decoration: none;
}
nav.vertical li a:hover{
 color: black;
}

/* Section Style */
#main{
 background-color: rgb(255, 211, 211);
 float: left;
 width: 600px;
}
#main > p {
 font-size: 20px;
 margin: 15px;
}
#main img{
 float: right;
 margin: 15px;
 width: 350px;
 border-bottom-left-radius: 350px;
 -moz-border-radius-bottomleft: 350px;
 -webkit-bottom-left-radius: 350px;
}

/* Coupon Style */
#main div.coupon{
 border: 5px;
 border-style: dashed;
 float: left;
 width: 170px;
 height: 150px;
 margin-top: 20px;
 margin-bottom: 20px;
 margin-left: 10px;
 margin-right: 10px;
 background: white url('slice.png') no-repeat right bottom;
}
#main div.coupon h1{
 color: white;
 background: rgb(192, 0, 0);
 font-size: 16px;
 letter-spacing: 2px;
 text-align: center;
 height: 25px;
 font-variant: small-caps;
}
#main div.coupon p{
 font-size: 14px;
 text-align: center;
 margin: 5px;
}

/* Aside Style */
aside{
 float: left;
 width: 200px;
}
aside h1{
 color: rgb(192, 0, 0);
 font-size: 20px;
 letter-spacing: 2px;
 font-weight: normal;
 text-align: center;
}
aside li{
 background-color: rgb(255, 135, 135);
 border-radius: 5px;
 list-style-type: none;
 margin: 10px;
 padding: 5px;
}

/*Footer Style*/
footer{
 clear: left;
 margin-left: 200px;
}
footer address{
 border-top-style: 1px solid red top;
 color: red;
 font-size: 10px;
 font-style: normal;
 text-align: center;
 margin-top: 25px;
 padding-bottom: 20px;
     }

2 个答案:

答案 0 :(得分:0)

地址位于页脚中心。您的问题是您希望地址位于#main部分,而页脚不在#main部分,它位于div#container中,导致地址以整个容器为中心。

但是,由于您的静态宽度为200px,我们可以将其作为页边距添加到页脚&gt;地址中,以便相应地对内容进行居中。

所以,我们希望页脚地址是:

margin-right:200px;

但是因为我们已经有了

margin-top:25px;

我们可以删除该边距顶线并同时说:

margin:25px 200px 0 0;

这是保证金前25px右200px底部0左0的简写。

最后,发布这个的正确方法是JSFiddle,这很容易理解,我在这里提出了我的解决方案:

http://jsfiddle.net/R8Hsv/

答案 1 :(得分:0)

所有关于你的字体大小似乎都很好,至少我可以改变它。您如何期待20px

必须为页脚设置宽度,与main相同。

footer address{
 border-top-style: 1px solid red top;
 color: red;
 font-size: 10px;
 font-style: normal;
 text-align: center;
 margin-top: 25px;
 padding-bottom: 20px;
 width:600px;
}

JSFIDDLE:http://jsfiddle.net/42h96/1/