2016-05-19 39 views
1

我正在用jQuery Mobile创建一个移动网站。我想分裂页脚4部分。但最后的div滑倒。我该如何解决这个问题?jQuery Mobile divs left left

HTML

<div data-role="footer" id="footer" data-position="fixed"> 
        <div class="footer-img"></div> 
        <div class="footer-img"></div> 
        <div class="footer-img"></div> 
        <div class="footer-img"></div> 
    </div> 

CSS

.footer-img{ 
    width: 24.5%; 
    border: 1px solid red; 
    float: left; 
    height: 50px; 
} 

ScreenShot

+0

尝试'宽度:23.5%;' – user2517200

+0

我尝试,但结果未改变 –

回答

0

你最好的赌注是计算使用jQuery的宽度。在将盒子向左侧移动时,只尝试使用CSS的页脚解决方案可能无法正常工作。

代码

var fwidth; 

//On page loads get the innewith of the footer, divide by 4 and subtract 2 pixels then Change footer-im width 
fwidth = $("#footer").innerWidth()/4 - 2; 
$(".footer-img").width(fwidth); 

//On resizing the the browser window get the innewith of the footer, divide by 4 and subtract 2 pixels then Change footer-im width 
$(window).resize(function() { 
fwidth = $("#footer").innerWidth()/4 - 2; 
$(".footer-img").width(fwidth); 
}); 

Demo

+0

甲导航栏是更容易或电网与4个块,其是相同的Navbar但没有按钮。 – Omar

+0

感谢您的评论。你的解决方案在jsfiddle上工作,但不能在我的电脑上工作。结果现在是相同的 –

+0

@Muhammed YusufTaşkesenligil - 正如Omar指出的在页脚中使用网格 - https://jsfiddle.net/zbocwr8L/ --- http://demos.jquerymobile.com/1.4.1/网格/#&UI状态=对话框 – Tasos