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

Internet Explorer のバージョンによって html 要素の class 属性を切り替えるやつを haml で書く #64

Open
shikakun opened this issue Mar 6, 2014 · 0 comments
Labels

Comments

@shikakun
Copy link
Owner

shikakun commented Mar 6, 2014

IE の条件つきコメントを利用して閲覧してる Internet Explorer のバージョンを把握したり、Modernizr という JavaScript のライブラリを利用して JavaScript を利用できるかどうか調べることができる、以下のような HTML のコードがある。

<!DOCTYPE html>
<!--[if lt IE 7]> <html class='no-js ie6' lang='ja'> <![endif]-->
<!--[if IE 7]> <html class='no-js ie7' lang='ja'> <![endif]-->
<!--[if IE 8]> <html class='no-js ie8' lang='ja'> <![endif]-->
<!--[if IE 9]> <html class='no-js ie9' lang='ja'> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--><html class='no-js' lang='ja'><!--<![endif]-->
  <head>
    <meta charset='utf-8'>
    ...

これを、haml で書くには!

!!!
/[if lt IE 7] <html class='no-js ie6' lang='ja'>
/[if IE 7] <html class='no-js ie7' lang='ja'>
/[if IE 8] <html class='no-js ie8' lang='ja'>
/[if IE 9] <html class='no-js ie9' lang='ja'>
<!--[if (gt IE 9)|!(IE)]><!-->
%html{class: 'no-js', lang: 'ja'}<>
  <!--<![endif]-->
  %head
    %meta{charset: 'utf-8'}

こうやって書けばいいんですね。

参考

@shikakun shikakun added the Haml label Mar 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant