这些编码风格是否正确?

时间:2015-09-25 11:12:16

标签: html css

我刚开始学习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>	&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
<a href=click.php style="text-decoration: none; color:white">Please Click Here</a>	&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
<a href=contact.php style="text-decoration: none; color:white">Contact</a>	&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
<a href=about.php style="text-decoration: none; color:white">About Me</a></p></center>
    
</style>
</div>
</div>

谢谢,

3 个答案:

答案 0 :(得分:2)

首先要注意的是..

  1. 不要使用内联CSS
  2. 不使用&nbsp;,而是使用marginpadding
  3. 边距和填充让你在两个标签之间留出空间
  4. 请参阅片段我如何实施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>

答案 1 :(得分:1)

注意事项:

  1. 缺少HTML骨架。
  2. CSS可以单独使用而非内联。
  3. 而不是您需要使用边距和填充。你需要知道浮动。

答案 2 :(得分: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;}
  6. 但其余的都是正确的。

相关问题