ahmed0saber

Self Chatting in HTML CSS JavaScript

Jun 3rd, 2021 (edited)
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2. <head>
  3.   <style>
  4.   body{
  5.     margin: 0;
  6.     background-color: #E2E2E2;
  7.     font-family: Times New Roman;
  8.   }
  9.   #container{
  10.     border: 2px solid black;
  11.     width:300px;
  12.     margin: auto;
  13.     margin-top:20px;
  14.     margin-bottom:20px;
  15.     background-color: #444;
  16.   }
  17.   #_div{
  18.     overflow-y: auto;
  19.     height: 350px;
  20.     width: 300px;
  21.   }
  22.   input{
  23.     width: 225px;
  24.     height: 50px;
  25.     margin: 0;
  26.     padding-left: 10px;
  27.     border-top:2px solid black;
  28.     font-size: 16px;
  29.     font-family: Times New Roman;
  30.   }
  31.   button{
  32.     width: 75px;
  33.     height: 50px;
  34.     margin: 0;
  35.     float: right;
  36.     border-top: 2px solid black;
  37.     border-left: 2px solid black;
  38.     font-family: Times New Roman;
  39.     font-size: 16px;
  40.   }
  41.   p{
  42.     margin-left: 10px;
  43.     margin-right: 10px;
  44.     padding: 10px;
  45.     background-color: #CCC;
  46.     border-radius: 10px;
  47.   }
  48.   #p1{
  49.     background-color: #AAA;
  50.     padding: 10px;
  51.     margin: 0;
  52.     border-top: 2px solid black;
  53.     border-radius: 0;
  54.   }
  55.   h1{
  56.     background-color: #AAA;
  57.     margin: 0;
  58.     padding: 10px;
  59.     border-bottom:2px solid black;
  60.   }
  61.   span{
  62.     color: red;
  63.   }
  64.   a{
  65.     color: red;
  66.   }
  67.   </style>
  68. </head>
  69. <body>
  70. <div id="container">
  71. <h1>Chat <span>Web</span> App</h1>
  72. <div id="_div">
  73.  
  74. </div>
  75. <input type="text" id="tx1" placeholder="Enter a message">
  76. <button onclick="_create()">Send</button>
  77. <br><p id="p1">Developed by <a href=" gg ">Ahmed Saber</a></p>
  78. </div>
  79. <script>
  80.  
  81. function _create()
  82. {
  83.    var tag = document.createElement("p");
  84.    var text = document.createTextNode(document.getElementById("tx1").value);
  85.    tag.appendChild(text);
  86.    var element = document.getElementById("_div");
  87.    element.appendChild(tag);
  88.    document.getElementById("tx1").value="";
  89.    
  90.     var element = document.getElementById("_div");
  91.     element.scrollTop = element.scrollHeight;
  92. }
  93. </script>
  94. </body>
  95. </html>
Add Comment
Please, Sign In to add comment