Despite the property resize:
not be supported in Firefox when used in iframes, as already stated in the other reply that was mentioned in the MDN, yet it is a property that will work perfectly in some other elements.
No need for any hack or library wild to achieve the desired effect, simply create a <div>
and in it you will add the resize:
(recommend adding the display: inline-block;
), then put the size you want and inside the <div>
put your <iframe>
, defining width and height as 100%
I created an example that works with horizontal, vertical and both:
Note¹: it is necessary to add the overflow: hidden
or overflow: auto
or overflow: scroll
in the element you want to use resize:
, except in elements <textarea>
which already has scroll by default (except if using overflow: visible;
)
Note²: it is necessary position:relative;
to work in Chrome, because if the resize cursor is not, it will be overwritten by the iframe
.resize, .resize-v, .resize-h {
position: relative;
display: inline-block;
overflow: hidden;
min-width: 50px; /* define largura minima */
min-height: 50px; /* define altura minima */
width: 200px; /* define largura padrão/inicial */
height: 200px; /* define altura padrão/inicial */
}
.resize-v {
resize: vertical;
}
.resize-h {
resize: horizontal;
}
.resize {
resize: both !important; /*prioridade, acaso adicione resize com as outras classes*/
}
.resize > iframe,
.resize-v > iframe,
.resize-h > iframe {
background-color: transparent;
width: 100%;
height: 100%;
resize: none;
border: none;
}
/* as cores abaixo são apenas para você diferenciar, pode remove-las */
.resize {
background-color: #f00;
}
.resize-v {
background-color: #00f;
}
.resize-h {
background-color: #fc0;
}
<div class="resize">
<iframe srcdoc="redimensiona vertical e horizontal"></iframe>
</div>
<hr>
<div class="resize-h">
<iframe srcdoc="redimensiona horizontal"></iframe>
</div>
<hr>
<div class="resize-v">
<iframe srcdoc="redimensiona vertical"></iframe>
</div>
Alternative
The only problem with the example is that in Chrome when the iframe is small the "cursor" to drag some when the scroll appears, one way around this would be to discount the height of the iframes, thus:
height: calc(100% - 14px);
An example:
.resize, .resize-v, .resize-h {
position: relative;
display: inline-block;
overflow: hidden;
min-width: 50px; /* define largura minima */
min-height: 50px; /* define altura minima */
width: 200px; /* define largura padrão/inicial */
height: 200px; /* define altura padrão/inicial */
}
.resize-v {
resize: vertical;
}
.resize-h {
resize: horizontal;
}
.resize {
resize: both !important; /*prioridade, acaso adicione resize com as outras classes*/
}
.resize > iframe,
.resize-v > iframe,
.resize-h > iframe {
background-color: transparent;
width: 100%;
height: calc(100% - 14px);
resize: none;
border: none;
}
/* as cores abaixo são apenas para você diferenciar, pode remove-las */
.resize {
background-color: #f00;
}
.resize-v {
background-color: #00f;
}
.resize-h {
background-color: #fc0;
}
<div class="resize">
<iframe srcdoc="redimensiona vertical e horizontal"></iframe>
</div>
<hr>
<div class="resize-h">
<iframe srcdoc="redimensiona horizontal"></iframe>
</div>
<hr>
<div class="resize-v">
<iframe srcdoc="redimensiona vertical"></iframe>
</div>
I just saw it :c is there is no hack for this ?
– AnthraxisBR
@Anthraxisbr I don’t know any, but I had an idea and I’m testing a code here to see if it works. If it works I’ll send you news.
– Sam
@Anthraxisbr I was able to create a hack using jQuery-ui on this Jsfiddle: https://jsfiddle.net/a4y09g68/1/ .. it’s not 100% perfect but it works :)
– Sam
I wish I could give more than one correct answer, there is even a mini editor of the plugin in your xD, an alternative to be analyzed, but the answer of Guilherme was simpler and only with css.
– AnthraxisBR
worked, the important thing to work is to set the 'overflow: Hidden;' in the element that will receive the 'resize:vertical', and set the iframe with 'width' and 'height' 100%.
– AnthraxisBR