html - 没有绝对位置的水平居中 float div

标签 html css

我无法将页面上的 div( Logo )居中。我已经尝试了一些方法,但它们似乎没有用。

通过将容器的文本对齐设置为中心并将绝对位置设置为 grid_4(右:0;),我能够使 Logo 在页面上居中。但是,当最小化浏览器时,2 个 div 会重叠。

    <!-- header -->
<header>

  <div class="container">


    <div class="grid_8 center-touch full-width wow fadeInDown animated">

      <a href="/">                       
        {% if settings.use_logo %}
        <img src="{{ 'logo.png' | asset_url }}" alt="{{ shop.name | escape }}" class="logo" />
        {% else %}
        <h1 class="logo">{{ shop.name | escape }}</h1>
        {% endif %}
      </a>

    </div>

    <div class="grid_4 right m-t-35 m-b-10 hide-touch wow fadeInDown animated">

      <div class="cart">

        <span class="total">{{ cart.total_price | money_with_currency }}</span>

      </div>

      <a href="/cart" class="cart-btn" title="Your cart"><span class="count">{{ cart.item_count }}</span></a> 

    </div>

  </div>




  <div class="clear"></div>

  {% include 'navigation' %}

</header>

最佳答案

给 anchor 标签,给css属性如下:

.grid_8 > a {
display: block;
width: 100%;
text-align: center;}
.grid_8 > h1 {
display: inline-block;}

这就像一个魅力。

关于html - 没有绝对位置的水平居中 float div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31412595/

相关文章:

javascript - 在 Jquery 中,需要从 CSS 中获取数字值而不是固定数字

html - 表格单元格边框是否算作其内容的一部分?

javascript - 可恢复的 Youtube uploader 如何工作?

javascript - 从浏览器打印重复线性渐变

php - 如何制作Wordpress自定义页面

css - 带站点基础的全屏布局

javascript - 在 if else 语句中传递 id 属性

jquery - 展开 jQuery 列表

html - Ionic,数组中的 HTML

html - 如何使通过 bootstrap css 加载的图形响应?