0

Is there a way of linking the button to another website ? (for example youtube) because it doesn't work with href="{link}"

<button href="www.youtube.com">GoTo Lessons</button>
<style>
a {
  border: 2px solid;
  color: black;
  border-radius: 15px;
}
</style>

<div class="code-area">
  <textarea id="htmlCode" class="1111" placeholder="HTML" 
            oninput="showPreview()"></textarea>
  <textarea id="cssCode" class="2222" placeholder="CSS" 
            oninput="showPreview()"></textarea>
  <textarea id="jsCode" class="333" placeholder="JavaScript" 
            oninput="showPreview()"></textarea>             
</div>
<div class="preview-area">
  <iframe id="preview-window"></iframe>
</div>

<style>
* {
  margin: 0px;
  padding: 0px;
  box-sizing: border-box;
}
body {
  height: 100vh;
  display: flex;
}
.code-area {
  display: flex;
  flex-direction:column;
  width: 50%;
  border-right:1px solid #555;
}
.code-area textarea {
  border: 2px solid;
  border-radius: 15px;
  resize: none;
  outline: none;
  width: 100%;
  height: 33.33%;
  font-size: 18px;
  padding: 10px;
}
.preview-area {
  border: 2px solid;
  border-radius: 15px;
  width: 50%;
}
.preview-area iframe {
  width: 100%;
  height: 100%;
  border: none;
}
</style>

<script>
function showPreview(){
  var htmlCode = document.getElementById("htmlCode").value;
  var cssCode = "<style>"+document.getElementById("cssCode").value+"</style>";
  var jsCode = "<scri"+"pt>"+document.getElementById("jsCode").value+"</scri"+"pt>";
  var frame = document.getElementById("preview-window").contentWindow.document;
  frame.open();
  frame.write(htmlCode+cssCode+jsCode);
  frame.close();
}
</script>

don't pay attention to this random text, i just entered it orelse it wouldn't let me ost cause i have too many code and not enough text so if this is boring your'e not forced to read this i think so yeah so if you want is you can go so dont read this so yeah so bye

1 Answers1

0

You can use CSS flexbox:

  display: flex;
  justify-content: center; /* for text "text-align: center;" will work too */
  align-items: center;

function showPreview(){
  var htmlCode = document.getElementById("htmlCode").value;
  var cssCode = "<style>"+document.getElementById("cssCode").value+"</style>";
  var jsCode = "<scri"+"pt>"+document.getElementById("jsCode").value+"</scri"+"pt>";
  var frame = document.getElementById("preview-window").contentWindow.document;
  frame.open();
  frame.write(htmlCode+cssCode+jsCode);
  frame.close();
}
* {
  margin: 0px;
  padding: 0px;
  box-sizing: border-box;
}
body {
  height: 100vh;
  display: flex;
}
.code-area {
  display: flex;
  flex-direction:column;
  width: 50%;
  border-right:1px solid #555;
}
.code-area textarea {
  border: 2px solid;
  border-radius: 15px;
  resize: none;
  outline: none;
  width: 100%;
  height: 33.33%;
  font-size: 18px;
  padding: 10px;
}
.preview-area {
  border: 2px solid;
  border-radius: 15px;
  width: 50%;
}
.preview-area iframe {
  width: 100%;
  height: 100%;
  border: none;
}

a {
  border: 2px solid;
  color: black;
  border-radius: 15px;
  
  /* Added */
  display: flex;
  text-align: center;
  align-items: center;
}
div {
  text-align: center;
  vertical-align: middle;
}
<a href="www.youtube.com">GoTo Lessons</a>

<div class="code-area">
  <textarea id="htmlCode" class="1111" placeholder="HTML" 
            oninput="showPreview()"></textarea>
  <textarea id="cssCode" class="2222" placeholder="CSS" 
            oninput="showPreview()"></textarea>
  <textarea id="jsCode" class="333" placeholder="JavaScript" 
            oninput="showPreview()"></textarea>             
</div>
<div class="preview-area">
  <iframe id="preview-window"></iframe>
</div>
ulou
  • 3,894
  • 2
  • 28
  • 41