【问题标题】:How can I overwrite all images width in php html?如何覆盖 php html 中的所有图像宽度?
【发布时间】:2012-12-13 17:31:03
【问题描述】:

我想将所有图像宽度覆盖为 90%。但是有些图片有css文件中的样式,有些看起来像这样:

 <img src="sss" style="something" ... 

我喜欢移动版网站中的所有样式。

就是这个:http://mikrobusz-berles.com 图片太大了。我想为移动版本调整它们的大小。有什么想法吗?

【问题讨论】:

标签: php html css image resize


【解决方案1】:

您可以使用输出缓冲区(请参阅手册) 它将捕获整个页面

 ob_start();

 //Content here
 $contents=ob_get_flush();

并在 $contents 上使用一些正则表达式来覆盖宽度,它们会回显 $contents

【讨论】:

    【解决方案2】:

    如果您只想在用户使用手机的情况下将宽度更改为 90%,您可以执行以下操作。

    编写一个CSS类如下:

    .mobile-image {
        width: 90% !important;
    }
    

    现在使用jquery知道用户是否在使用手机,然后使用addClass()方法如下,将上述css类添加到所有图片中。

    $(document).ready(function(){
        // Check if a user is logged in using a Mobile Phone or a Handheld Device.
        if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
            // To adjust the width
            $('img').addClass('mobile-image');
            // To Remove style attribute
            $('img').attr('style') = '';
        }
    }
    

    【讨论】:

      【解决方案3】:

      将此添加到您的 css 文件中:

      .jFlowSlideContainer img{
         width:99.9%;
      }
      

      【讨论】:

        【解决方案4】:

        您可以使用 jquery 再次覆盖样式。 代码:

        $(document).on('pageinit',function(){
            $('img').css('width','50%');
        });
        

        此代码适用于您正在使用的 jquery mobile。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-01-22
          • 1970-01-01
          • 2021-02-04
          相关资源
          最近更新 更多