Remove attributes “height” and “width” of the imag

2019-01-23 18:16发布

In order to create a responsive website with Typo3 and Twitter Bootstrap, I would like to remove the height and width attributs of images

Here's how images are generated in Frontend via content element of type text & image and image

<img src="typo3temp/pics/a625b79f89.jpg" width="300" height="226" alt="blabla" />

I would like to remove the dimension attributes and get this:

<img src="typo3temp/pics/a625b79f89.jpg" alt="blaba" />

Can anyone help me ?

12条回答
Evening l夕情丶
2楼-- · 2019-01-23 18:57

Use jquery

set an id to your image object:

<img src="typo3temp/pics/a625b79f89.jpg" width="300" height="226" alt="blabla" id="myimage" />

$('#myimage').removeAttr("heigth").removeAttr("width");

here is alternative javascript code:

var myImage= document.getElementById("myimage");
myImage.removeAttribute("heigth");
myImage.removeAttribute("width");
查看更多
够拽才男人
3楼-- · 2019-01-23 18:58

FYI: There is no way to remove this with typoscript. The width and height attribute is hardcoded in sysext/cms/tslib/class.tslib_content.php function cImage. (Typo3 4.7)

查看更多
女痞
4楼-- · 2019-01-23 19:02

This will be possible with TYPO3 6.2 LTS. Checkout http://forge.typo3.org/issues/49723.

查看更多
我只想做你的唯一
5楼-- · 2019-01-23 19:04

To remove the effects of fixed width and/or height attributes without actually removing these attributes you can set them back to "auto" in your CSS definitions:

img {
    height: auto !important;
    width: auto !important;
}

I suggest to do that only for the img tags where you really need the pictures to be fluid. This could be done by adding an id or class to the img tags or any surrounding tag.

E.g. if your fluid images are located in a wrapper div with class "fluid_pics" you could use:

.fluid_pics img {
    height: auto !important;
    width: auto !important;
}

Often you will only need to set the height back to auto, as the width is already overwritten to be 100% by your framework (e.g. Twitter Bootstrap).

查看更多
对你真心纯属浪费
6楼-- · 2019-01-23 19:04

There is a solution for old TYPO3s with TYPOSCRIPT:

stdWrap {
    replacement {
        10 {
            search = /\s+(width|height)="[^"]+"/
            useRegExp = 1
            replace =
        }
    }
}

Use this stdWrap-TS where your image is rendered.

查看更多
够拽才男人
7楼-- · 2019-01-23 19:06

Call an image tag in document.ready function.

$('img').removeAttr('width').removeAttr('height');
查看更多
登录 后发表回答