Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inline styling with hiccup

Tags:

html

css

clojure

I have an html document that I generate with clojure hiccup. When I send the file as an attachment to an email, the css gets stripped out. The css is external and being referenced in the head of the file like below:

[:head
  [:title "My Title"]
   (include-css "css/mycss.css")]

I heard mail servers strip out all external css so it does not interfere with theirs. One solution I was able to fin was to do an inline styling. For example if I have the below html, how do I perform inline styling on it.

[:thead
   [:tr [:th "First column"] [:th "Second column"] [:th "Third column"]]]

Additionally, feel free to suggest if there is a better answer to what I want to do. Thanks!

like image 939
sparrow Avatar asked Aug 26 '14 21:08

sparrow


People also ask

How do you apply inline styling?

Inline CSS An inline style may be used to apply a unique style for a single element. To use inline styles, add the style attribute to the relevant element. The style attribute can contain any CSS property.

What does inline styling mean?

Inline styles are styles that are applied to a specific element within the body section of the webpage. The style will be applied to that individual element only rather than to the entire page (internal style) or across all linked pages (external style sheet). In this example a style is applied to a paragraph.

Is inline styling good?

Inline styles, while they have a purpose, generally are not the best way to maintain your website. They go against every one of the best practices: Inline styles don't separate content from design: Inline styles are exactly the same as embedded font and other clunky design tags that modern developers rail against.


1 Answers

hiccup supports attributes right out of the box with the {} syntax, so you could simply use this for settings style attributes on elements easily, e.g., [:p {:style "color:#E0E0E0"} "My paragraph"] will put the color on the paragraph. But I guess in your case, it might be more convenient to put the general style definitions in the head element, using the style element. hiccup supports :style for this as one would expect, e.g.

[:head [:title "My title"]
       [:style "body { padding-top: 60px; }"]].
like image 62
schaueho Avatar answered Nov 03 '22 00:11

schaueho