2015-11-05 52 views
-1

我的iframe有問題。在頂部有一個酒吧,左邊有一個用於放置HTML的textarea。我也有兩個textarea用於放置CSS和JS,但他們有display:none。然後,我想在左邊的一個iframe中,我可以看到我放入的所有東西的結果。但是,iframe是HTML文本區下的所有內容。我試圖改變我的iframe的位置,但是當我讓我的窗口變大時,它總是在其他地方。我將顯示我的所有代碼,因爲我可能在其他地方犯了一個錯誤。我的代碼管理器中的一個奇怪的地方我的iframe

<script> 
 
    var height=$(window).height()-40; 
 
    $(".codecontainer").height(height+"px"); 
 
</script>
<!doctype html> 
 
<html> 
 
<head> 
 
<title>CodePlayer</title> 
 
<meta charset="utf-8" /> 
 
<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> 
 
<meta name="viewport" content="width=device-width, initial-scale=1" /> 
 

 
    \t <script src="http://code.jquery.com/jquery-1.10.2.js"></script> 
 

 
    \t <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jqueryui.min.js"></script> 
 

 
    \t <style> 
 
\t \t * { 
 
\t \t \t \t font-family: "HelveticaNeue-Light", "Helvetica Neue Light", 
 
\t \t "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; 
 
\t \t \t \t margin:0; 
 
\t \t \t \t padding:0; 
 
\t \t } 
 
\t \t \t \t 
 
\t \t body, html { 
 
\t \t \t \t height:100%; 
 
\t \t \t \t width:100%; 
 
\t \t } 
 
\t \t #container { 
 
\t \t \t \t height:100%; 
 
\t \t } 
 
\t \t \t \t 
 
\t \t #titlebar { 
 
\t \t \t width:100%; 
 
\t \t \t background-color:#EEEEEE; 
 
\t \t \t border-bottom:1px solid grey; 
 
\t \t \t height:40px; 
 
\t \t } 
 

 
\t \t #title { 
 
\t \t \t padding:10px 0 0 20px; 
 
\t \t \t font-weight:bold; 
 
\t \t \t float:left; 
 
\t \t } 
 

 
\t \t #menu { 
 
\t \t \t margin:0 auto; 
 
\t \t \t width:220px; 
 
\t \t \t padding:5px; 
 
\t \t } 
 
\t \t 
 
\t \t #menu ul { 
 
\t \t \t border:1px solid grey; 
 
\t \t \t border-radius:5px; 
 
\t \t \t height:30px; 
 
\t \t } 
 

 
\t \t #menu li { 
 
\t \t \t float:left; 
 
\t \t \t list-style:none; 
 
\t \t \t border-right:1px solid grey; 
 
\t \t \t height:20px; 
 
\t \t \t padding:5px 10px; 
 
\t \t } 
 

 
\t \t #menu li:hover { 
 
\t \t \t background-color:grey; 
 
\t \t } 
 

 
\t \t #result{ 
 
\t \t \t position: relative; 
 
\t \t \t top: -30px; 
 
\t \t \t left: 153px; 
 
\t \t \t border-right: 1px solid white; 
 
\t \t } 
 

 
\t \t #runButton{ 
 
\t \t \t float: right; 
 
\t \t \t position: relative; 
 

 
\t \t } 
 

 
\t \t #run{ 
 
\t \t \t padding: 10px 15px 10px 15px; 
 
\t \t \t border:none; 
 
\t \t \t border-radius: 10px; 
 
\t \t } 
 

 
\t \t #run:hover{ 
 
\t \t \t background-color:grey; 
 
\t \t } 
 

 
\t \t .break { 
 
\t \t \t clear:both; 
 
\t \t } 
 

 
\t \t .codecontainer{ 
 
\t \t \t width:49%; 
 
\t \t \t float:left; \t \t 
 
\t \t \t position:relative; 
 
\t \t \t top: -24px; 
 
\t \t \t height: 100%; 
 
\t \t } 
 

 
\t \t .codecontainer textarea{ 
 
\t \t \t width: 100%; 
 
\t \t \t height: 100%; 
 
\t \t \t border:none; 
 
\t \t \t border-right: 1px solid grey; 
 
\t \t \t font-family: monotype; 
 
\t \t \t font-size: 120%; 
 
\t \t \t padding:4px; 
 
\t \t } 
 

 
\t \t .codeLabel{ 
 
\t \t \t border:1px grey solid; 
 
\t \t \t width: 50px; 
 
\t \t \t position: absolute; 
 
\t \t \t top: 20px; 
 
\t \t \t right: 10px; 
 
\t \t \t padding: 5px 5px 5px 5px; 
 
\t \t \t border-radius: 5px; 
 
\t \t } 
 

 
\t \t #cssContainer, #jsContainer{ 
 
\t \t \t display: none; 
 
\t \t } 
 

 
\t \t iframe{ 
 
\t \t \t height: 100%; 
 
\t \t \t width: 100%; 
 
\t \t \t margin: 0; 
 
\t \t \t float: left; 
 
\t \t } 
 

 
    \t </style> 
 
\t 
 
</head> 
 
<body> 
 
\t <div id="container"> 
 
\t \t <div id="titlebar"> 
 
\t \t \t <div id="title"> 
 
\t \t \t \t \t CodePlayer 
 
\t \t \t </div> 
 
\t \t \t \t \t 
 
\t \t \t <div id="runButton"> 
 
\t \t \t \t \t \t 
 
\t \t \t \t \t <button id="run">Run</button> 
 
\t \t \t \t \t 
 
\t \t \t </div> 
 
\t \t \t \t \t 
 
\t \t \t <div id="menu"> 
 
\t \t \t \t \t <ul> 
 
\t \t \t \t \t \t <li>HTML</li> 
 
\t \t \t \t \t \t <li>CSS</li> 
 
\t \t \t \t \t \t <li>JS</li> 
 
\t \t \t \t \t \t <li style="border:none" id="result">Result</li> 
 
\t \t \t \t \t </ul> 
 
\t \t \t </div> 
 
\t \t \t \t \t 
 
\t \t \t \t \t 
 
\t \t \t \t \t 
 
\t \t </div> 
 
\t \t \t \t \t 
 
\t \t <div class="break"></div> 
 
\t \t \t \t \t 
 
\t \t <div class="codecontainer" id="htmlContainer"> 
 

 
\t \t \t <span class="codeLabel">HTML</span> 
 

 
\t \t \t <textarea>Example code</textarea> 
 

 
\t \t <div class="codecontainer" id="cssContainer"> 
 

 
\t \t \t <span class="codeLabel">CSS</span> 
 

 
\t \t \t <textarea>Example code</textarea> 
 
\t \t \t \t \t 
 
\t \t </div> 
 

 
\t \t <div class="codecontainer" id="jsContainer"> 
 

 
\t \t \t <span class="codeLabel">JS</span> 
 

 
\t \t \t <textarea>Example code</textarea> 
 
\t \t \t \t \t 
 
\t \t </div> 
 

 
\t \t <div class="codecontainer" id="resultContainer"> 
 

 
\t \t \t <span class="codeLabel">Result</span> 
 

 
\t \t \t <iframe></iframe> 
 
\t \t \t \t \t 
 
\t \t </div> 
 

 
\t </div> 
 
</body> 
 
</html>

+0

可以請你告訴我們你真正實現?你的問題不是很清楚。 –

+0

對不起,這個錯誤。我希望我的iframe也是窗口的一半,在textarea旁邊放置HTML。 – RVDE

+0

檢查我的答案 –

回答

0

錯就錯在你的HTML標籤,你的第一個codecontainer

<div class="codecontainer" id="htmlContainer"> 

下面的內容之後沒有關閉,所以它包裹所有其他div的裏面通過使他們的孩子div

<span class="codeLabel">HTML</span> 
<textarea>Example code</textarea> 

所以它應該是這樣的:

​​

使用此代碼:

<!doctype html> 
<html> 
<head> 
<title>CodePlayer</title> 
<meta charset="utf-8" /> 
<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> 
<meta name="viewport" content="width=device-width, initial-scale=1" /> 

    <script src="http://code.jquery.com/jquery-1.10.2.js"></script> 

    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jqueryui.min.js"></script> 

    <style> 
     * { 
       font-family: "HelveticaNeue-Light", "Helvetica Neue Light", 
     "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; 
       margin:0; 
       padding:0; 
     } 

     body, html { 
       height:100%; 
       width:100%; 
     } 
     #container { 
       height:100%; 
     } 

     #titlebar { 
      width:100%; 
      background-color:#EEEEEE; 
      border-bottom:1px solid grey; 
      height:40px; 
     } 

     #title { 
      padding:10px 0 0 20px; 
      font-weight:bold; 
      float:left; 
     } 

     #menu { 
      margin:0 auto; 
      width:220px; 
      padding:5px; 
     } 

     #menu ul { 
      border:1px solid grey; 
      border-radius:5px; 
      height:30px; 
     } 

     #menu li { 
      float:left; 
      list-style:none; 
      border-right:1px solid grey; 
      height:20px; 
      padding:5px 10px; 
     } 

     #menu li:hover { 
      background-color:grey; 
     } 

     #result{ 
      position: relative; 
      top: -30px; 
      left: 153px; 
      border-right: 1px solid white; 
     } 

     #runButton{ 
      float: right; 
      position: relative; 

     } 

     #run{ 
      padding: 10px 15px 10px 15px; 
      border:none; 
      border-radius: 10px; 
     } 

     #run:hover{ 
      background-color:grey; 
     } 

     .break { 
      clear:both; 
     } 

     .codecontainer{ 
      width:49%; 
      float:left;   
      position:relative; 
      top: -24px; 
      height: 100%; 
     } 

     .codecontainer textarea{ 
      width: 100%; 
      height: 100%; 
      border:none; 
      border-right: 1px solid grey; 
      font-family: monotype; 
      font-size: 120%; 
      padding:4px; 
     } 

     .codeLabel{ 
      border:1px grey solid; 
      width: 50px; 
      position: absolute; 
      top: 20px; 
      right: 10px; 
      padding: 5px 5px 5px 5px; 
      border-radius: 5px; 
     } 

     #cssContainer, #jsContainer{ 
      display: none; 
     } 

     iframe{ 
      height: 100%; 
      width: 100%; 
      margin: 0; 
      float: left; 
     } 

    </style> 

</head> 
<body> 
    <div id="container"> 
     <div id="titlebar"> 
      <div id="title"> 
        CodePlayer 
      </div> 

      <div id="runButton"> 

        <button id="run">Run</button> 

      </div> 

      <div id="menu"> 
        <ul> 
         <li>HTML</li> 
         <li>CSS</li> 
         <li>JS</li> 
         <li style="border:none" id="result">Result</li> 
        </ul> 
      </div> 



     </div> 

     <div class="break"></div> 

     <div class="codecontainer" id="htmlContainer"> 

      <span class="codeLabel">HTML</span> 

      <textarea>Example code</textarea> 
     </div> 

     <div class="codecontainer" id="cssContainer"> 

      <span class="codeLabel">CSS</span> 

      <textarea>Example code</textarea> 

     </div> 

     <div class="codecontainer" id="jsContainer"> 

      <span class="codeLabel">JS</span> 

      <textarea>Example code</textarea> 

     </div> 

     <div class="codecontainer" id="resultContainer"> 

      <span class="codeLabel">Result</span> 

      <iframe></iframe> 

     </div> 

</body> 
</html> 
+0

謝謝Arsh。如果世界只存在於像你這樣的人身上,那麼這個世界必須是一個非常適合居住的地方。感謝您所做的一切。 – RVDE

+0

@RVDE總是樂於幫助:)。很高興它有幫助 –