Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wide table handling is not flexible, how to override the CSS? #117

Open
smartass101 opened this issue Apr 27, 2014 · 17 comments
Open

Wide table handling is not flexible, how to override the CSS? #117

smartass101 opened this issue Apr 27, 2014 · 17 comments
Labels
Design Design or UX/UI related Improvement Minor improvement to code Needed: design decision A core team decision is required

Comments

@smartass101
Copy link

I understand that wide tables need special handling in responsive designs.
However, on a computer screen a table like this http://docs.getpelican.com/en/latest/settings.html#basic-settings is very inconvenient to read.

Any ideas how to address this inconvenience?
I tried to override the CSS style for the table as described in getpelican/pelican#1311 (specifically commit smartass101/pelican@e1ee4c9), but that works only locally. It would work well if I could get something like sphinx_rtd_theme.get_html_theme_path() on RTD, but I wasn't able to find the out what the theme path is on RTD.

If CSS overriding is not possible, would it be possible to add some theme setting that would disable the current wide table handling?

@KevinCathcart
Copy link

Until @snide can address the underlying concern, here is a workaround to easilly add custom CSS that should work just fine on the RTD site:

One simple approach to adding custom CSS is not to create a whole new theme, but simple drop a css file in _static. Then add a file named _template/layout.html that contains the following:

{% extends "!layout.html" %}
{% set css_files = css_files + ["_static/pelican.css"] %}

(Credit: http://stackoverflow.com/a/9738992/179917 )

@smartass101
Copy link
Author

I found a solution that works without making a layout.html file. The solution is to only create a _static/theme_overrides.css (relative to conf.py):

/* override table width restrictions */
.wy-table-responsive table td, .wy-table-responsive table th {
    white-space: normal;
}

.wy-table-responsive {
    margin-bottom: 24px;
    max-width: 100%;
    overflow: visible;
}

and then in conf.py

html_static_path = ['_static']

html_context = {
    'css_files': [
        '_static/theme_overrides.css',  # overrides for wide tables in RTD theme
        ],
    }

@ericholscher
Copy link
Member

The workaround that @smartass101 came up with is a good one. We should probably document this :)

@KevinCathcart
Copy link

@ericholscher: Actually, you might want to document something slightly different.

@smartass101: While setting css_files via html_context appears to work, it actually prevents any sphinx extensions from being able to register css files, because the value specified in html_context will override the preregistered list of css files. This is more noticeable when using script_files via html_context, since doing so causes jQuery to not be included!

Here is yet another alternative, which works just fine. It registers the extra files for inclusion in the same way as a sphinx extension would. Simply add this function to conf.py:

def setup(app):
   app.add_javascript("custom.js")
   app.add_stylesheet("custom.css")

Note the absence of the _static folder name. That is added automatically by the definitions of add_javascript and add_stylesheet.

@smartass101
Copy link
Author

I was afraid something like that would bite me back eventually. Thank you @KevinCathcart for this cleaner solution that is also documented in Sphinx docs.

@snide
Copy link
Collaborator

snide commented Apr 28, 2014

Dunno how you guys want to me to handle this. If someone wants to update the readme or something with proper docs I'll merge it in. I'm just a design hack :)

@smartass101
Copy link
Author

Unfortunately the fix by @KevinCathcart works only locally because on RTD the commond hosted CSS theme files get added after that the one specified by app.add_stylesheet

<link type="text/css" href="_static/theme_overrides.css" rel="stylesheet"></link>

<link type="text/css" href="https://media.readthedocs.org/css/sphinx_rtd_theme.css" rel="stylesheet"></link>

<link type="text/css" href="https://media.readthedocs.org/css/readthedocs-doc-embed.css" rel="stylesheet"></link>

@smartass101
Copy link
Author

For the time being I solved this by declaring the overrides as !important

/* override table width restrictions */
.wy-table-responsive table td, .wy-table-responsive table th {
    /* !important prevents the common CSS stylesheets from
       overriding this as on RTD they are loaded after this stylesheet */
    white-space: normal !important;
}

.wy-table-responsive {
    overflow: visible !important;
}

@ericholscher
Copy link
Member

Hmm. Yea, the calls to add_javascript get called before our own calls, so
appear sooner in the list. Not sure the best workaround there.

On Mon, Apr 28, 2014 at 1:03 PM, Ondrej Grover notifications@github.comwrote:

For the time being I solved this by declaring the overrides as !important

/* override table width restrictions */.wy-table-responsive table td, .wy-table-responsive table th {

/* !important prevents the common CSS stylesheets from       overriding this as on RTD they are loaded after this stylesheet */
white-space: normal !important;}

.wy-table-responsive {
overflow: visible !important;}


Reply to this email directly or view it on GitHubhttps://github.com//issues/117#issuecomment-41606147
.

@kmike
Copy link

kmike commented May 25, 2014

Thanks @smartass101 for providing a workaround!

Why not have relevant CSS fixed by default? Are there cases when it is desirable to truncate the information in table, be it a tablet screen or a computer screen? On tablets existing tables are even worse because horizontal scroll of individual elements is hard on touch interfaces. On macs there is no indication that table can be horizontally scrolled because scrollbars are hidden by default; they don't appear even on hover, you need to actually start scrolling to see the scrollbars.

@ghost
Copy link

ghost commented Jul 20, 2014

I did not found a solution to include custom css files, and I changed layout.html like in sylius, removed this if

@binwiederhier
Copy link

@KevinCathcart's solution works just fine for me, see my conf.py

The order of the included files is avtually not that important, as long as the specificity of the CSS statement is higher: html body div.someclass ... > .someclass. See my theme_overrides.css.

Thanks!

chfw added a commit to pyexcel/pyexcel that referenced this issue Nov 30, 2014
@chfw
Copy link

chfw commented Nov 30, 2014

@smartass101, your solution worked for my project. Thanks!

tych0 added a commit to qtile/qtile that referenced this issue Feb 28, 2015
This makes things far easier to read. Workaround stolen from:
readthedocs/sphinx_rtd_theme#117
christianp added a commit to numbas/editor-docs that referenced this issue Jun 9, 2015
carlos-jenkins added a commit to carlos-jenkins/autoapi that referenced this issue Sep 20, 2015
@danielquinn
Copy link

If I could make on addendum to this solution:

/* override table width restrictions */
@media screen and (min-width: 767px) {

  .wy-table-responsive table td {
    /* !important prevents the common CSS stylesheets from
       overriding this as on RTD they are loaded after this stylesheet */
    white-space: normal !important;
  }

  .wy-table-responsive {
    overflow: visible !important;
  }

}

This will enable scrolling for devices where it makes sense (phones and small tablets) and disable it for others. I've also stripped the exception for th since generally those shouldn't wrap, but I leave it up to you lot to make that call.

@stsewd stsewd added Improvement Minor improvement to code Needed: design decision A core team decision is required labels Oct 8, 2020
@rodrigorenie
Copy link

rodrigorenie commented Apr 29, 2021

@KevinCathcart

def setup(app):
   app.add_javascript("custom.js")
   app.add_stylesheet("custom.css")

Sphinx now returns a warning when using app.add_stylesheet, just use app.add_css_file instead.

malthe added a commit to malthe/airflow-site that referenced this issue Jan 14, 2022
See readthedocs/sphinx_rtd_theme#117 for a bigger discussion and many references.
il-steffen added a commit to il-steffen/ccc-linux-guest-hardening-docs that referenced this issue Apr 2, 2022
il-steffen added a commit to intel/ccc-linux-guest-hardening-docs that referenced this issue Apr 4, 2022
marnanel added a commit to marnanel/yex that referenced this issue May 9, 2022
adacore-bot pushed a commit to AdaCore/spark2014 that referenced this issue May 31, 2022
Solution taken from here:

readthedocs/sphinx_rtd_theme#117

The LRM doesn't contain tables AFAICS so I didn't apply this patch.

Change-Id: Ib6428f605613199b647dd04a297512c865cf7b12
dschwoerer added a commit to boutproject/BOUT-dev that referenced this issue Sep 15, 2022
ZedThree pushed a commit to boutproject/BOUT-dev that referenced this issue Sep 16, 2022
sarabellei added a commit to sarabellei/cling that referenced this issue Oct 14, 2022
potiuk pushed a commit to apache/airflow-site that referenced this issue Nov 8, 2022
See readthedocs/sphinx_rtd_theme#117 for a bigger discussion and many references.
@moi90
Copy link

moi90 commented Feb 8, 2023

Since Sphinx 1.8, the correct way to specify custom css files in conf.py seems to be:

html_css_files = [
  'custom.css'
  'https://example.com/css/custom.css',
  ('print.css', {'media': 'print'})
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Design Design or UX/UI related Improvement Minor improvement to code Needed: design decision A core team decision is required
Projects
None yet
Development

No branches or pull requests