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

CSS can conflict with parent rules #9

Open
dmorrison42 opened this issue Apr 14, 2016 · 5 comments
Open

CSS can conflict with parent rules #9

dmorrison42 opened this issue Apr 14, 2016 · 5 comments

Comments

@dmorrison42
Copy link

With certain parent CSS rules, it is possible to break styling (accidentally).

This can be seen with this Sphinx theme https://github.com/snide/sphinx_rtd_theme.

For example see the template below:

{% extends "!layout.html" %}

{%- block extrahead %} 
<script src="/_static/json-schema-view.min.js"></script>
<link rel="stylesheet" href="/_static/json-schema-view.min.css"></script>
<script>
window.addEventListener('load', function () {
    var view;
    var codeBlocks = document.getElementsByClassName('highlight-jsonschema');
    for (var i = 0; i < codeBlocks.length; i++) {
        try {
            view = new JSONSchemaView(JSON.parse(codeBlocks[i].textContent));
        } catch (e) {
            console.log(e)
        }
        codeBlocks[i].parentElement.replaceChild(view.render(), codeBlocks[i]);
    }
});
</script>
<style>
.json-schema-view .property, 
json-schema-view .property {
    display: table-row !important;
}
</style>
{% endblock %}
@mohsen1
Copy link
Owner

mohsen1 commented Apr 14, 2016

Every CSS class is scoped under json-schema-view class.

Do you mean CSS from this module is effecting other elements or the other way around?

@dmorrison42
Copy link
Author

dmorrison42 commented Apr 14, 2016

The following rule from the Sphinx theme is causing the view to break.

 .rst-content dl:not(.docutils) .property {
    display: inline-block;
    padding-right: 8px;
}

image

@mohsen1
Copy link
Owner

mohsen1 commented Apr 14, 2016

We can't add !important to all properties to avoid this. It's a problem in Sphinx rule that over-target elements.

@dmorrison42
Copy link
Author

I would generally agree, especially with the fact that we shouldn't use !important everywhere.

One possible option would be inline styles, but I understand if that's not a direction we want to go in either.

One other possibility may be to make the rules more specific so that the :not selector is less of a problem.

I'm OK with my current work around, because the parent CSS will always be able to create a rule that will break things, but it would obviously be ideal if it wasn't needed.

@mohsen1
Copy link
Owner

mohsen1 commented Apr 14, 2016

The acceptable solution is to prepend all of classes with some specific prefix. For example jsv--property instead of property. It should be done via tooling and not by hand.

I don't have the time to do that but will review a pull request if you make one. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants