2011-09-21 64 views
1

我正在參加HTML /網頁設計課程,並在其他一週剛剛開始。現在,這不是我第一次完成HTML,但我並沒有真正記得它。我試圖將一些Java代碼放到我的一個網頁上,作爲「展示我最近的成就」的一種方式。HTML塊格式化

所以我在尋找的是一種格式化文本塊,以便它保留所有的空白/標籤的方式。

<BODY> 
    <h1> Java Code Samples! </h1> 

    <P> Hello, and welcome to the java code sample section of my site. Here I will put some </P> 
    <P> random samples of code that I have written and projects that I have completed </P> 
    <br /> 
    <h3 align="left"> These are some random methods: </h3> 
    <p> 
    <i> //Returns index of item in other array 
     //Efficiency (O(N)) 
     public static int getOtherIndex(String searchString, College[] searchTarget) 
     { 
      for(int i = 0; i < searchTarget.length; i++) 
       if(searchString.trim().equalsIgnoreCase(searchTarget[i].nameOfSchool.trim())) 
        return i; 

      return -1; 
     } 
    </i> 
    </p> 

</BODY> 

我想以保留最初的空白區域的方式格式化該方法,但使用斜體標記使其突出顯示。

任何幫助,將不勝感激。

回答

1

您可以使用<pre>標記來執行此操作。

它保持格式相同。

例子:http://jsfiddle.net/jasongennaro/JC9ej/

據透露...更好的樣式化p標籤,而不是使用i斜體。

+0

當然,完全忘了那個標籤......謝謝! – Brendan

+0

很高興幫助@lesniakbj! –