首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >引导-md-4 h2不以移动为中心

引导-md-4 h2不以移动为中心
EN

Stack Overflow用户
提问于 2015-04-29 07:25:42
回答 1查看 107关注 0票数 0

我使用rails制作了一个简单的购物应用程序,它显示了一个产品列表。在移动视图中,当产品堆栈为1长列表而不是3行时,产品h2标记没有对中,并且由于某种原因向右浮动。第一个h2标记的中心很好,但其余的则向右浮动,并且没有正确地居中。我已经尝试了与css相关的所有我能想到的东西

  • text-align: center;
  • margin-bottom: 10px;
  • text-center
  • 想因为它离我们太近而漂浮吗?

这是我的html和css。

代码语言:javascript
复制
<div class="row text-center">
        <% @products.each do |product| %>
          <div class="product col-md-4 text-center">
           <h2><%= link_to product.name, product_path(product) %></h2>
            <%= link_to image_tag(product.image_file_name, product_path(product), :class => 'img-responsive' %>
            <div class="product-info">
                <div class="product-info-left"><%=product.descrip %></div>
                <div class="product-info-right">$<%=product.price %></div>
            </div>
          </div>
        <% end %>
    </div>

Css

代码语言:javascript
复制
@media(max-width:768px) {
    .product-page, .product-show {
        padding-top: 2px;
    }

    .product-info-right, .product-info-left {
        margin-bottom: 10 !important;
    }

    .product > h2{
        text-align: center !important;
    }
}

    .product-info-left {
    float: left;
    width: 50%;
    font-family: 'Pacifico', cursive; 
    font-size: 15px;
}

.product-info-right {
    float: right;
    width: 50%;
    font-family: 'Oswald', sans-serif;
}

.product img {
    height: 200px !important;
    width: 250px !important;
}

.product h2 {
    font-family: 'Oswald', sans-serif;
    font-size: 24px;
}

.product > h2 > a {
    color: black !important;
    border-bottom: 1px solid #1e9b69;
}

我的想法是,这可能是因为这些元素太近了,在默认情况下被正确浮动,但是我试图通过边距、浮动和文本对齐来纠正这种行为,但仍然什么也没有。任何帮助或建议,我可能做错了,将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2015-04-29 07:27:01

在HTML中,您有h2,但是在样式中,您尝试将h1放在线上。

代码语言:javascript
复制
.product > h1{
    text-align: center !important;
}

一定有

代码语言:javascript
复制
.product > h2 {
    text-align: center !important;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29936974

复制
相关文章

相似问题

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