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: https://i.sstatic.net/hnTYg.jpg

.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

Issue with .html causing .hover to malfunction

Attempting a basic image rollover using jQuery, I've encountered an issue with the code below: HTML: <div class="secondcircle" id="circleone"> <p> <img src="/../ex/img/group1.png"> </p> </div> JS: $("# ...

Is it possible to insert an image directly into the <img> tag without having to first send it to the server?

I've created an upload form that allows users to submit images: <form> <input accept="image/jpeg, image/gif, image/png" type="file" name="image" id="image" class="UploadInput" onchange="submitImageUploaderForm()"/> </form> Once t ...

Conceal HTML elements from the bottom as new content is being added dynamically

I am currently working on a comments feed feature. By default, only the first four comments are displayed, with an option to show more when clicking the "show more" anchor. The issue I'm facing is that if new comments are dynamically added, the CSS hi ...

I'm having trouble keeping my navbar fixed

Having trouble keeping my navigation bar fixed I attempted using the <nav class="fixed-nav-bar> with no success. I also tried adjusting it in CSS, but it still wouldn't stay fixed. <nav role="navigation" class="navbar navbar-default"> ...

Updating hyperlinks from dynamic php links to stable static links

I have a script that predominantly uses absolute addressing, but now I need to switch to relative addressing. The problem I'm encountering is when trying to change the links in PHP from: <link href="<?php print $theme; ?>style.css" type="tex ...

Storing Documents on Your Device

I've been working on a project to create a web page that provides links to online PDF files. When you click on these links, the file should be saved locally and its name/path added to local storage. I then aim to display all the saved files by iterati ...

How to align content within a FormControlLabel using Material UI

My goal is to line up the label and radio button inside a FormControlLabel component so that the label occupies the same width regardless of its content. The current appearance can be seen below: https://i.stack.imgur.com/GhXed.png Below is the code I am ...

Check the input in the text box against the selected options to validate it

Currently, I am working on an add contacts page where I am facing the challenge of displaying an error message or highlighting input as invalid if a user tries to enter a contact name that already exists. It seems like one solution could be populating a s ...

Optimizing website layout for mobile devices

I have a website with a fixed page layout at . It displays properly on desktop browsers but not on mobile devices. The website is adjusting to fit the browser size, but some components are changing format. Can anyone offer assistance? Thank you! ...

Challenges with Setting up reCaptcha

Issue arises while trying to implement reCaptcha. In the body of my basic HTML page, I have a form with the following content. <form action="/cgi-bin/new_forms/form.pl" method="post" name="pledgeform" onSubmit="return validate(this)"> All form info ...

Ways to restrict input text to a specific set of values

When using an input text form, I need to ensure that users only insert values ranging from 1 to 10. However, my attempts to utilize a mask for customization have resulted in allowing values higher than 10. How can I restrict the input to only be allowed b ...

Move a div to line up with a table row when clicked using jQuery

As I mentioned in a previous post, my experience with jQuery is limited and I apologize for that. The task I am attempting to accomplish seems relatively straightforward. Here's an overview of the situation: I have a table enclosed within a div. Each ...

On one webpage, IE 11 is correctly styling certain visited hyperlinks while failing to do so for others

Although I acknowledge that others have asked similar questions, none seem to address the exact issue I am facing, nor do they offer practical solutions or clear explanations. Issue I'm encountering a problem where some visited hyperlinks in IE 11 f ...

Using VBA to Populate Dropdown List on Webpage from an iFrame

I am facing an issue with my code that aims to interact with a webpage by clicking on a link and then modifying dropdown lists within an Iframe. Specifically, I am attempting to populate the Manufr dropdown list based on data from the Year iFrame using VBA ...

Generate code in Yii2 using the active form

This is the code I am using in Yii2: <?= $form->field($model, 'username')->label(false); ?> <?= $form->field($model, 'password')->label(false); ?> It produces the following output: <div class="form-group fi ...

What is the proper method for delivering Javascript code with rendered HTTP to a client?

During the development process, I made a decision to switch to server-side rendering in order to have better control and take advantage of other benefits. My web application relies heavily on AJAX with no url redirecting, creating a website that dynamicall ...

HTML 4.01 character and character offset attributes

I'm curious about the purpose of the charoff attribute in HTML 4.01 Transitional. Specifically, consider a table column that contains the following cells: <td>1.30</td> <td>10</td> <td>100.2</td> <td>1000 ...

Exploring the depths of HTML with the Agility Pack

Looking to extract specific elements from my HTML code: <div id="mailbox" class="div-w div-m-0"> <h2 class="h-line">InBox</h2> <div id="mailbox-table"> <table id="maillist"> <tr> ...

Glistening R resize plotOutput

Attempting to resize a plotOutput using Shiny R. The plot in question can be viewed https://i.sstatic.net/fgzag.png This is the code snippet: #In ui: fluidRow( column(width = 12, h4("Diagrama Persistencia"), plotOutput("Dia ...

What is the best way to eliminate the extra spacing on the right side of my navigation bar?

Hello everyone! I am diving into the world of HTML and CSS, but I've hit a roadblock. Despite searching through various resources and forums, I can't seem to find a solution to my problem. The issue at hand involves an irritating space in my nav ...