`
peryt
  • 浏览: 54396 次
  • 来自: ...
最近访客 更多访客>>
社区版块
存档分类
最新评论
  • waiting: 既然都指定了dataType为'script'那就不必特别在b ...
    jQuery

css and layout in rails

阅读更多

First, let's see a sample layout file in rails, and explain it step by step:

 

 

<!DOCTYPE html>
<html>
  <head>
    <title><%= title %></title>
    <%= csrf_meta_tag %>
    <!--[if lt IE 9]>
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->    
    <%= stylesheet_link_tag 'blueprint/screen', :media => 'screen' %>
    <%= stylesheet_link_tag 'blueprint/print',  :media => 'print' %>
    <!--[if lt IE 8]><%= stylesheet_link_tag 'blueprint/ie' %><![endif]-->
    <%= stylesheet_link_tag 'custom', :media => 'screen' %>
  </head>
  <body>
    <div class="container">
      <header>
        <%= image_tag("logo.png", :alt => "Sample App", :class => "round") %>
        <nav class="round">
          <ul>
            <li><%= link_to "Home", '#' %></li>
            <li><%= link_to "Help", '#' %></li>
            <li><%= link_to "Sign in", '#' %></li>
          </ul>
        </nav>
      </header>
      <section class="round">
        <%= yield %>
      </section>
    </div>
  </body>
</html>

 

1. rails 3 use html5 as default, as indicated in <!DOCTYPE html>

2. since html5 is too new, some old IE browsers like IE8 don't support totally support it, so we include some javascript code (known as "html5shiv")to work around it.

 

<!--[if lt IE 9]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

 this code piece is weird.

it means, this line of script including will only be included if IE version is less than IE9.

 

[if lt IE 9] is not rails, it is conditional comment supported only by IE. This purpose is just supplying a way to provide code that only work in IE, not any other browsers. This is very useful

 

3. then 

 

 

    <!--[if lt IE 8]><%= stylesheet_link_tag 'blueprint/ie' %><![endif]-->

 works the same way, if current browser less than IE8, it will include another css file.

This css file fixed many IE-only issues.

 

4. next, we include another css file, called "custom", to put your custom css, we haven't created it yet.

css is forgiving, even if there is no this file, our page still work fine.

 

5.next, we put all the contents in to a container div,

<div class="container">

</div>

This is needed by blueprint,

 

the div tag in html is a generic division, it does nothing but divding the doc into distinct part.

in older html, div tags are used for nearly all site divisions, but html5 adds the "header", "nav" and "section" elements, for divisions common to many apps.

 

then, there are header and section elements, the header contains the site navigation(nav), 

the section element contains the site's main content.

 

all html elements, including divs and the new html5 elements, can be assigned classed and ids.

these are merely labels, and are useful for styling with CSS. The main differences between classes and ids is that classed can be used multiple times on a page, but ids can only be use once.

 

<img alt="Sample App" class="round" src="/images/logo.png" />
 

6. inside the header is a rails helper called "image_tag"

 

<%= image_tag("logo.png", :alt => "Sample App", :class => "round")%>

 note, we also passed a hash as second param,  

let's see the html generated:

 

<img alt="Sample App" class="round" src="/images/logo.png" />

 the alt attr is what will be displayed if there is no image.

 

a. you can see for a img tag, it is not <img></img>

instead, it is <img ....... />

this kind of tag are known as self-closing tags.

 

b. the alt attr is optional, if you don't specify this param, rails will auto use the file name of the image file,  if image doesn't display.

 

c. rails helpers ofter take options hashes in this way, giving us the flexibility to add arbitrary html options without ever leaving Rails!

 

7. next is a list of navigation links, using unordered list tag <ul>

link_to is a rails helper to creat links, which will create <a href=""></a> as html.

the 1st argument is the link text.

the 2nd argument is the url, for now we just use "#" means blank link, link to itself. we will fill it with useful url later.

 

the generated html will be

<nav class="round">
  <ul>
    <li><a href="#">Home</a></li>
    <li><a href="#">Help</a></li>
    <li><a href="#">Sign in</a></li>
  </ul>
</nav>
 

 

0
0
分享到:
评论

相关推荐

    Ruby on Rails 学习案例

    12. **Asset Pipeline**:Rails的资产管道负责处理CSS、JavaScript和其他静态资源,通过Sprockets编译和合并文件,实现压缩和缓存,提升应用性能。 13. **Heroku部署**:Rails应用可以便捷地部署到Heroku这样的云...

    HTML5_and_CSS3_2010

    - **响应式设计**:通过媒体查询(Media Queries)和流式布局(Fluid Layout),CSS3支持创建自适应不同设备屏幕尺寸的网站,实现真正的响应式设计。 - **动画与过渡效果**:CSS3引入了`@keyframes`规则,允许...

    blog.tar.gz_Rails

    - `public/`:静态资源文件,如CSS、JavaScript、图片等,对外直接可用。 - `spec/`:RSpec或其他测试框架的测试文件。 - `Gemfile`:定义项目依赖的Gem包。 - `Gemfile.lock`:记录具体版本的Gem包,确保部署时一致...

    关于css排版的几点心得

    2. **定位机制**:CSS提供了三种定位机制:正常流(block layout)、浮动(float)和绝对定位(position: absolute)。正常流遵循从左到右、从上到下的排列方式;浮动用于创建多列布局,但可能导致父元素高度塌陷;...

    andy_rails_toolbox

    Andy Rails工具箱 Andy Rails Toolbox包含许多有用的Rails开发帮助器。 安装 将此行添加到您的应用程序的Gemfile中: gem 'andy_rails_toolbox' 然后执行: $ bundle 或将其自己安装为: $ gem install andy_...

    sample_app:Rails教程第3章

    13. **布局(Layout)**: Rails中的布局定义了页面的通用结构,如头部和尾部。`app/views/layouts/application.html.erb`是默认布局。 14. **Bootstrap或Sass**: 示例应用可能使用Bootstrap库来快速创建响应式设计...

    rail 4 days

    **Sharing Variables between the Templates and the Layout** 有时需要在不同的视图文件之间共享变量。可以通过实例变量或局部变量来实现。 **The ToDo List screen** 了解如何设计和实现 To-Do List 的主屏幕。...

    faee:用 Ruby on Rails 开发的食品服务 CMS

    4. 布局和部分视图:Rails支持布局(Layout)和部分视图(Partial),用于页面结构的复用。 5. 表单处理:使用FormHelper生成表单元素,处理用户输入,与控制器的行动关联。 6. 测试驱动开发:Rails鼓励TDD(Test-...

    Widgets-Layout

    该项目是通过引导的。 您将在下面找到一些有关如何执行...Ruby on Rails 在开发中代理API请求 配置代理后出现“无效的主机头”错误 手动配置代理 配置WebSocket代理 在开发中使用HTTPS 在服务器上生成动态&lt;met

    k_admin:带有 KAdmin 主题的 Rails 引擎,其中包含准备工作的 CMS

    #KAdmin 此 Rails 引擎为您提供构建具有以下外观和感觉的 CMS 所需的工具: : 该项目使用 KAdmin 的扩展许可证 为了为 CMS 提供外观和感觉包装器,您必须指定布局并包含帮助程序: class ItemsController &lt;...

    react-routes-multi-layout

    Ruby on Rails 在开发中代理API请求 配置代理后出现“无效的主机头”错误 手动配置代理 配置WebSocket代理 在开发中使用HTTPS 在服务器上生成动态&lt;meta&gt;标记 预渲染为静态HTML文件 将数据从服务器注入

    moonlanders.github.io

    4. **布局技术**:CSS提供了多种布局方式,如流体布局、网格布局(CSS Grid)、Flexbox(弹性盒子)和最近的CSS Layout Module Level 3(CSS 模块布局)。 5. **响应式设计**:使用 `@media` 查询,CSS可以根据设备...

    firstClass:雅各布的电子商务

    头等舱 部署的URL: : 概述 NCfirstclass允许用户下订单,该订单将由管理员处理,以将产品交付给用户。 管理员将能够查看用户信息,已订购产品的名称以及其商品代码,如果是在库存中则要发货,如果不是,则...|__ css/

    yzclaire.github.io:Claire Zhang的个人资料

    在Ruby on Rails中,开发者通常使用Markdown或HTML来编写内容,CSS和JavaScript来处理样式和交互,而Ruby则用于后端逻辑和数据库交互。yzclaire.github.io-master这个文件名表示这是项目的主要分支,可能是GitHub...

    railsapps.github.com:RailsApps网站的内容

    要更改布局和设计,请在railsapps.github.io.wiki存储库中编辑_Layout.html文件以及CSS和Javascript。 然后,使用位于gem从Wiki生成静态网页。 要提交生成的网页,您需要拥有组织团队成员的存储库读写权限。 目标 ...

    javascript框架介绍

    它提供了一套DOM操作API和事件处理机制,作为核心框架,支撑了一系列的JavaScript扩展库,成为了许多开发者首选的底层框架,尤其是在Ruby on Rails中的广泛应用。Scriptaculous即基于Prototype,用于实现各种JS组件...

    天象移动客户端云定制平台技术文档.pdf

    - "webContentProviders"、"ResourceManager"、"Layoutfiles"、"NotificationManager"、"ActivityManager"等词汇是Android系统中常见的组件和管理器,用于管理应用的内容、资源、布局、通知和活动。 - "AndroidC/...

    Javascript框架Script.aculo.us的英文文档

    - **Block Elements/Inline Elements/Giving Elements Layout**:介绍如何使用CSS布局元素。 通过上述知识点的总结,我们可以看到Script.aculo.us不仅提供了丰富的视觉效果,还集成了实用的UI控制组件,使得开发者...

    Shopify

    " Liquid "是Shopify的默认模板语言,由Ruby on Rails社区开发。这是一种动态、声明式的标记语言,专门用于构建Shopify商店的前端界面。 Liquid设计的目标是安全,确保即使在用户输入的数据被渲染时,也不会对服务器...

    font_awesomex:用于Elixir和Phoenix Framework的Font Awesome标记渲染助手

    接着,在你的Phoenix项目的`web/templates/layout/application.html.eex`或相应的布局文件中,引入`font_awesomex`的CSS样式表。这样,你的应用就能识别并正确显示所有的Font Awesome图标。 在实际开发中,`font_...

Global site tag (gtag.js) - Google Analytics