简体   繁体   English

响应式棋盘问题

[英]Responsive Chess Board Issue

As can be seen in the fiddle below, the chessboard responds as it should which is no more then 512px wide, while shrinking to fit whatever device. 从下面的小提琴中可以看出,棋盘做出了应有的响应,宽度不超过512像素,同时缩小以适合任何设备。 The pieces also respond with the board as they should. 棋子也应按原样与董事会回应。 The problem I am having is that when I add a piece to the board / inside a square div, its like the img is creating a bunch of extra space below. 我遇到的问题是,当我在方形div内的木板上添加一块时,就像img在下面创建了一堆额外的空间。 Looks like its twice the size of the img... I know that the img's are causing the issue because I removed all the img's from the top of the board and the squares are completely square as they should be. 看起来它的大小是img的两倍...我知道img引起了这个问题,因为我从板子顶部移走了所有img,并且正方形完全是正方形。 Yes, the img's I am using are 64px x 64px. 是的,我正在使用的img为64px x 64px。 Any ideas of whats happening here? 对这里发生的事情有任何想法吗? Any help would be great. 任何帮助都会很棒。 Thanks! 谢谢!

http://jsfiddle.net/4vxLP http://jsfiddle.net/4vxLP

<div id="A2" class="whiteSquare square fl">
    <img src="img/64PieceImg/white_pawn.png" class="piece"/>
</div>


.fl{

    float:left;
}

.board{

    max-width:512px;
    margin: 0 auto;   
}

.whiteSquare{

    max-height: 64px;
    max-width: 64px;
    width:12.5%;
    padding-bottom:12.5%;
    background-color:#F7F7F7;
}

.blackSquare{

    max-height: 64px;
    max-width: 64px;
    width:12.5%;
    padding-bottom: 12.5%;
    background-color:#29BEE8;
}

.piece{

    max-width: 100%;
    max-height: 100%;
}

You can just add position:absolute; 您可以只添加position:absolute; to your .piece class: http://jsfiddle.net/4vxLP/2/ The problem you are having is the padding-botton you are using to keep the size in the empty divs. 到您的.piece类: http : //jsfiddle.net/4vxLP/2/您遇到的问题是用于将尺寸保持为空div的padding-botton。 Remember when you use padding it sums space to the total of the container, so when you add the image you have the image size plus the padding added. 请记住,使用填充时,它会将空间总和为容器的总和,因此,在添加图像时,您将获得图像大小加上添加的填充。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM