Another week, another question I'm afraid. I've searched but I can't find an appropriate fix for this. I have an svg image with a number of areas in and I want to show a new iframe, which I have wrapped in a div, on top of the existing content when the links in the svg image are clicked. The div will be the same each time but the content of the iframe will be sourced from a different internal page for each link clicked.
The link part of this seems to work as I have removed the 'display:none' from the '.ifallc:empty' and I can see the iframe in the div is being populated when I click the links.
The problem is that when I add '.ifallc:empty {display: none;}' the iframe disapears on page refresh but it does not come back when I click the link to populate the iframe.
My question is, is an iframe with content from another page loaded still considered empty?
And if it is is there a simple way around this?
There are going to be a lot of data in the links and I am trying to prevent all the data on the linked pages from loading before it needs to be.
I hope there is enough code here to see whats going on.
box-sizing: border-box;
position: absolute;
top: -.2rem;
left: -.1rem;
z-index: 2;
/*background-color:#93c6e2;*/
border: .15rem solid #222;
border-bottom-right-radius: 0.5rem;
background: rgb(85, 85, 85);
height: auto;
width: auto;
max-width: 70%;
/* display: auto; */
/* background: linear-gradient(rgb(85, 85, 85),rgb(255, 255, 255)); */
/* display: none; /* FOR USE WHEN REQUIRED */
}
.ifallc { /*the iframe*/
display: auto;
box-sizing: border-box;
margin: auto;
border: auto;
}
.ifallc:empty {
display: none;
}
<a href="peif.html" target="ifall">
<path id="pe" class="landxx pe" d="m 649.707,798.409 c 0.997,-2.059 1.546,-3.468 3.113,-5.222 0.7,-0.783 1.24,-1.722 2.086,-2.366 0.613,-0.467 1.945,-1.093 2.001,-1.993 0.994,0.284 2.042,4.348 1.178,4.856 -0.629,0.37 -1.347,0.04 -1.8,0.682 -0.517,0.735 -0.401,1.737 0.622,1.882 -0.845,1.126 -0.609,2.552 0.724,1.115 1.17,-1.261 1.759,-0.377 2.87,0.565 0.952,0.808 2.042,-0.417 2.792,0.799 0.77,1.25 0.795,3.32 2.582,3.657 1.509,0.285 1.604,0.206 2.036,-1.463 2.884,-11.149 5.237,-15.065 1.92,-2.984 -0.482,1.754 0.515,-3.174 1.261,-4.859 0.383,-0.866 0.687,-1.349 0.701,-2.345 0,-0.632 0.957,-2.523 1.315,-0.825 0.241,-0.39 0.288,-0.8 0.141,-1.229 -0.06,-0.553 0.75,-1.151 1.045,-1.542 0.768,-1.021 1.729,-1.778 2.888,-2.309 2.522,-1.156 5.474,-1.581 7.776,-3.179 4.842,-3.362 8.195,-8.395 9.248,-14.131 0.394,0.417 0.873,0.583 1.439,0.5 -0.713,-1.66 0.03,-3.129 -0.958,-4.546 -0.39,-0.558 -2.329,-2.255 -2.209,-2.944 0.817,0.139 1.77,0.418 2.544,-0.04 0.767,-0.454 0.524,-0.602 1.389,-0.281 1.492,0.553 2.596,1.145 3.626,2.386 1.339,1.615 2.096,2.211 2.737,4.276 0.268,0.861 -0.07,1.565 1.122,1.668 1.151,0.1 0.85,0.56 1.646,1.271 1.544,1.381 2.681,0.646 3.219,3.003 0.417,1.826 0.339,2.265 2.286,2.848 2.098,0.628 0.117,3.076 1.188,4.296 0.581,0.661 1.487,0.886 2.335,0.851 0.529,-0.07 1.061,-0.118 1.595,-0.142 0.708,0 1.535,0.418 2.163,0.396 1.443,-0.05 3.152,-1.094 3.778,-2.353 0.661,-1.329 2.487,1.212 3.277,1.273 1.191,0.09 3.102,-1.774 3.95,-1.153 0.677,0.496 1.202,1.391 1.854,1.838 0.626,0.43 2.098,0.313 2.483,0.722 1.574,1.67 1.598,2.272 0.368,4.22 -0.985,1.56 -2.899,4.229 -3.172,6.044 -0.327,2.171 2.174,0.471 3.113,1.291 0.758,0.661 1.318,1.568 1.885,2.39 0.273,0.395 0.584,0.579 0.447,0.907 -0.09,0.7 -0.704,0.938 -1.131,0.151 -0.193,0.24 -0.386,0.48 -0.58,0.72 -1.122,-1.524 -3.609,-2.516 -5.024,-0.729 -1.613,2.038 -5.125,1.5 -7.443,2.114 -1.214,0.322 -1.801,1.67 -3.004,2.045 -1.264,0.395 -0.853,0.902 -1.695,1.66 -2.018,1.819 -3.416,1.297 -3.446,4.415 -0.01,1.081 0.06,1.987 -0.578,2.928 -0.603,0.895 -1.323,1.792 -1.083,2.939 0.249,1.19 1.275,2.882 -0.06,3.8 -1.119,0.771 -2.177,1.165 -3.094,2.24 -0.669,0.784 -1.017,1.675 -0.803,2.708 0.115,0.5 0.289,0.981 0.521,1.44 -0.559,0.243 -1.14,0.548 -1.561,1.001 -1.624,1.748 3.168,3.265 1.201,4.468 1.003,0.655 1.697,1.851 1.909,3.015 0.124,0.681 0.593,0.918 1.085,1.315 0.616,0.496 0.558,1.252 0.965,1.87 0.715,1.083 2.093,1.593 2.595,2.847 0.599,1.495 -0.55,2.408 -1.371,3.483 1.777,0.93 4.389,0.09 6.154,1.267 1.146,0.761 2.204,2.739 1.766,4.133 2.387,0.3 5.447,0.817 7.57,-0.636 1.34,-0.917 3.087,-4.232 4.891,-4.254 -0.211,0.867 -0.885,0.911 -0.355,1.807 0.562,0.951 -0.378,1.9 -0.318,2.986 0.154,2.824 0.251,5.72 0.593,8.527 0.927,-0.813 1.554,0.849 2.52,0.755 1.332,-0.13 2.266,-1.179 3.635,-1.167 1.306,0.01 2.252,-0.139 2.632,1.152 0.578,1.961 1.963,3.579 2.957,5.368 1.001,1.801 1.998,3.604 3.028,5.39 0.896,1.552 1.69,2.53 0.221,3.63 -1.295,0.969 -1.448,2.719 -0.977,4.115 0.408,1.205 0.109,2.815 0.177,4.988 0.03,0.937 1.17,2.128 1.211,3.1 0,0.06 -0.833,2.366 -0.9,2.427 -0.876,0.792 -1.396,2.227 -1.803,3.332 -0.744,2.019 1.247,2.191 1.252,3.76 0,1.114 -0.73,1.573 -0.938,2.653 -1.168,-0.801 -3.788,-3.527 -4.288,-1.497 -0.345,1.4 0.301,0.92 0.45,2.673 0.08,0.2 -1.168,-1.154 -0.666,-0.728 -0.01,0.296 -1.669,1.773 1.288,2.819 0.105,-1.402 1.81,0.859 2.605,0.633 0.456,-0.13 0.218,0.509 0.128,1.573 0.91,0.263 2.526,0.709 2.673,0.135 0.121,0.02 0.846,0.116 1.051,0.271 -0.585,3.217 -0.181,2.501 0.257,2.863 -0.323,0.668 0.139,0.516 -0.322,1.114 -0.792,1.028 -1.505,2.592 -2.458,3.539 -0.415,0.412 -0.99,0.631 -1.318,1.134 -0.602,0.923 0.647,0.492 0.808,1.265 0.207,0.991 0.606,0.956 0.253,1.399 -5.734,7.2 -1.924,0.984 -2.163,1.487 -0.536,1.129 0.861,2.579 0.105,3.875 -0.651,1.116 -2.026,1.511 -3.241,1.511 -1.364,0 -2.414,-1.019 -3.339,-1.891 -1.091,-1.027 -2.285,-1.508 -3.465,-2.344 -2.094,-1.483 -1.937,-4.181 -4.447,-5.211 -2.971,-1.22 -4.973,-4.122 -8.118,-4.896 -1.472,-0.362 -2.984,-1.379 -4.263,-2.175 -1.531,-0.952 -3.187,-1.271 -4.747,-2.112 -1.527,-0.825 -2.823,-2.085 -4.354,-2.957 -1.722,-0.98 -3.437,-1.941 -5.176,-2.894 -1.469,-0.805 -2.354,-2.651 -3.51,-3.84 -1.532,-1.576 -3.691,-2.404 -4.762,-4.36 -0.604,-1.104 -1.373,-2.43 -2.433,-3.095 -0.927,-0.582 0.304,-2.806 -1.32,-2.526 0.02,-0.281 0.09,-0.548 0.216,-0.8 0.242,0.144 0.482,0.291 0.72,0.44 0.64,-3.198 -0.743,-4.856 -2.346,-7.476 -1.456,-2.38 -2.445,-4.897 -4.486,-6.832 -0.612,-0.581 -1.237,-0.887 -1.07,-1.682 0.192,-0.915 -0.344,-1.942 -0.781,-2.704 -0.429,-0.749 -0.948,-1.552 -1.613,-2.117 -0.612,-0.521 -1.657,-0.768 -2.046,-1.526 -0.05,-0.397 -0.01,-0.791 0.107,-1.18 -0.121,-0.863 -0.668,-1.851 -1.061,-2.615 -0.753,-1.465 -1.781,-2.763 -2.616,-4.179 -0.787,-1.334 -1.229,-2.932 -1.786,-4.369 -1.3,-3.356 -3.396,-5.94 -4.338,-9.185 -1.287,-4.429 -5.048,-7.125 -6.755,-11.5 -1.953,-5.004 -5.991,-8.57 -10.887,-10.634 -0.431,-0.182 -2.046,-0.57 -2.101,-1.167 -0.08,-0.832 -0.251,-2.22 0.944,-2.072 2.126,0.264 1.319,-1.746 0.631,-2.793 -0.971,-1.477 -1.937,-2.094 -1.988,-3.931 0.197,-0.236 0.389,-0.476 0.576,-0.72 -0.04,-0.28 -0.885,-1.054 -1.074,-1.268 -0.994,-1.12 -0.386,-1.78 -0.802,-3.047">
<title>First</title>
</path>
</a>
<div class="miscbar"><iframe name="ifall" class="ifallc"></iframe></div>```
As per the specification, the :empty pseudo-class matches elements that has no children. By children, it means it could either be an element or just text.
If you defined your iframe like this:
<iframe src="//example.com"></iframe>
It will be counted as empty. (see jsfiddle)
However, if you start adding texts inside:
<iframe src="//example.com">No iframe support</iframe>
It will not be considered empty. (see jsfiddle)
I managed it :) I put an empty header in the wrapper div (misc bar) which contains the iframe and removed the line height and visibility of the header. Then I sent some text to that header at the same time the iframe is populated. I can now add border and background to the contents of the html which will only appear when the link is clicked.
<a href="peif.html" target="ifall" onclick="document.getElementById('miscbartitle').innerHTML = 'Enjoy'">
.miscbar { /*the outer div*/
box-sizing: border-box;
position: absolute;
top: -.2rem;
left: -.1rem;
z-index: 2;
/*
border: .15rem solid #222;
border-bottom-right-radius: 0.5rem;
background: rgb(85, 85, 85);
height: auto;
width: auto;
max-width: 70%;
*/
margin: 0;
padding: 0;
border: none;
}
.ifallc { /*the iframe*/
display: auto;
box-sizing: border-box;
margin: auto;
border: auto;
border: none;
}
#miscbartitle {
visibility: hidden;
line-height: 0;
}
It's a screenshot from a page currently I'm building. I'm trying to make sure the green button is always on the bottom of the container. Here is a piece of the code:
HTML
<div class="list-product-pat">
<article>
<!-- title, image, spec ... -->
<div class="pricing-pat">
<!-- the button goes here -->
</div>
</article>
</div>
CSS
.list-product-pat article {
position: relative;
min-height: 260px;
}
.list-product-pat .pricing-pat {
position: absolute;
bottom: 0;
width: 100%;
}
So far there is no problem... until the product spec gets too long and it breaks into the green button.
I want to maintain the green button in the most bottom position, but in the same time I also want the height to extend if the product title/product spec gets too long.
In the ideal world, it should be something like this:
So my idea is to maintain the absolute positioning while still keeping it inside the document flow (so the product spec knows the green button is there and doesn't break through it).
I need it only to extend if the spec height gets too long. In other words, if the spec is in normal height, it wouldn't extent. I'd like to avoid a weird gap between the spec and the green button.
Is there any idea how to do it?
Here is a fiddle to see how I did it: http://jsfiddle.net/xaliber/xrb5U/
Adding position:absolute takes it out of the document flow, there's no way to keep it in it.
But you can add padding-bottom equivalent to height of the button to the article container instead, which will prevent long text overrunning the button.
.list-product-pat article {
position: relative;
min-height: 260px;
padding-bottom:80px;
-moz-box-sizing:border-box;
box-sizing:border-box;
}
http://jsfiddle.net/xrb5U/3/
A separate issue is that two containers with different amount of texts will be different sizes (if one is larger than the min-height set). There's no easy fix for this in CSS positioning, you have to resort to Javascript, Flexbox or display:table-cell to keep the height of all them the same but each of them has their own issues too.
As #mikel already pointed out, you can't keep an element with position: absolute inside the normal document flow, but you can workaround this problem by simulating it.
Considering the example below:
img {
position: absolute;
}
<img src="https://dummyimage.com/300x400/d9ca29/ffffff">
<span>Lorem Ipsum is simply dummy text of the printing and typesetting industry</span>
The <img> element is out of flow, this cause the <span> to be hidden behind it.
You can wrap the absolute element inside an empty container, then add height and width to container equal to height and width of the absolute element. By doing so, an invisible box is created around the absolute element, which makes it appear as part of the document normal flow.
If you already know the exact dimensions of the <img> element, you can simulate normal flow using just css:
div {
border: 2px dotted grey;
position: relative;
width: 300px;
height: 400px;
}
img {
position: absolute;
}
<div>
<img src="https://dummyimage.com/300x400/d9ca29/ffffff">
</div>
<span>Lorem Ipsum is simply dummy text of the printing and typesetting industry</span>
Else, if you don't know the dimensions of the absolute element upfront you have to simulate the normal flow dynamically with javascript:
window.addEventListener('load', function() {
var div = document.querySelector('div');
var img = document.querySelector('img');
var rect = img.getBoundingClientRect();
div.style.height = rect.height + 'px';
div.style.width = rect.width + 'px';
});
div {
border: 2px dotted grey;
position: relative;
max-width: 200px;
}
img {
position: absolute;
width: 100%;
}
<div>
<img src="https://dummyimage.com/300x400/d9ca29/ffffff">
</div>
<span>Lorem Ipsum is simply dummy text of the printing and typesetting industry</span>
At some point in the (hopefully near) future, you'll be able to use the subgrid feature of CSS Grids. Currently, only Firefox supports this, but other browsers should add support soon.
Subgrid enables you to use Grid features with a non-flat structure (eg, an unordered list). That is, you can line up children of one element with children of another element, or in this case, the image, title, description, and price button.
.list-product-pat {
/* Create a grid with 5 columns that are 175px wide,
each with 5 rows that are sized based on the smallest item in the row */
display: inline-grid;
grid-template-columns: repeat(5, 175px);
grid-template-rows: repeat(5, min-content);
/* Colors and spacing to match design */
background: #f4f4f4;
padding: 1em;
grid-column-gap: 1em;
border: 1px solid #ddd;
}
.list-product-pat li {
/* Ensure this item takes up the column */
grid-row: 1 / -1;
/* Make children grid items */
display: grid;
/* Use parent's grid for children */
grid-template-rows: subgrid;
/* Styles to match design */
text-align: center;
justify-items: center;
border: 1px solid #ddd;
background: #fff;
}
/* STYLES TO MATCH DESIGN BELOW */
.list-product-pat > li > img {
margin-top: 1em;
}
.list-product-pat > li > h1 {
margin: .8em 0;
font-size: 1em;
}
.list-product-pat > li > p {
margin: 0;
color: #bbb;
font-size: .8em;
margin: 0 .5em 1em;
}
.list-product-pat > li > a {
text-decoration: none;
color: white;
font-weight: bold;
background: linear-gradient(#60bb76, #48b161);
border-radius: .5em;
box-shadow: 1px 1px 2px rgba(0, 0, 0, .5);
padding: .5em;
min-width: calc(100% - 1em);
margin-bottom: .5em;
box-sizing: border-box;
}
.list-product-pat > li > a > small {
display: block;
font-weight: normal;
font-size: .7em;
margin-top: .2em;
}
<ul class="list-product-pat">
<li>
<img src="https://placehold.it/40x70/">
<h1>HTC Desire C</h1>
<p>GSM, GPS, WiFi, kamera 5MP, bluetooth, Android, touchscreen, 600MHz</p>
1.699.000 <small>6 Produk/4 Website</small>
</li>
<li>
<img src="https://placehold.it/40x70/">
<h1>Samsung 19300 Galaxy S III</h1>
<p>GSM, GPS, WiFi, kamera 8MP, bluetooth, Android, touchscreen, 1.4GHz</p>
5.300.000 <small>8 Produk/5 Website</small>
</li>
<li>
<img src="https://placehold.it/40x70/">
<h1>Samsung Galaxy Grand i9082</h1>
<p>GSM, GPS, WiFi, touchscreen, 1.2GHz</p>
3.499.000 <small>10 Produk/8 Website</small>
</li>
<li>
<img src="https://placehold.it/40x70/">
<h1>Apple iPhone 5 16GB</h1>
<p>GSM, GPS, WiFi, kamera 8MP, bluetooth, iOS 6, touchscreen, 1.2GHz</p>
7.599.000 <small>6 Produk/5 Website</small>
</li>
<li>
<img src="https://placehold.it/40x70/">
<h1>BlackBerry Curve 9360 (Apollo)</h1>
<p>GSM, GPS, WiFi, kamera 5MP, bluetooth, 800MHz</p>
225.000 <small>9 Produk/4 Website</small>
</li>
</ul>
The solution is actually quite simple. Duplicate the absolutely positioned footer with visibility hidden.
<div style="background: silver; position: relative; height: 100px">
Height is 100px
<div style="position: absolute; bottom: 0; left: 0">Footer</div>
<div style="visibility: hidden">Footer</div>
</div>
<br />
<div style="background: silver; position: relative">
No height specified
<div style="position: absolute; bottom: 0; left: 0">Footer</div>
<div style="visibility: hidden">Footer</div>
</div>