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

Decouple styles from the <html>, <head>, <title>, and <body> #31

Open
evanplaice opened this issue Jan 15, 2016 · 4 comments
Open

Decouple styles from the <html>, <head>, <title>, and <body> #31

evanplaice opened this issue Jan 15, 2016 · 4 comments
Assignees
Milestone

Comments

@evanplaice
Copy link

With the current setup, trying to embed a HTML output into a website is not possible without some manual hacks.

2 changes are required to fix this:

  1. don't base css styles off of the tags mentioned in the description. Use as the base.
  2. remove the <link> tags by using @import in the stylesheet.

With these changes and shadow DOM encapsulation, it should be trivial to generate a partial that can be embedded in any website.

@hacksalot
Copy link
Member

Thanks @evanplaice! -- a few notes:

  1. Agreed. The idea has been to get something usable out and iterate through this kind of progressive enhancement. Feel free to make specific suggestions here, and there will be a large-ish CSS refactoring round after Sass/LESS support is integrated with HMR.

  2. Agreed. Currently HMR will switch between embedded and linked styles on the fly via the {{styleSheet}} helper and --css embed|link, but the end goal is to allow the theme author, the user, and HMR itself to all have a hand in the decision of how CSS linkage is carried out, including explicit support for @import.

A few areas where this matters:

  • generating a PDF from HTML, embedded <style>s in <head> give the best consistency across engines and platforms
  • public-facing web context: use <link>s or @imports unless the user says otherwise.
  • Ideally the .html output format of a FRESH theme should not fall apart when viewed locally in the user's (or employer's) browser, which again points toward embedded styles or easily-resolved relative <link>s or @imports.
  • Etc.

This could be supported fairly easily at the theme authorship level by replacing each stylesheet reference (whether <link>, <style> or @import) with a helper similar to {{styleSheet}} as we've done, and by relying on the fact that these are FRESH (ie, structured and hopefully decoupled and DRY-ed) themes. I think that would give the toolchain enough of a handle to allow fairly transparent support of all three flavors. Shortly we'll also add template expansion to CSS files to give a bit more capability here too.

Also keep in mind that we'll be expanding the "FRESH" theme infrastructure outside of a resume context, so think in terms of generic documents, not just resumes.

@evanplaice
Copy link
Author

1.

As an example, take the 'modern' theme's modern-html.css

* {
  box-sizing: border-box;
}

main {
  display: block;
}

body {
  font-family: 'Helvetica Neue', Helvetica, 'Lato', sans-serif;
  font-size: 15px;
  color: #333;
  line-height: 1.42857143;
  background-color: #F0F0F0;
  margin: 0;
  padding: 0;
}

/* Typical page borders are awkward when rendered to PDF. */
body.pdf {
  background-color: #FFFFFF;
}

/* Adobe or wkhtmltopdf has issues with the <main> tag, so we use <div> for
the PDF case, <main> for the HTML case, and style both via an ID. */
#main {
  background-color: #FFF;
  margin: 10px;
  padding: 10px;
  border: 1px solid #E6E6E6;
}

body.pdf > #main {
  border: none;
}

#container > header {
  padding-top: 6em;
  padding-bottom: 1em;
}

body.pdf #container > header {
  padding: 0;
}

#main > #container > section {
  margin-left: 5em;
  position: relative;
  display: block;
}

span.fa
{
  position: absolute;
  top: 4px;
  left: -50px;
  font-size: 30px;
  color: #BFC1C3;
}

hr {
  margin-top: 20px;
  margin-bottom: 20px;
  border: 0;
  border-top: 1px solid #EEE;
}

.tenure, .keywords {
  font-size: 75%;
}

h1 {
  margin: 0;
  font-size: 46px;
}

h2 {
  font-size: 24px;
  color: #BFC1C3;
  text-transform: uppercase;
  font-weight: normal;
}

h3 {
  margin-bottom: 0;
  font-size: 18px;
}

a, a:visited {
  color: #428BCA;
  text-decoration: none;
  font-weight: bold;
}

a:hover {
  text-decoration: underline;
}

.defunct {
  color: #989898;
  font-weight: bold;
}

#summary > p > strong {
  font-size: 1.25em;
}


.label-keyword {
  display: inline-block;
  background: #7eb0db;
  color: white;
  font-size: 0.9em;
  padding: 5px;
  border: 1px solid #357ebd;
  border-radius: 5px;
  margin-top: 2px;
}

.card-skills {
    position: relative;
}
.card-nested {
    min-height: 0;
    margin-bottom: 10px;
    border-width: 1px 0 0 0;
}
.card {
    background: #FFF;
    border-radius: 3px;
    padding: 10px;
}

.skill-level {
  border-radius: 3px;
  position: absolute;
  top: 10px;
  bottom: 10px;
  left: 0;
  width: 10px;
  box-shadow: inset 0 0 1px rgba(0, 0, 0, 0.5);
}
.skill-level .skill-progress {
  position: absolute;
  border-radius: 3px;
  bottom: 0;
  width: 100%;
  -webkit-transition: height 1s ease;
}
.skill-level .skill-progress.beginner {
  height: 50%;
  background: #e74c3c;
}
.skill-level .skill-progress.intermediate {
  height: 70%;
  background: #f1c40f;
}
.skill-level .skill-progress.advanced {
  height: 80%;
  background: #428bca;
}
.skill-level .skill-progress.master {
  height: 95%;
  background: #5cb85c;
}
.skill-info {
  margin-left: 10px;
}
@media (max-width: 480px) {
  .skill-info {
    margin-left: 20px;
  }
}

.list-unstyled {
  padding-left: 0;
  list-style: none;
}

.card-skills {
  position: relative;
}

.space-top {
    margin-top: 10px;
}

#container {
  max-width: 800px;
  margin: 0 auto;
}

#elevator-pitch {
  text-align: center;
  font-size: 24px;
  color: #BFC1C3;
  text-transform: uppercase;
  font-weight: normal;
}

.res-label {
  font-style: italic;
}

Instead of basing the styles off of the base HTML elements (ex <html>, <h1> - <h5>, etc) base them off of <main>.

main {
  display: block;
  box-sizing: border-box;
  font-family: 'Helvetica Neue', Helvetica, 'Lato', sans-serif;
  font-size: 15px;
  color: #333;
  line-height: 1.42857143;
  background-color: #F0F0F0;
  margin: 0;
  padding: 0;
}

/* Adobe or wkhtmltopdf has issues with the <main> tag, so we use <div> for
the PDF case, <main> for the HTML case, and style both via an ID. */
#main {
  background-color: #FFF;
  margin: 10px;
  padding: 10px;
  border: 1px solid #E6E6E6;
}

#container > header {
  padding-top: 6em;
  padding-bottom: 1em;
}

#main > #container > section {
  margin-left: 5em;
  position: relative;
  display: block;
}

main span.fa
{
  position: absolute;
  top: 4px;
  left: -50px;
  font-size: 30px;
  color: #BFC1C3;
}

main hr {
  margin-top: 20px;
  margin-bottom: 20px;
  border: 0;
  border-top: 1px solid #EEE;
}

.tenure, .keywords {
  font-size: 75%;
}

main h1 {
  margin: 0;
  font-size: 46px;
}

main h2 {
  font-size: 24px;
  color: #BFC1C3;
  text-transform: uppercase;
  font-weight: normal;
}

main h3 {
  margin-bottom: 0;
  font-size: 18px;
}

main a, a:visited {
  color: #428BCA;
  text-decoration: none;
  font-weight: bold;
}

main a:hover {
  text-decoration: underline;
}

.defunct {
  color: #989898;
  font-weight: bold;
}

#summary > p > strong {
  font-size: 1.25em;
}


.label-keyword {
  display: inline-block;
  background: #7eb0db;
  color: white;
  font-size: 0.9em;
  padding: 5px;
  border: 1px solid #357ebd;
  border-radius: 5px;
  margin-top: 2px;
}

.card-skills {
    position: relative;
}
.card-nested {
    min-height: 0;
    margin-bottom: 10px;
    border-width: 1px 0 0 0;
}
.card {
    background: #FFF;
    border-radius: 3px;
    padding: 10px;
}

.skill-level {
  border-radius: 3px;
  position: absolute;
  top: 10px;
  bottom: 10px;
  left: 0;
  width: 10px;
  box-shadow: inset 0 0 1px rgba(0, 0, 0, 0.5);
}
.skill-level .skill-progress {
  position: absolute;
  border-radius: 3px;
  bottom: 0;
  width: 100%;
  -webkit-transition: height 1s ease;
}
.skill-level .skill-progress.beginner {
  height: 50%;
  background: #e74c3c;
}
.skill-level .skill-progress.intermediate {
  height: 70%;
  background: #f1c40f;
}
.skill-level .skill-progress.advanced {
  height: 80%;
  background: #428bca;
}
.skill-level .skill-progress.master {
  height: 95%;
  background: #5cb85c;
}
.skill-info {
  margin-left: 10px;
}
@media (max-width: 480px) {
  .skill-info {
    margin-left: 20px;
  }
}

.list-unstyled {
  padding-left: 0;
  list-style: none;
}

.card-skills {
  position: relative;
}

.space-top {
    margin-top: 10px;
}

#container {
  max-width: 800px;
  margin: 0 auto;
}

#elevator-pitch {
  text-align: center;
  font-size: 24px;
  color: #BFC1C3;
  text-transform: uppercase;
  font-weight: normal;
}

.res-label {
  font-style: italic;
}

Note: I removed the pdf-specific styles. Isn't pdf styling already covered in modern-pdf.css?

This way, the styling doesn't rely on the higher order DOM elements.


2.

That makes sense. Injecting the styles inline would be ideal because it would make the html portable*.

*Except in cases where custom fonts are required.

I think my particular usage falls a little too far outside of the scope. I basically have to re-implement the templates from scratch. To keep avoid collisions with global css definitions I have to use the shadow DOM and inject the style at the component-level. So, keeping the template separate from the css is essential.

@hacksalot
Copy link
Member

Just a note that these changes are pending. Thanks!

@evanplaice
Copy link
Author

Awesome! I'll keep an eye out.

@hacksalot hacksalot added this to the v1.0.0 milestone Jan 22, 2016
@hacksalot hacksalot self-assigned this Feb 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants