What is the best way to position a table caption at the top of a table?

I need help setting up a calendar within a table structure, and I'm struggling to add a caption at the top of the table.

Unfortunately, I can't modify the current table structure. I want it to resemble the example shown below:

.calendar_wrap table {
    width: 100%;
}
.calendar_wrap #wp-calendar thead th {
    font-weight: 500;
    color: #45515a;
    font-size: 20px;
    line-height: 28px;
}
.calendar_wrap #wp-calendar tbody td {
    font-weight: 400;
    font-size: 24px;
    line-height: 36px;
    color: #5b666f;
}
.calendar_wrap #wp-calendar tfoot td a {
    color: #3d9596;
    font-weight: 500;
    margin-top: 10px;
    display: inline-block;
    font-size: 22px;
    line-height: 32px;
}
.calendar_wrap #wp-calendar tbody td a {
    color: #EF9950;
}
.calender-box {
    padding: 15px;
    border: 1px solid #d4d9dd;
    border-radius: 8px;
}
caption {
    font-size: 30px;
    line-height: 36px;
    color: #007ab0;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<section class="calendar_wrap mt-5">
  <div class="container">
    <div class="row justify-content-center">
      <div class="col-4 mt-4 calender-box">
        <table id="wp-calendar">
          <caption>February 2019</caption>
          <thead>
            <tr>
              <th scope="col" title="Monday">M</th>
              <th scope="col" title="Tuesday">T</th>
              <th scope="col" title="Wednesday">W</th>
              <th scope="col" title="Thursday">T</th>
              <th scope="col" title="Friday">F</th>
              <th scope="col" title="Saturday">S</th>
              <th scope="col" title="Sunday">S</th>
            </tr>
          </thead>
          <tfoot>
            <tr>
              <td colspan="3" id="prev"><a href="//192.168.1.37:8000/silk-insurance/2018/10/">« Oct</a></td>
              <td class="pad">&nbsp;</td>
              <td colspan="3" id="next" class="pad">&nbsp;</td>
            </tr>
          </tfoot>
          <tbody>
            <tr>
              <td colspan="4" class="pad">&nbsp;</td><td>1</td><td>2</td><td>3</td>
            </tr>
            <tr>
              <td>4</td><td>5</td><td>6</td><td>7</td><td>8</td><td>9</td><td>10</td>
            </tr>
            <tr>
              <td>11</td><td>12</td><td>13</td><td><a href="//192.168.1.37:8000/silk-insurance/2019/02/14/" aria-label="Posts published on February 14, 2019">14</a></td><td>15</td><td>16</td><td>17</td>
            </tr>
            <tr>
              <td><a href="//192.168.1.37:8000/silk-insurance/2019/02/18/" aria-label="Posts published on February 18, 2019">18</a></td><td>19</td><td>20</td><td>21</td><td>22</td><td>23</td><td>24</td>
            </tr>
            <tr>
              <td id="today">25</td><td>26</td><td>27</td><td>28</td>
              <td class="pad" colspan="3">&nbsp;</td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>            
</section>

Answer №1

Include caption-side: top in your CSS for increased style specificity. To achieve this, either target the selector as #wp-calendar caption or use !important in the style rule. Refer to the demo showcased below:

.calendar_wrap table {
    width: 100%;
}
.calendar_wrap #wp-calendar thead th {
    font-weight: 500;
    color: #45515a;
    font-size: 20px;
    line-height: 28px;
}
.calendar_wrap #wp-calendar tbody td {
    font-weight: 400;
    font-size: 24px;
    line-height: 36px;
    color: #5b666f;
}
.calendar_wrap #wp-calendar tfoot td a {
    color: #3d9596;
    font-weight: 500;
    margin-top: 10px;
    display: inline-block;
    font-size: 22px;
    line-height: 32px;
}
.calendar_wrap #wp-calendar tbody td a {
    color: #EF9950;
}
.calender-box {
    padding: 15px;
    border: 1px solid #d4d9dd;
    border-radius: 8px;
}
caption {
    font-size: 30px;
    line-height: 36px;
    color: #007ab0;
}

#wp-calendar caption { /* ADDED */
  caption-side: top;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<section class="calendar_wrap mt-5">
  <div class="container">
    <div class="row justify-content-center">
      <div class="col-4 mt-4 calender-box">
        <table id="wp-calendar">
          <caption>February 2019</caption>
          <thead>
            <tr>
              <th scope="col" title="Monday">M</th>
              <th scope="col" title="Tuesday">T</th>
              <th scope="col" title="Wednesday">W</th>
              <th scope="col" title="Thursday">T</th>
              <th scope="col" title="Friday">F</th>
              <th scope="col" title="Saturday">S</th>
              <th scope="col" title="Sunday">S</th>
            </tr>
          </thead>
          <tfoot>
            <tr>
              <td colspan="3" id="prev"><a href="//192.168.1.37:8000/silk-insurance/2018/10/">« Oct</a></td>
              <td class="pad">&nbsp;</td>
              <td colspan="3" id="next" class="pad">&nbsp;</td>
            </tr>
          </tfoot>
          <tbody>
            <tr>
              <td colspan="4" class="pad">&nbsp;</td><td>1</td><td>2</td><td>3</td>
            </tr>
            <tr>
              <td>4</td><td>5</td><td>6</td><td>7</td><td>8</td><td>9</td><td>10</td>
            </tr>
            <tr>
              <td>11</td><td>12</td><td>13</td><td><a href="//192.168.1.37:8000/silk-insurance/2019/02/14/" aria-label="Posts published on February 14, 2019">14</a></td><td>15</td><td>16</td><td>17</td>
            </tr>
            <tr>
              <td><a href="//192.168.1.37:8000/silk-insurance/2019/02/18/" aria-label="Posts published on February 18, 2019">18</a></td><td>19</td><td>20</td><td>21</td><td>22</td><td>23</td><td>24</td>
            </tr>
            <tr>
              <td id="today">25</td><td>26</td><td>27</td><td>28</td>
              <td class="pad" colspan="3">&nbsp;</td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>            
</section>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The navigation bar on the web app is functioning properly on Android devices but experiencing a CSS problem on

My Nextjs web app includes a navbar with a hamburger menu, logo, and avatar. The navbar functions perfectly on desktop in Chrome, Mozilla, Brave (in developer tools mobile mode), and on Android phones using Chrome. However, when accessed from an iPhone X, ...

Tips on how to properly format a DateTime String

I need help with formatting a DateTime string retrieved from an API where it is in the format of YYYY-MM-DDTHH:MM:SS +08:00 and I want to change it to DD-MM-YY HH:MM getDataFromApi(res) { this.timestamp = this.timestamp.items[0].timestamp; console ...

Aurelia-powered DataTable plugin for effortless data updating

I'm currently utilizing the DataTables and DatePicker plugins along with Aurelia in my project. The goal is for the user to select a date, which will then prompt the data table to display the corresponding data for that specific date. However, I' ...

What is the best way to store plain HTML text in a database?

Currently, I am working on PHP source code to insert the page created using Quill text editor. Although the text editor data insertion is working fine, it is not inserting plain text as desired. My goal is to insert HTML plain text instead. Below is the J ...

Issue with QuickSand Script not displaying properly on Internet Explorer 7

My website features an edited version of Quicksand that displays correctly on Chrome, Opera, and Firefox, but runs into CSS issues on IE. Oddly enough, when I was using the static version, the CSS displayed properly even on IE until I added the Quicksand e ...

s3 key not found, The specified key does not exist. previewing file from a web link

After utilizing paperclip and s3, I successfully uploaded a word document and now I am seeking the ability to preview it directly from the database using an iframe. https://i.stack.imgur.com/ceCPu.png <iframe src="<%= agreement.document.url(:smal ...

Automatically updating the JavaScript content on a webpage without having to refresh the entire HTML page, based on the changing

Is there a way to adjust the opacity change rate of my nav bar automatically without the need to refresh the page? The current opacity change rate is based on the width of the window, but once the page is loaded, adjusting the width does not affect the rat ...

Display a substitute image if there is no internet connection available to load the Google Map Canvas

I have a WebApp that runs locally, but it's possible that users may not always have access to 3G/WiFi when using the app. This means that the Google Map will not load without an internet connection since it requires the web API. In order to provide a ...

Unable to position a div alongside a fluid div with minimum and maximum widths

Within this container, there is a div. #leftBanner { height: 100%; background-color: #CCC; width: 22%; min-width: 245px; max-width: 355px; float: left; } This particular div doesn't cooperate when I try to float another div next to it. While I could ...

Highcharts' labels on the x-axis do not automatically rotate

One issue I am facing is that my custom x-axis labels on the chart do not rotate upon window resize. I would like to have them rotated when the screen size is less than 399px. Check out the code here $(function () { $('#container').highchart ...

The webpage failed to show the hamburger menu

I'm trying to create a hamburger menu and have written the following code: <header class="header"> <nav class="flex flex-jc-sb flex-ai-c"> <a href="/" class="header__logo"> <img src="im ...

If a quote character is detected in a string, color the line red

My goal is to highlight each line from a string in red if it contains the ">" character. I am applying this logic to a database query result, and while it's successful, I'm encountering an issue where an HTML line break is inserted after each "qu ...

How can CSS be utilized to style the visited links that are hovered over

Is there a way to change the font color specifically for visited hyperlinks that are being hovered over by the mouse? I am trying to achieve this: a:visited:hover {color: red} ...

Preventing Paste Function in Electron Windows

Currently, I am utilizing Electron and attempting to prevent users from pasting into editable content. While paste and match style remains enabled, the functionality is flawless on Mac devices. However, there seems to be an issue on Windows where regular ...

Generating dynamic input field values using jQuery in a CodeIgniter PHP framework application

I am facing an issue where I am unable to display the value from a dynamically created input field in the page controller. Below is the jQuery code used to append the dynamic input fields: var tableRow='<tr>'; tableRow+=' ...

Ways to correct inverted text in live syntax highlighting using javascript

My coding script has a highlighting feature for keywords, but unfortunately, it is causing some unwanted effects like reversing and mixing up the text. I am seeking assistance to fix this issue, whether it be by un-reversing the text, moving the cursor to ...

Tips for keeping a div element at the top of the page

I am looking to have a div stick to the top of the page when someone scrolls down When the page is scrolled, the green div with class stickdiv should automatically stick to the top var left = document.getElementsByClassName("stickdiv"); for( var i = 0; ...

Explore our array of images displayed in an interactive gallery featuring clickable

I have a query I'm facing an issue with my code. Currently, I have a gallery that displays images perfectly. Now, I want to enhance it by showing a larger resolution of the image when clicked. However, when I add the href tag to link the images, they ...

Tips for implementing a waiting period during an ajax request using jQuery

My current task involves calling a URL to generate a token and then opening another page on the same site once the token is generated. The issue I'm facing is that the window generating the token closes quickly, making it difficult for me to authentic ...

Having trouble updating attribute through ajax requests

How can I set attribute values using ajax-jquery? Here are some snippets of code: HTML_CODE ========================================================================== <div class="col"> <ul class="nav nav-pills justify-content-end& ...