首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用带有引导的rails的一些HTML元素不以移动浏览器为中心

问使用带有引导的rails的一些HTML元素不以移动浏览器为中心
EN

Stack Overflow用户
提问于 2013-09-18 05:01:09
回答 1查看 718关注 0票数 0

我正在使用带有Rails的Twitter引导程序,并尝试它的响应性设计功能。我有两个HTML元素(在下面的注释中引用的h1元素和表单),它们在移动设备上偏离中心。但是,当我缩小浏览器时,它们是以我的浏览器为中心的(见屏幕截图)。我不知道如何确保这些元素以移动为中心。

视图中有以下代码:

代码语言:javascript
复制
<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><%= full_title(yield(:title)) %></title>
    <%= stylesheet_link_tag "application", media: "all",
                                           "data-turbolinks-track" => true %>
    <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
    <%= csrf_meta_tags %>
  </head>
  <body>
  <header class="navbar navbar-fixed-top navbar-inverse">
    <div class="navbar-inner">
      <div class="container">
        <%= link_to "ReRide", root_path, id: "logo" %>
        <nav>
          <ul class="nav pull-right">
            <li><%= link_to "Home",    root_path %></li>
            <li><%= link_to "About",    about_path %></li>
          </ul>
        </nav>
      </div>
    </div>
  </header>
    <div class="container">
      <% flash.each do |key, value| %>
        <div class="alert alert-<%= key %>"><%= value %>
          <a class="close" data-dismiss="alert">×</a>
        </div>
      <% end %>
      <div class="center hero-unit">
        <h1>Welcome to ReRide!</h1>   <!--THIS IS OFF CENTER-->
        <p>Where selling a used bike is painless </p>
        <p>
          <%= simple_form_for @contact, :html => {:class => "form-inline"} do |f| %>  <!--THIS IS OFF CENTER-->
            <%= f.input_field :email, placeholder: 'Email', label: false, input_html: { class: 'input-medium' } %>
            <%= f.input_field :potential_relationship, input_html: { class: 'input-medium' }, collection: Contact::RELATIONSHIP_CHOICES.invert, prompt: "I am a:", label: false%>
            <%= f.button :submit, 'Stay Informed', :class => 'btn btn-primary' %>
          <% end %>
        </p>
      </div>
      <footer class="footer">
        <small>
          <a href="http://www.reridebikes.com/">ReRide Bikes</a>
        </small>
      </footer>
    </div>
  </body>
</html>

CSS文件:

代码语言:javascript
复制
@import "bootstrap";
body {
  padding-top: 60px;  
}
@import "bootstrap-responsive";

/*Everything below is overriding Bootsrap CSS*/

/* mixins, variables, etc. */

$grayMediumLight: #eaeaea;

@mixin box_sizing {
  -moz-box-sizing: border-box; 
  -webkit-box-sizing: border-box; 
  box-sizing: border-box;
}

/* universal */

html {
  overflow-y: scroll;
  width: auto;  
  overflow-x: hidden; 
}

body {
  width: auto; 
  overflow-x: hidden; 
}

section {
  overflow: auto;
}

textarea {
  resize: vertical;
}

.center {
  text-align: center; 
  h1 {
    margin-bottom: 10px;
  }
}

/* typography */

h1, h2, h3, h4, h5, h6 {
  line-height: 1;
}

h1 {
  font-size: 3em;
  letter-spacing: -2px;
  margin-bottom: 30px;
  text-align: center;
}

h2 {
  font-size: 1.2em;
  letter-spacing: -1px;
  margin-bottom: 30px;
  text-align: center;
  font-weight: normal;
  color: $grayLight;
}

p {
  font-size: 1.1em;
  line-height: 1.7em;
}

/* footer */

footer {
  margin-top: 45px;
  padding-top: 5px;
  border-top: 1px solid $grayMediumLight;
  color: $grayLight;
  a {
    color: $gray;
    &:hover {
      color: $grayDarker;
    }
  }
  small {
    float: left;
  }
  ul {
    float: right;
    list-style: none;
    li {
      float: left;
      margin-left: 10px;
    }
  }
}

/* forms */

input, textarea, select, .uneditable-input {
  border: 1px solid #bbb; 
}


input {
  height: auto !important;
}

#error_explanation {
  color: #f00;
  ul {
    list-style: none;
    margin: 0 0 18px 0;
  }
}

.field_with_errors {
  @extend .control-group;
  @extend .error;
}

在皱缩的铁丝网中:

​

在iPhone上:

​

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-18 05:12:08

你需要媒体查询来动态地改变那个大人物的字体大小。例如:

代码语言:javascript
复制
@media only screen 
  and (max-width : 320px) {
  h1 {
      font-size: 2em;
     }
}

这意味着,在最大宽度为320 px的屏幕上,使h1字体大小为2em (与原来文章中默认的3em不同)

下面是媒体查询的小页面

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18864202

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档