Table Cells not Responding to Custom Header CSS #1399

Closed
opened 2026-02-05 00:47:46 +03:00 by OVERLORD · 5 comments
Owner

Originally created by @Anti-Distinctlyminty on GitHub (Oct 11, 2019).

Describe the bug
Placing custom style in the Custom HTML Head Content does not affect table cells (td).

Steps To Reproduce
Steps to reproduce the behavior:

  1. Go to Custom HTML Head Content
  2. Add
    <style> table, th, td {width: 100%; border-collapse: collapse; background-color: #f2f2f2; border-style: solid; border-color: #ffffff;} </style>
  3. Go to a new page and create a table. The cells will not have a white border, just the outer edge of the table itself. As you can see here
    chrome_2019-10-11_11-23-29

Expected behavior
The specified CSS should produce a white border around all cells.
You can see from https://www.w3schools.com/css/tryit.asp?filename=trycss_table_border that the CSS is valid.
chrome_2019-10-11_11-10-57

The desired effect can be done if I go to Cell > Cell Properties. But why does the table not respond to standard CSS formatting?

Your Configuration (please complete the following information):
Apologies here, but I did not set this up. I'm hunting down this information.

  • Exact BookStack Version (Found in settings): BookStack v0.26.2
  • PHP Version: N/K
  • Hosting Method (Nginx/Apache/Docker): N/K
Originally created by @Anti-Distinctlyminty on GitHub (Oct 11, 2019). **Describe the bug** Placing custom style in the Custom HTML Head Content does not affect table cells (td). **Steps To Reproduce** Steps to reproduce the behavior: 1. Go to Custom HTML Head Content 2. Add `<style> table, th, td {width: 100%; border-collapse: collapse; background-color: #f2f2f2; border-style: solid; border-color: #ffffff;} </style>` 3. Go to a new page and create a table. The cells will not have a white border, just the outer edge of the table itself. As you can see here ![chrome_2019-10-11_11-23-29](https://user-images.githubusercontent.com/1378483/66640619-959de000-ec19-11e9-9212-e67567ec29b5.png) **Expected behavior** The specified CSS should produce a white border around all cells. You can see from [https://www.w3schools.com/css/tryit.asp?filename=trycss_table_border](url) that the CSS is valid. ![chrome_2019-10-11_11-10-57](https://user-images.githubusercontent.com/1378483/66639875-10fe9200-ec18-11e9-843d-9dd05580b6ca.png) The desired effect _can_ be done if I go to Cell > Cell Properties. But why does the table not respond to standard CSS formatting? **Your Configuration (please complete the following information):** Apologies here, but I did not set this up. I'm hunting down this information. - Exact BookStack Version (Found in settings): BookStack v0.26.2 - PHP Version: N/K - Hosting Method (Nginx/Apache/Docker): N/K
Author
Owner

@cnfw commented on GitHub (Oct 11, 2019):

Adding the !important property to the border colour got this working for me.
Seems like the ordering CSS is a little funny in that some of it is applied after the custom html head content.
eg:
border-color: #ffffff !important;

image

@cnfw commented on GitHub (Oct 11, 2019): Adding the `!important` property to the border colour got this working for me. Seems like the ordering CSS is a little funny in that some of it is applied after the custom html head content. eg: `border-color: #ffffff !important;` ![image](https://user-images.githubusercontent.com/1470412/66643454-a3059b00-ec16-11e9-807c-f6ba852d5a5c.png)
Author
Owner

@Anti-Distinctlyminty commented on GitHub (Oct 11, 2019):

@cw1998 Thanks for the workaround. That did indeed work. However, just to state the obvious, the CSS should work without hacks.

@Anti-Distinctlyminty commented on GitHub (Oct 11, 2019): @cw1998 Thanks for the workaround. That did indeed work. However, just to state the obvious, the CSS should work without hacks.
Author
Owner

@ssddanbrown commented on GitHub (Oct 11, 2019):

The css is working as intended. CSS specificity is the key here.

Ordering is only one factor in determining the rules that override others. The default BookStack table cell rules are targeting table td which is more specific (Since it has two type selectors) that your own rule of just td (One type selector). Therefore the custom border-color gets overridden. The !important above will effectively boost the specificity "score" so it overrides the default BookStack style. You can change your styles to the following to override BookStack as expected without !important:

<style> table, table th, table td {width: 100%; border-collapse: collapse; background-color: #f2f2f2; border-style: solid; border-color: #ffffff;} </style>
@ssddanbrown commented on GitHub (Oct 11, 2019): The css is working as intended. [CSS specificity](https://www.w3.org/TR/2018/REC-selectors-3-20181106/#specificity) is the key here. Ordering is only one factor in determining the rules that override others. The default BookStack table cell rules are targeting `table td` which is more specific (Since it has two type selectors) that your own rule of just `td` (One type selector). Therefore the custom border-color gets overridden. The `!important` above will effectively boost the specificity "score" so it overrides the default BookStack style. You can change your styles to the following to override BookStack as expected without `!important`: ```html <style> table, table th, table td {width: 100%; border-collapse: collapse; background-color: #f2f2f2; border-style: solid; border-color: #ffffff;} </style> ```
Author
Owner

@Anti-Distinctlyminty commented on GitHub (Oct 11, 2019):

@ssddanbrown Thank you for the clarification. I think the issue here was a combination of my lack of CSS knowledge and the inability to see the default BookStack table cell rules. If it's not already documented then it may be worth adding some clarification to the Custom HTML Head Content section.

@Anti-Distinctlyminty commented on GitHub (Oct 11, 2019): @ssddanbrown Thank you for the clarification. I think the issue here was a combination of my lack of CSS knowledge and the inability to see the default BookStack table cell rules. If it's not already documented then it may be worth adding some clarification to the Custom HTML Head Content section.
Author
Owner

@ssddanbrown commented on GitHub (Oct 12, 2019):

Okay, I'm not sure how much clarification we can really add to that section though since there's so much that someone can do there. The default BookStack rules are can be seen via the browser devtools or by viewing the open code here in the repo.

Since this is now solved I'll close this off.

@ssddanbrown commented on GitHub (Oct 12, 2019): Okay, I'm not sure how much clarification we can really add to that section though since there's so much that someone can do there. The default BookStack rules are can be seen via the browser devtools or by viewing the open code here in the repo. Since this is now solved I'll close this off.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#1399