Rails で Twitter Bootstrap を使用し、レスポンシブ デザイン機能を試しています。モバイル デバイスで中心から外れている 2 つの HTML 要素 (以下のコメントで参照されている h1 要素とフォーム) があります。ただし、ブラウザーを縮小すると、ブラウザーの中央に配置されます (スクリーンショットを参照)。要素がモバイル中心になるようにする方法がわかりません。
ビューに次のコードがあります。
<!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 ファイル:
@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 の場合: