How to make a div inside a table cell "height: 100%" - html

I have a layout using table cells. I know, using tables is quite out-dated, but I needed it for this one to make each row the same height without using absolute values for their height
See this fiddle or this draft.
I needed the .wrapper div, to display the .infobox correctly in firefox. Before that, I had the .infobox set as 100% height (with position absolute) which worked fine on chrome, since the parenting td-element had position:relative.
I want the hover-effect to be applied to the whole table cell but I'm desperate to figure out, how. I only want to use relative values (like em or %) for height and width, to make the layout sort of responsive/fluid.
Edit: Ok, using #OneTrickPony's idea, I tried wrapping them around in another "table-row"-div. So how can I now make both "table-cell"-divs the same height, with kind of vertical-align: middlebut without specifying an absolute height for "table-row"-div?

There is another option, but whether or not it is a good fit for your project depends on which browsers you want to support.
http://caniuse.com/#search=flexbox
I've simplified your markup a bit and completely removed the table.
<div id="pictures">
<article class="entry picture">
<div class="entry picture">
<img class="picture" src="./images/150x150.jpg" width="150" height="150"></img>
</div>
<div class="entry picture infobox">
<a href="#" class="entry">
<h3 class="entry picture headline">contents_0 alpha headline</h3>
<div class="view picture">
<span class="comments_amount">5</span>
<span class="articlenk info">Bild zeigen</span>
</div>
</a>
</div>
</article>
<article class="entry picture"><div class="picture wrapper">
<div class="entry picture">
<img class="picture" src="./images/150x71.jpg" width="150" height="71"></img>
</div>
<div class="entry picture infobox">
<a href="#" class="entry">
<h3 class="entry picture headline">contents_0 beta headline</h3>
<div class="view picture">
<span class="comments_amount">5</span>
<span class="pictures info">Bild zeigen</span>
</div>
</a>
</div></div>
</article>
</table>
The CSS for this is very simple, but I've left off the prefixes:
div#pictures {
display: flex;
flex-flow: row wrap;
}
article {
flex: 1 1 50%;
box-sizing: border-box; /* optional */
position: relative;
}
div.infobox {
position: absolute;
bottom: 0;
}
http://jsfiddle.net/NDMTH/1/
Figure/figcaption would probably be a more appropriate choice here than article.

Ok, so I figured that there actually is no way to set the height of two (or more) divs to equal values without defining absolute values. As a workaround, I wrote this little script, which does that job:
$(window).load(function() { /* Important because the script has to "wait" until the content (images) has been loaded */
$('.picture-row').each(function() {
var rowHeight = 0;
$(this).children('.picture.item').each(function() {
if ($(this).outerHeight() > rowHeight) {
rowHeight = $(this).outerHeight();
}
});
$(this).children('.picture.item').each(function() {
$(this).height(rowHeight + 'px');
});
});
});

Related

Let last column in a bootstrap row take up rest of viewport width

I'm having a bit of trouble trying to create a layout section on a site which uses Twitter bootstrap grid.
I need a regular .container with a col-xs-3 column and then the next column should simply fill the rest of the browser viewport. The content of the large "full width" column should fill the div all the way to the right side of the browser.
While I do realise that this is violating the rules of the grid, it's important for me, that the first col (.col-xs-3) uses the exact same left position as all other columns to keep content aligned horizontally.
See drawing for clarification:
I'm absolutely open to suggestions of doing this without using the boostrap grid in the middle section, but still, it's important the left position from tablet and up.
Any suggestions? :-)
EDIT:
Here's my markup:
<div class="product-slideshow">
<div class="container">
<div class="row">
<div class="col-xs-3 categories">
<ul>
<li><a>Product 1</a></li>
<li><a>Product 2</a></li>
<li><a>Product 3</a></li>
<li><a>Product 4</a></li>
</ul>
</div>
<!-- This column should span all the way to the right side of the browser -->
<div class="col-xs-9 images">
<div class="slider-wrapper">
<img class="slide" src="..." />
<img class="slide" src="..." />
<img class="slide" src="..." />
<img class="slide" src="..." />
</div>
</div>
</div>
</div>
</div>
EDIT 2:
Actually managed to fix this meanwhile. I'm using Slick.js slider for the slideshow/content in the large column, and appearantly, the following CSS (SASS) did the trick:
.products-slideshow {
overflow-x: hidden;
.images {
position: relative;
.slider-wrapper {
max-width: calc(100vw - 25%); // 25% being the col-xs-3 width
position: absolute;
height: auto;
}
}
}
If i truly understand you, you can use flexbox:
.row{
width: 100vw;
display: flex;
}
.col-xs-9{
flex: 1;
}
The div with flex: 1 will fill the remained space of the container, in flex direction (in this case row).

image won't appear on the webpage

I have added a few images on my html but it doesn't show up on the webpage. The directory path for the images are correct and the first image appeared before i added the rest. I thought it was something to do with the height so i added height on the css but still nothing.
Not sure if it helps to figure out without the images but i have pasted my codes below:
<section class="pictures">
<div class="container">
<div class="row1">
<div id="first" class="img1" style="background-image:url(images/page-1_img1.jpg);">
</div>
<div id="second" class="img2" style="background-image:url(images/page-1_img2.jpg);">
</div>
</div>
<div class="row2">
<div id="third" class="img3" style="background-image:url(images/page-1_img3.jpg);">
</div>
<div id="fourth" class="img4" style="background-image:url(images/page-1_img4.jpg);">
</div>
<div id="fifth" class="img5" style="background-image:url(images/page-1_img5.jpg);">
</div>
</div>
</div>
</section>
CSS:
.container {
height: 500px;
width:1024px;
}
Thank you.
Since you are using the images as background-images, you have to define at least a height (preferably also a width) for all their containers, i.e. #first, #second etc.
Otherwise (since they don't have any other content) those elements will have zero height, so the background-images will remain invisible
Addition: Actually, it makes more sense to use img tags instead of using the images as background-images, if you are not aiming at any special solution that requires background-images. If you insist on using background-images, you also have to define their size and no-repeat.

How to positioning the elements one under the other, regardless of the height of the item?

How to positioning the elements one under the other, regardless of the height of the item? As having the following markup, to place the elements in the following way:
.photo {
display: inline-block;
vertical-align: top;
max-width: 160px;
width: 100%;
margin: 0px 20px 20px 0;
background:red;
}
<div class="photo">
<div class="photo__item photo__item_1"></div>
</div>
<div class="photo">
<div class="photo__item photo__item_2"></div>
</div>
<div class="photo">
<div class="photo__item photo__item_3"></div>
</div>
<div class="photo">
<div class="photo__item photo__item_4"></div>
</div>
<div class="photo">
<div class="photo__item photo__item_5"></div>
</div>
<div class="photo">
<div class="photo__item photo__item_6"></div>
</div>
There are a couple of ways of doing this.
Emulate this effect by using the css column property, I found this fiddle for example, you can see how the elements are positioned.
Other way (most viable I think) is to use a plugin like masonry as #kukkuz said before, it does almost everything you need.
Create your own grid using javascript and css in order to position every element based on other element's positions (which I wouldn't recommend) because you have to do some calcs and it could take some time.

container not responsive when the window resizes - leaving white space on the right

The current website has 3 column block layout and I am trying to make it responsive. As the window gets small enough, the 3 columns turn into 2 columns, which is what I wanted. However, it leaves white space where the third column was used to be and I don't want the extra white space. So the white space should be hidden as the window gets smaller (this is what happens when the window is large enough for 3 columns. The white space on the right side gets hidden, until the 3 columns turns into 2).
Thank you. :)
JSFiddle
html:
<body>
<div id="content">
<div class="grid3">
<article class="bucket" >
<a href="#">
<img src="images/baskerville1.jpg" alt=""/>
<div class = "img-overlay">
<h3>Monogram</h3></div>
</a>
</article>
<article class="bucket">
<a href="#">
<img src="images/Gastalt.png" alt=""/>
<div class="img-overlay">
<h3>Gastalt Composition</h3>
</div>
</a>
</article>
<article class="bucket">
<a href="#">
<img src="images/redThread.png" alt=""/>
<div class="img-overlay">
<h3>The Red Thread - A Visual Book</h3>
</div>
</a>
</article>
<article class="bucket">
<a href="#">
<img src="images/poster copy.png" alt=""/>
<div class="img-overlay">
<h3>Typographic Hierarchy</h3>
</div>
</a>
</article>
<article class="bucket">
<a href="#">
<img src="images/Spaces.png" alt=""/>
<div class="img-overlay">
<h3>Living in Two Spaces</h3>
</div>
</a>
</article>
css:
#charset "UTF-8";
*{
margin:0;
}
.bucket {
position:relative;
float: left;
margin-left: 3.2%;
margin-bottom:30px;
}
.grid3 .bucket:nth-of-type(3n+1){
margin-left: 0;
clear: left;
}
.grid3 .bucket{
width: 31.2%;
}
.img-overlay h3 {
opacity: 1;
display: inline-block;
margin: auto;
height: 20px;
position: absolute;
top: 0;
bottom: 0;
right: 0;
left:0;
color: rgba(255,254,254,1.00);
text-align: center;
vertical-align: middle;
}
Controlling exact numbers in responsive layout (3col, 2col, etc.) should be done via percentages because it's heaps easier to control when and where breakpoints happen.
Here's a JSFiddle showcasing this: http://jsfiddle.net/sickdesigner/GLnfU/
Essentially, the key to the whole thing is having your .buckets set to percentages according to how many columns you want. This makes your article fill up their container in three columns (27.3+3+3 = 33.3*3 = 99.9%).
.bucket{
margin: 2% 3%;
width: 27.3%; }
Also, for sanity's sake, I added a universal box-sizing. More on why box-sizing makes life easier here: http://www.paulirish.com/2012/box-sizing-border-box-ftw/
However,
If you really want to let your content do what it want, when it feels like it, you could skip the whole matter of floating elements altogether. This is the more hippie-lovey-dovey version of this layout and while it looks sleek and sexy and makes coders, myself included, drool with code-lust, it also means leaving a lot to chance and the hope that your content won't break itself (think what would happen if the images were all different proportions to each other).
Here's another JSFiddle, this time with the hippie-drooly approach: http://jsfiddle.net/sickdesigner/zq8YC/1/
P.S.: the hippie-drooly approach also doesn't require media queries, which is kind of cool, actually.
Cheers!

CSS - Margin-top won't work on one selector, but does in compatability mode

I am making a website and have split the site into the usual header, maincontainer and footer divs. The maincontainer contains 3 extra divs and all 3 divs (section 1,2,3) have a margin-top: 5px command associated to them. The first 2 divs (section 1 and 2) work perfectly, but the 3rd div (section 3) doesn't work at all. It just stays glued beneath section 2. However, if I go to IE compatibility mode, the 3rd div will drop down by the 5px specified in the CSS.
Code below.
CSS:
#middlecontainer {
width: 960px;
height: auto;
}
.section1, .section2, .section3{
width: 960px;
margin-top: 5px !important;
}
HTML:
<div id="middlecontainer">
<div class="section1">
<div class="promo1">
<h1>Celebrate the real flavour of Indian cuisine at Mela.</h1>
<p>&nbs</p>
<p>&nbsp</p>
</div>
<div class="promo2">
<img src="images/home-1.jpg" alt="Mela West End, London" />
</div>
</div>
<div class="section2">
<div class="promo3">
<img src="images/mela-limitless.gif" alt="Up to 50% off Mela Limitless" />
</div>
<div class="promo4">
<img src="images/gift-vouchers.gif" alt="Mela's Gift Vouchers" />
</div>
<div class="promo5">
<img src="images/food-1.jpg" alt="Mela Curries" />
</div>
</div>
<div class="section3">
<div class="promo6">
<img src="images/visit-redhill.gif" alt="Visit Mela Redhill in Surrey" />
</div>
<div class="promo7">
<img src="images/recipe-of-the-month.jpg" alt="Mela's Recipe of the Month" />
</div>
<div class="promo8">
<img src="images/cookery-class.gif" alt="Did you buy a cookery class" />
</div>
</div>
</div>
If needed I can provide the CSS code for the .promo divs, but as they are child elements I didn't think that would effect the parent div.
Keith
EDIT:
Here is the code put into jsFiddle, it seems to work fine in here though so I am completely stumped as to why it won't work in my browser. http://jsfiddle.net/8xpxH/4/
Because you float your promo-elements, the parent elements (.sectionX) have height 0. This messes up your margins.
You need to clear the floats. Easiest way to to this is to set overflow:auto and everything is fine. (auto might make (unnecessary) scrollbars appear which can be problematic, so if you are sure, your stuff fits perfectly and there will be no overflow issues take hidden instead.)
.section1, .section2, .section3{
width: 960px;
margin-top: 5px;
overflow: hidden;
}