The border styling for top and bottom of table rows in Bootstrap seems to be malfunctioning

I am trying to format my table to look like the one shown in https://i.sstatic.net/FEPyL.jpg

My goal is to add top and bottom borders to each row (tr) of my table, similar to what is depicted in the image. While I managed to get one border working, the other seems to be a challenge. I read online that setting display block for tr might solve the issue, but doing so causes all my text to align to the left side. For clarity, I used red and blue borders in my code snippet. Can someone guide me on how to achieve this?

table {
  background-color: #EEEEEE;
  margin-top: 40px;
}
table tr {
  /*display: block;*/
  border-top: 2px solid red;
  border-bottom: 2px solid blue;
}
<!DOCTYPE html>
<html>
<head>
<title></title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</head>
<body>
<table class="table table-striped">
    <tbody>
    <tr>
    <td>&nbsp;</td>
        <td class="table-title">Matin</td>
        <td class="table-title">Apres-midi</td>
    </tr>
    <tr>
        <td>Lundi</td>
        <td>08h00-12h00</td>
        <td>13h00-17h00</td>
    </tr>
    <tr>
        <td>Mardi</td>
        <td>08h00-12h00</td>
        <td>13h00-17h00</td>
    </tr>
    <tr>
        <td>Mercredi</td>
        <td>08h00-12h00</td>
        <td>13h00-17h00</td>
    </tr>
    <tr>
        <td>Jeudi</td>
        <td>08h00-12h00</td>
        <td>13h00-17h00</td>
    </tr>
    <tr>
        <td>Vendredi</td>
        <td>08h00-12h00</td>
        <td>13h00-17h00</td>
    </tr>
    <tr>
        <td>Samedi</td>
        <td>08h00-12h00</td>
        <td>13h00-17h00</td>
    </tr>
    <tr>
        <td>Dimache</td>
        <td>Ferme</td>
        <td>Ferme</td>
    </tr>
    </tbody>
</table>
</body>
</html>

Answer №1

To override the default Bootstrap styling, you may need to increase specificity or use !important.

The code snippet is:

.table>tbody>tr>td, 
.table>tbody>tr>th, 
.table>tfoot>tr>td, 
.table>tfoot>tr>th, 
.table>thead>tr>td, 
.table>thead>tr>th {
    padding: 8px;
    line-height: 1.42857143;
    vertical-align: top;
    border-top: 1px solid #ddd;
}

You also need to override the border-collapse property.

table {
  background-color: #EEEEEE;
  margin-top: 40px;
  border-collapse: separate !important;
}
.table>tbody>tr>td,
.table>tbody>tr>th,
.table>tfoot>tr>td,
.table>tfoot>tr>th,
.table>thead>tr>td,
.table>thead>tr>th {
  padding: 8px;
  line-height: 1.42857143 vertical-align: top;
  border-top: 4px solid green !important;
  border-bottom: 4px solid red !important;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<table class="table table-striped">
  <tbody>
    <tr>
      <td>&nbsp;</td>
      <td class="table-title">Morning</td>
      <td class="table-title">Afternoon</td>
    </tr>
    <tr>
      <td>Monday</td>
      <td>08:00-12:00</td>
      <td>13:00-17:00</td>
    </tr>
    <tr>
      <td>Tuesday</td>
      <td>08:00-12:00</td>
      <td>13:00-17:00</td>
    </tr>
    <tr>
      <td>Wednesday</td>
      <td>08:00-12:00</td>
      <td>13:00-17:00</td>
    </tr>
    <tr>
      <td>Thursday</td>
      <td>08:00-12:00</td>
      <td>13:00-17:00</td>
    </tr>
    <tr>
      <td>Friday</td>
      <td>08:00-12:00</td>
      <td>13:00-17:00</td>
    </tr>
    <tr>
      <td>Saturday</td>
      <td>08:00-12:00</td>
      <td>13:00-17:00</td>
    </tr>
    <tr>
      <td>Sunday</td>
      <td>Closed</td>
      <td>Closed</td>
    </tr>
  </tbody>
</table>

Answer №2

I have made some adjustments to your code. Now, the top border color is set to red and the bottom border color is blue.

table {
  background-color: #EEEEEE;
  margin-top: 40px;
}
tr:nth-child(even){
  /*display: block;*/
  border-top: 2px solid red;
  /*background-color: #CC9999;*/
  
}
tr:nth-child(odd){
  /*display: block;*/
  border-top: 2px solid blue;
  
}
<!DOCTYPE html>
<html>
<head>
<title></title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</head>
<body>
<table class="table table-striped">
    <tbody>
    <tr>
    <td>&nbsp;</td>
        <td class="table-title">Matin</td>
        <td class="table-title">Apres-midi</td>
    </tr>
    <tr>
        <td>Lundi</td>
        <td>08h00-12h00</td>
        <td>13h00-17h00</td>
    </tr>
    <tr>
        <td>Mardi</td>
        <td>08h00-12h00</td>
        <td>13h00-17h00</td>
    </tr>
    <tr>
        <td>Mercredi</td>
        <td>08h00-12h00</td>
        <td>13h00-17h00</td>
    </tr>
    <tr>
        <td>Jeudi</td>
        <td>08h00-12h00</td>
        <td>13h00-17h00</td>
    </tr>
    <tr>
        <td>Vendredi</td>
        <td>08h00-12h00</td>
        <td>13h00-17h00</td>
    </tr>
    <tr>
        <td>Samedi</td>
        <td>08h00-12h00</td>
        <td>13h00-17h00</td>
    </tr>
    <tr>
        <td>Dimache</td>
        <td>Ferme</td>
        <td>Ferme</td>
    </tr>
    </tbody>
</table>
</body>
</html>

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

Is it possible to stop Angular requests from being made within dynamic innerhtml?

I have a particular element in my code that looks like this: <div [innerHtml]="htmlContent | sanitiseHtml"></div> The sanitiseHtml pipe is used to sanitize the HTML content. Unfortunately, when the htmlContent includes relative images, these ...

Fade in an image using Javascript when a specific value is reached

Here's the select option I'm working with: <div class="okreci_select"> <select onchange="changeImage(this)" id="selectid"> <option value="samsung">Samsung</option> <option value="apple">App ...

Using Jquery to select and apply functions to specified div elements

As someone who is relatively new to JQuery, I have a question regarding the .on() function. Take this example: $('div').on('click', function() {$(this).toggleClass('show-description');}); This code selects all the 'div& ...

What is the best way to shift my content to the next line once it reaches a specific width in my paragraph

When a string is pulled from a database and inserted into a paragraph, it breaks perfectly if the paragraph has spaces. However, if a word is longer than the line, it goes off the page. How can I make it wrap to the next line instead of overflowing off the ...

Using a varnish proxy to transmit server-sent events

My website is currently operating behind a Varnish proxy, but I am experiencing issues with server-sent events. The connections remain open indefinitely without receiving any content, and Varnish waits for the stream to end before forwarding it to the brow ...

Is it advisable to hold off until the document.onload event occurs?

I'm working with a basic HTML file where I need to generate SVGs based on data retrieved through an AJAX call. Do I need to ensure the document is fully loaded by enclosing my code within a document.onload = function() { ... } block, or can I assume ...

What is the best way to send data to a child component in Angular, including components that can be

There are two components in my project: the parent component and the child component, each with their own unique markup. It is crucial for this example that the child component fetches its own data to render and not be provided by the parent. Currently, th ...

Why is it that every time I write this code, the localhost gets redirected and a message pops up saying

<?php include("connect.php"); if(isset($_POST['submit'])) { $qonax=@$_POST['qonax']; $subject=@$_POST['subject']; $insert="INSERT INTO subject(ID,Qonax,Subject)VALUES('','$qonax', ...

Using Javascript, the sum of inputs is calculated based on the keyup event

I am a beginner in javascript and I'm learning about events. Below is the HTML code for a table that displays income titles and their respective prices. <table class="table table-hover table-bordered" id="incomeId"> <thead> <tr&g ...

Display the specified div element automatically

Despite my best efforts, I can't seem to figure this out. I've searched everywhere for a solution but no luck so far. Is there a way to automatically display the content from http://tympanus.net/Tutorials/CSS3ContentNavigator/index.html#slide-mai ...

How can you manage both HTML5 mode routes and hash routes in Angular?

After utilizing the "standard" routes in Angular 1 with the # sign (e.g. /app#/home), I have decided to make the switch to HTML5 mode for cleaner URLs (e.g.: /app/home). I successfully activated HTML5 mode using $locationProvider.html5Mode(true), and ever ...

What causes the vuetify tag not to render as HTML in the browser?

I ran into a styling issue while using Vuetify in my Nuxt 2 project. Upon inspecting the element in dev tools, I noticed that some Vuetify tags were not being converted to HTML as expected (they were displayed as div class="tag_name"). These unco ...

Comparing Chaining jQuery Functions with If Statements in Checking Check Box Values

I'm working with multiple checkboxes and trying to determine the overall value for them all. For example, if one checkbox is checked then the value should be true/selected. If none are checked, then it should be false/unchecked. The HTML code I am ...

Connect your Flask/Dash application to a customized Bootstrap stylesheet stored locally

I have created a Flask/Dash application and I am currently linking it to an external bootstrap stylesheet as shown below: dash_app = dash.Dash(server=server, routes_pathname_prefix='/dashapp/', ...

What causes the disruption of vertical alignment among inline-block elements when using overflow:hidden?

Take a look at these two JSFiddles: http://jsfiddle.net/am28dsbz http://jsfiddle.net/am28dsbz/1/ Why is it that the first one shows my text aligned correctly, while the second one displays the first link lower than the second? Stack Overflow requires m ...

reduce the size of the image as the browser width decreases

Struggling with a webpage layout that features an image on the left and content area on the right, both with fixed widths. When reducing browser width, the image should not shrink but be cropped from the left side instead. Any solutions for this issue? ...

What is the method for deactivating an underlying element to prevent it from being clicked on?

I have a situation where I have two elements stacked on top of each other. When I click a button in the first element, the second element opens on top of it. What I am trying to achieve is to make the underlying element non-interactive while the overlaying ...

Is there a way to make the button text bold before deleting it post clicking on an alert message?

While testing my sequence in IE, I noticed that it appeared correctly, but in Chrome, the button text was not showing up as bold. Instead, only the alert message was displayed, and the button itself was removed. Upon further investigation using Chrome&apo ...

Adjust the text area to automatically expand or shrink based on the text it contains

Is there a way to automatically adjust the size of a textarea based on its content? Here is the code I am currently using for this purpose: var element = document.getElementById(event.target.id); var content = $(this).val().trim(); if (content == "") { ...

Are cookies always included in client requests?

With every interaction between the server and browser, cookies are exchanged back and forth. However, what happens when an image is requested? <img src='myPic.jpg' /> Is the browser also sending cookies during this type of request? If i ...