2015-09-25 111 views
-1

我刚开始学习CSS并在本地门户网站上创建了一个示例页面。我想知道这些编码风格是否正确。这些编码风格是否正确?

我开始知道这些编码风格在主要程度上不起作用。

你能纠正我的代码,使它更可行,我会尝试学习一些你的编码风格,并会适应我的方便。

很抱歉,如果这些问题不能在本网站上提出。

<div class="initial"> 
 

 
<div style="position:relative; width:100%; margin-Top: 4.75%; font-size: 1.3em; font-family: Helvetica; text-align: center; background-color: #bbb;"> 
 
<center><p style='line-height:200%'> 
 

 
<a href=h.php style="text-decoration: none; color:white"> Home</a> \t &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
 
<a href=click.php style="text-decoration: none; color:white">Please Click Here</a> \t &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
 
<a href=contact.php style="text-decoration: none; color:white">Contact</a> \t &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
 
<a href=about.php style="text-decoration: none; color:white">About Me</a></p></center> 
 
    
 
</style> 
 
</div> 
 
</div>

感谢,

+0

不要在一个文件中混合使用HTML和CSS;将缩进应用于您的代码,以便阅读;不要使用 进行布局(改为使用样式)。 – akasummer

+3

如果你想要代码审查,使用代码审查http://codereview.stackexchange.com/ – Neoaptt

+0

对于这种线我可以混合CSS和HTML不是吗? Novice

回答

2

在要注意的第一点..

  1. 不要使用,而不是使用&nbsp;兼用marginpadding
  2. 的内联CSS
  3. 保证金和填充让我们提供两个之间的空间标签

查看片段我如何实施padding

.initial-content { 
 
    position: relative; 
 
    width: 100%; 
 
    margin-Top: 4.75%; 
 
    font-size: 1.3em; 
 
    font-family: Helvetica; 
 
    text-align: center; 
 
    background-color: #bbb; 
 
} 
 
p { 
 
    line-height: 200%; 
 
} 
 
a { 
 
    text-decoration: none; 
 
    color: white; 
 
    padding: 5px 25px; 
 
}
<div class="initial"> 
 

 
    <div class="initial-content"> 
 
    <center> 
 
     <p> 
 

 
     <a href=h.php> Home</a> 
 
     <a href=click.php>Please Click Here</a> 
 
     <a href=contact.php>Contact</a> 
 
     <a href=about.php>About Me</a> 
 
     </p> 
 
    </center> 
 

 
    </div> 
 
</div>

+0

感谢您根据类型的详细代码。 – Novice

1

注意事项:

  1. HTML框架缺失。
  2. CSS可以单独使用,而是内联使用。
  3. 而不是nbsp你需要使用边距和填充。你需要知道浮点数。
+0

感谢您的分享。现在将工作在边缘,但我想知道为什么要在此代码中使用填充属性? – Novice

+0

@Novice像这样想:“我想传递给用户什么信息?” - 你的HTML应该回答这个问题。 “我想让它看起来像什么?” - 使用CSS来实现。 – akasummer

+0

@Novice在这个例子中,你使用' '作为视觉目的,这应该是你的触发器,用正确的CSS代替它 – akasummer

0

好吧,如果它没有在大范围的工作“,回答你一半的问题:它意味着它是不正确的。什么是不正确的:

  1. 内联CSS应该可以正常工作,您可以使用它进行测试。但你应该使用一个css文件。使用标识符如ID和类。
  2. href属性值必须在引号或双引号内。
  3. </style>关闭不关闭任何东西。您可以在这些标签中使用css代码,但更适合使用.css文件。
  4. &nbsp;事情:使用定位css。例如,如果要将项目垂直对齐,则可以使用item{clear:left;float:left;}
  5. <center>标记已被弃用。 Why?改用:<div class="centered(or whatever you feel like calling it)">和风采吧:.centered{width: 60%;margin:auto;}

但剩下的只是正确的。