Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep the size of images and table's cells relative on browser resizing

I have board game with some image and table.
The display is ok when I am working with Chrome but on other browsers, such IE, or other computer with smaller screen then mine the display is being disrupted.
When I tried to resize my browser I found this problem too.

Before resizing browser to left:
enter image description here

After resizing browser to left:
enter image description here

I found posts on this issue and they suggested to use:

margin-left: 10%;
margin-right: 10%;

to the pictures but it didn't help.

CSS:

td {
    width: 105px;
    height: 90px;
    text-align: left;
    vertical-align: top;
    border: 1px solid black;
    position: relative;
    margin-left: 10%;
    margin-right: 10%;
}
table
{
    position: fixed;
    left:9px;
    top:8px;
}

#dice
{
   right: 230px;
    position:fixed; 
    margin-left: 10%;
    margin-right: 10%;
}

HTML:

<img id="dice" src="Resources/images/dice_5.png" number="5">
<table oncontextmenu="return false">
  <tbody>
    <tr>
     <td class="" cellnumber="1" row="0" col="0"><span>1</span></td>
     <td class="" cellnumber="2" row="0" col="1"><span>2</span></td>
     <td class="" cellnumber="3" row="0" col="2"><span>3</span></td>
     <td class="" cellnumber="4" row="0" col="3"><span>4</span></td>
     <td class="" cellnumber="5" row="0" col="4"><span>5</span></td>
   </tr>
  </tbody>
</table>
like image 810
E235 Avatar asked Nov 11 '22 01:11

E235


1 Answers

You're using position: fixed; which takes the table and img out of the document flow and displays them in the same place on the screen even if you scroll down the page; this means that they are not aware of the space that either of them occupies.

If you don't need the elements to be fixed I would suggest rearranging their order in HTML and floating them instead:

table {
    float: left;
}
td {
    border: 1px solid black;
    height: 90px;
    margin-left: 10%;
    margin-right: 10%;    
    position: relative;
    text-align: left;
    vertical-align: top;
    width: 105px;
}
#dice {
    float: left;
}
<table oncontextmenu="return false">
  <tbody>
    <tr>
     <td class="" cellnumber="1" row="0" col="0"><span>1</span></td>
     <td class="" cellnumber="2" row="0" col="1"><span>2</span></td>
     <td class="" cellnumber="3" row="0" col="2"><span>3</span></td>
     <td class="" cellnumber="4" row="0" col="3"><span>4</span></td>
     <td class="" cellnumber="5" row="0" col="4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ddle.net/LqwbLwv3/

If it is required to keep them fixed and the table is a set width (which seems to be the case) you can position the img from the left instead, that way it will not attempt to occupy the same space as the table:

table {
    left:9px;
    position: fixed;
    top:8px;
}
td {
    border: 1px solid black;
    height: 90px;
    margin-left: 10%;
    margin-right: 10%;
    position: relative;
    text-align: left;
    vertical-align: top;
    width: 105px;
}
#dice {
   left: 570px;
   position:fixed;
}
<img id="dice" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAE4AAABOCAMAAAC5dNAvAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoV2luZG93cykiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MzJENkNBODk0N0MyMTFFNEI1NzdFRkFBOTIzNTBGNDkiIHhtcE1NOkRvY3V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ys0K9A3ngjjqUKzSLoOWp3Bh396oqI6wDO63bGMe2Eil1FEQi2J8oZGhuzRshT0UWyv1ei1HoH+SMumFS2Kh6ADEUK7iXGD9R249R4Hdh5W9h6l9h709h5D9x6Sdxvh/wgwAOIqZ8jWZlkFAAAAAElFTkSuQmCC" number="5" />
<table oncontextmenu="return false">
  <tbody>
    <tr>
     <td class="" cellnumber="1" row="0" col="0"><span>1</span></td>
     <td class="" cellnumber="2" row="0" col="1"><span>2</span></td>
     <td class="" cellnumber="3" row="0" col="2"><span>3</span></td>
     <td class="" cellnumber="4" row="0" col="3"><span>4</span></td>
     <td class="" cellnumber="5" row="0" col="4"><span>5</span></td>
   </tr>
  </tbody>
</table>

JS Fiddle: http://jsfiddle.net/jw8buh20/

like image 141
Hidden Hobbes Avatar answered Nov 14 '22 21:11

Hidden Hobbes