【问题标题】:Trouble with CSS format [closed]CSS格式的问题[关闭]
【发布时间】:2014-03-01 04:33:27
【问题描述】:

我这辈子都无法找出 CSS 代码有什么问题,我无法将 main <p> 中的字体设为 20 像素,并且无法将地址正确居中在页脚中。我只能编辑 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;
     }

【问题讨论】:

  • 请在您的问题中发布相关代码。

标签: html css notepad++ sections


【解决方案1】:

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

但是,由于您的侧边有 200 像素的静态宽度,我们可以将其作为边距添加到页脚>地址中,以便相应地居中内容。

所以,我们要的页脚地址是:

margin-right:200px;

但是既然我们已经有了

margin-top:25px;

我们可以只删除顶部边距线并同时使用:

margin:25px 200px 0 0;

这是margin top 25px right 200px bottom 0 left 0的简写。

最后,正确的发布方式是在 JSFiddle 上,这很容易弄清楚,我把我的解决方案放在这里:

http://jsfiddle.net/R8Hsv/

【讨论】:

  • 谢谢!你是一个真正的救星我已经被这个特殊问题困扰了一周
【解决方案2】:

所有关于你的字体大小似乎都很好,至少我可以改变它。你觉得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/

【讨论】:

  • 我有点困惑,因为在完成项目的图片中,字体看起来比我的小很多
  • @user3273012 好的,我明白了,px 和 pt 以及 indesign 和浏览器等不同的编辑器存在差异,希望对您有所帮助。 ;)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-09-04
  • 2011-02-12
  • 2018-10-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多