dongrao9454 2014-12-10 07:24 采纳率: 100%
浏览 20

媒体查询以对齐图像

I yesterday posted the question beneath in another post. It seems that it went messed up. (Posting date, comments... etc) I hope it will go better with this post. I invite the commenters on the other post to look at it and comment aqain. Thanks in advance.

On my woocommerce single product page is a fairly large thumbnail shown. For one product a portrait image for another a landscape. I want to center the portrait ones in the surrounding div. I've tried it with margin-left and margin-right set to x%. This works fine for the portrait ones but the landscape ones are pushed to far to the right. The thumbnail images are floating to the left. Changing this will mess up the size.

In short, i want the portrait thumbnails centered and the landscape thumbnails standard (aligned to the left).

I was wondering can this be achieved with a media query or do I oversee a more simple solution. Please advice.

EDIT

Hereby the generated html/css code:

.woocommerce img,
.woocommerce-page img {
     height: auto;
     max-width: 100%;
}
.woocommerce #content div.product div.images,
.woocommerce div.product div.images,
.woocommerce-page #content div.product div.images,
.woocommerce-page div.product div.images {
     float: left;
     max-width: 100%;
}
   <body class="single single-product postid-3758 logged-in admin-bar no-customize-support custom-background woocommerce woocommerce-page custom-background-white custom-font-enabled single-author">

<div id="primary" class="site-content">
  <div id="content" role="main">

    <div itemscope itemtype="http://schema.org/Product" id="product-3758" class="post-3758 product type-product status-publish has-post-thumbnail downloadable virtual taxable shipping-taxable purchasable product-type-simple product-cat-adri-2 product-cat-hellevoetsluis product-tag-adri product-tag-hellevoetsluis product-tag-zaandam instock">

      <div class="images">
        <a href="http://etc" itemprop="image" class="woocommerce-main-image zoom" title="SONY DSC" data-rel="prettyPhoto">
          <img width="567" height="853" src="http://placehold.it/567x853" class="attachment-shop_single wp-post-image" alt="SONY DSC" title="SONY DSC" />
        </a>
      </div>

      <div class="summary entry-summary">
        <h1 itemprop="name" class="product_title entry-title">Photo 3</h1>
        <div itemprop="offers" itemscope itemtype="http://schema.org/Offer">

          <p class="price"><span class="amount">&euro;xx,xx</span>  <small class="woocommerce-price-suffix">Exclusief BTW</small>
          </p>

          <meta itemprop="price" content="xx" />
          <meta itemprop="priceCurrency" content="EUR" />
          <link itemprop="availability" href="http://schema.org/InStock" />
        </div>
      </div>
    </div>
  </div>
</div>
</body>

</div>
  • 写回答

2条回答 默认 最新

  • douxing8323 2014-12-10 07:37
    关注

    You're right. You can achieve what you want using media query just change the float:left to float:inherit or float:none

    here is the sample code.

        //when screen is resize to 300px
        @media screen and (max-width: 300px) {
                .woocommerce #content div.product div.images,
                .woocommerce div.product div.images,
                .woocommerce-page #content div.product div.images,
                .woocommerce-page div.product div.images {
                     float: inherit;
                     //more styles here
                 }
            }
    

    it is ok if you don't include max-width: 100%;

    评论

报告相同问题?

悬赏问题

  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗