Referring to a table or content on a website or document that includes a button for copying code blocks. Many modern platforms provide this feature to make it easier to copy-paste code for reuse.If you're implementing such functionality, you can use a combination of HTML, CSS, and JavaScript to achieve this.

 Hello நண்பா 🥰



This HTML code creates a table with a single cell containing a code block. The code block has a "Copy" button that, when clicked, copies the text inside the code block to the clipboard.

Key Features

  1. Code Block: A pre element with the id "codeBlock" contains the code to be copied.
  2. Copy Button: A button inside the table header with an onclick event that triggers the copyCode function.
  3. Copy Functionality: The copyCode function uses the navigator.clipboard.writeText method to copy the code block text.

Example Use Case

  1. Replace "Suresh" in the codeBlock pre element with your desired code.
  2. Click the "Copy" button to copy the code.
  3. Paste the code wherever needed.

Advice

  1. Ensure the browser supports the navigator.clipboard API.
Adjust styles as needed for better integration with your website or application.


5 line code block white colour background 


Code

<div>
  <table style="border-collapse: collapse; margin: 20px 0px; position: relative; width: 100%;">
    <thead>
      <tr>
        <th style="background-color: #f2f2f2; border: 1px solid rgb(221, 221, 221); padding: 10px; text-align: left;">
          Code
          <button onclick="copyCode()" style="background-color: #4caf50; border-radius: 5px; border: none; color: white; cursor: pointer; float: right; padding: 5px 10px;">
            Copy
          </button>
        </th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td style="background-color: #f9f9f9; border: 1px solid rgb(221, 221, 221); padding: 10px;">
          <pre id="codeBlock" style="background-color: white; border-radius: 5px; color: black; font-family: monospace; max-height: 100px; overflow-y: auto; padding: 10px; white-space: pre-wrap;">suresh
          </pre>
        </td>
      </tr>
    </tbody>
  </table>

  <script>
    function copyCode() {
      var copyText = document.getElementById("codeBlock").textContent;
      navigator.clipboard.writeText(copyText).then(function() {
        alert("Code copied to clipboard!");
      }, function(err) {
        alert("Failed to copy the code!");
      });
    }
  </script>
</div>

Do not work the code block  Download another one TXT format



5 line code block black colour background 


Code

<div><br /></div><div><table style="border-collapse: collapse; margin: 20px 0px; position: relative; width: 100%;">
  <thead>
    <tr>
      <th style="background-color: #f2f2f2; border: 1px solid rgb(221, 221, 221); padding: 10px; text-align: left;">
        Code
        <button onclick="copyCode()" style="background-color: #4caf50; border-radius: 5px; border: none; color: white; cursor: pointer; float: right; padding: 5px 10px;">
          Copy
        </button>
      </th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td style="background-color: #f9f9f9; border: 1px solid rgb(221, 221, 221); padding: 10px;">
        <pre id="codeBlock" style="background-color: #333333; border-radius: 5px; color: white; font-family: monospace; max-height: 100px; overflow-y: auto; padding: 10px; white-space: pre-wrap;">suresh
        </pre>
      </td>
    </tr>
  </tbody>
</table>

<script>
  function copyCode() {
    var copyText = document.getElementById("codeBlock").textContent;
    navigator.clipboard.writeText(copyText).then(function() {
      alert("Code copied to clipboard!");
    }, function(err) {
      alert("Failed to copy the code!");
    });
  }
</script>
</div><div><br /></div><div><br /></div><div><br /></div><div><br /></div>





Do not work the code block  Download  another one TXT format


Code block white colour background 

Code

<table style="border-collapse: collapse; margin: 20px 0px; position: relative; width: 100%;">

  <thead>

    <tr>

      <th style="background-color: #f2f2f2; border: 1px solid rgb(221, 221, 221); padding: 10px; text-align: left; font-size: 12px;">

        Code<button onclick="copyCode()" style="background-color: #4caf50; border-radius: 5px; border: none; color: white; cursor: pointer; float: right; padding: 5px 10px; font-size: 12px;">

          Copy

        </button>

      </th>

    </tr>

  </thead>

  <tbody>

    <tr>

      <td style="background-color: #ffffff; border: 1px solid rgb(221, 221, 221); padding: 10px;">

        <pre id="codeBlock" style="background-color: #ffffff; border-radius: 5px; color: black; font-family: monospace; font-size: 12px; padding: 10px; white-space: pre-wrap;">Suresh

        </pre>

      </td>

    </tr>

  </tbody>

</table>


<script>

  function copyCode() {

    var copyText = document.getElementById("codeBlock").textContent;

    navigator.clipboard.writeText(copyText).then(function() {

      alert("Code copied to clipboard!");

    }, function(err) {

      alert("Failed to copy the code!");

    });

  }

</script>

Do not work the code block  Download another one TXT format


Code block black colour background

Code

<!--Table with Copy Button-->

<table style="border-collapse: collapse; margin: 20px 0px; position: relative; width: 100%;">

  <thead>

    <tr>

      <th style="background-color: #f2f2f2; border: 1px solid rgb(221, 221, 221); padding: 10px; text-align: left;">

        Code<button onclick="copyCode()" style="background-color: #4caf50; border-radius: 5px; border: none; color: white; cursor: pointer; float: right; padding: 5px 10px;">

          Copy

        </button>

      </th>

    </tr>

  </thead>

  <tbody>

    <tr>

      <td style="background-color: #f9f9f9; border: 1px solid rgb(221, 221, 221); padding: 10px;">

        <pre id="codeBlock" style="background-color: #333333; border-radius: 5px; color: white; font-family: monospace; padding: 10px; white-space: pre-wrap;">Suresh

        </pre>

      </td>

    </tr>

  </tbody>

</table>


<script>

  function copyCode() {

    var copyText = document.getElementById("codeBlock").textContent;

    navigator.clipboard.writeText(copyText).then(function() {

      alert("Code copied to clipboard!");

    }, function(err) {

      alert("Failed to copy the code!");

    });

  }

</script>



Do not work the code block Download another one TXT format

"This Content Sponsored by Genreviews.Online

Genreviews.online is One of the Review Portal Site

Website Link: https://genreviews.online/

Sponsor Content: #genreviews.online, #genreviews, #productreviews, #bestreviews, #reviewportal"

Post a Comment

Previous Post Next Post