Forum Moderators: not2easy

Message Too Old, No Replies

Strange space gaps showing on my page

         

alex100

9:26 pm on Jan 24, 2015 (gmt 0)

10+ Year Member



Hi!

I'm in the process of building a mobile website, and today I spent hours trying to solve a problem.

At the top of the homepage I have a set of image buttons. It's very important that they all rescale up and down according to the viewframe of the mobile device. Although I'm new to CSS, I found a solution that seems to work ok, except for one thing: it leaves some small space gaps at the top of the buttons.

This happens on my desktop computer, under Opera Mobile Emulator AND Chrome. I even spotted the problem under FireFox, although not as frequent. But it does happen in FireFox too!

I built a small testing page so you can see what I'm talking about.
There you can see 20 images, all next to each other. Please note that they all use the same image file. This PNG image has a 1px black border around it and is a png image that is 150 x 50px and named test.png

Now, the problem... some of the images seem to be shrinked in their height, leaving a space gap at their top. Through that gap, you can see the yellow background of the page.

If I open the page below in Chrome and resize the browser window, both horizontally, and vertically and I can notice the gaps at the top:

Remember, the 20 images use the same graphic file. Therefore, I'm assuming that the browser should rescale them all at the same height, not at different heights.

The CSS and test html code I'm using is shown below. Its main purpose is to rescale the images for various mobile viewports. The images should always cover 100% of the viewport (horizontally), and rescale their height accordingly.

If you have any idea on how I can eliminate those gaps, I would appreciate if you could please let me know. I would very much prefer to stick to this CSS code, if possible. Thank you very much!

Alex

------------------ CSS CODE ------------------
<html>
<head>
<meta name="viewport" content="width=320, initial-scale=1.0, user-scalable=1">
<style type="text/css">
body { background-color: yellow; margin: 0px; }
div.table { width: 100%; display: table; }
div.tr { display: table-row; }
div.td { display: table-cell; border: 0px solid yellow; }
img { width:100%; }
</style>
</head>
<body>
<div class="table">
<div class="tr">
<div class="td"><img src="test.png" style="img"></div>
<div class="td"><img src="test.png" style="img"></div>
<div class="td"><img src="test.png" style="img"></div>
<div class="td"><img src="test.png" style="img"></div>
<div class="td"><img src="test.png" style="img"></div>
<div class="td"><img src="test.png" style="img"></div>
<div class="td"><img src="test.png" style="img"></div>
<div class="td"><img src="test.png" style="img"></div>
<div class="td"><img src="test.png" style="img"></div>
<div class="td"><img src="test.png" style="img"></div>
<div class="td"><img src="test.png" style="img"></div>
<div class="td"><img src="test.png" style="img"></div>
<div class="td"><img src="test.png" style="img"></div>
<div class="td"><img src="test.png" style="img"></div>
<div class="td"><img src="test.png" style="img"></div>
<div class="td"><img src="test.png" style="img"></div>
<div class="td"><img src="test.png" style="img"></div>
<div class="td"><img src="test.png" style="img"></div>
<div class="td"><img src="test.png" style="img"></div>
<div class="td"><img src="test.png" style="img"></div>
</div>
</div>
</body>
</html>

[edited by: not2easy at 10:43 pm (utc) on Jan 24, 2015]
[edit reason] Edited to comply with Charter [/edit]

birdbrain

12:12 am on Jan 25, 2015 (gmt 0)



Hi there alex100,
I would simplify your code somewhat...


<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="utf-8">

<meta name="viewport" content="width=320, initial-scale=1.0, user-scalable=1">

<title>untitled document</title>

<style media="screen">
body {
margin:0;
background-color:#ff0;
}
.table {
overflow:hidden;
}
.table img {
float:left;
width:5%;
}
</style>

</head>
<body>

<div class="table">
<img src="test.png" alt="">
<img src="test.png" alt="">
<img src="test.png" alt="">
<img src="test.png" alt="">
<img src="test.png" alt="">
<img src="test.png" alt="">
<img src="test.png" alt="">
<img src="test.png" alt="">
<img src="test.png" alt="">
<img src="test.png" alt="">
<img src="test.png" alt="">
<img src="test.png" alt="">
<img src="test.png" alt="">
<img src="test.png" alt="">
<img src="test.png" alt="">
<img src="test.png" alt="">
<img src="test.png" alt="">
<img src="test.png" alt="">
<img src="test.png" alt="">
<img src="test.png" alt="">
</div>

</body>
</html>



birdbrain

alex100

2:43 am on Jan 25, 2015 (gmt 0)

10+ Year Member



Thank you for your answer!

In regards to your code... is there a way to make it work with images in various widths?

As it is now, if I use an image with a larger width, it will shrink it in height, while keeping the fixed 5% width.

The buttons I'm planning to use have different widths (heights are all the same).

I need the browser to rescale both the width, and the height (of course, keeping the ratio).

Horizontally, from left to right, they should all cover 100% of the space - and that, under any viewport resolution, and whether viewed in portrait or landscape mode.