Ruby on Rails / Rubygems / FullStack / Git / Mac notes.
How to Put Css in Html Body?
There are two ways to set css file into our html documents.
first way: using pure javascript to append css file into head part of html.
123456789101112131415161718
<script type="text/javascript">functionloadCSS(filename){varfile=document.createElement("link")file.setAttribute("rel","stylesheet")file.setAttribute("type","text/css")file.setAttribute("href",filename)if(typeoffile!=="undefined")document.getElementsByTagName("head")[0].appendChild(file)}//just call a function to load a new CSS:loadCSS("path_to_css/file.css")</script>
Fashion way is to use style tag in body. (notice: some old browsers would not support this.)
1234567891011121314151617
<!DOCTYPE html><html><head></head><body><divid ="scoped-content"><style type ="text/css"scoped>h1{color:red;}</style><h1>Hello</h1></div><h1>World</h1></body></html>