http://jsfiddle.net/zbbHc/45/
सुनिश्चित नहीं हैं कि इस बेला की कोशिश करें, लेकिन मुझे लगता है यह अधिकतम हम अकेले सीएसएस का उपयोग कर सकते है।
अद्यतन: (यह, सभी मामलों में काम नीचे जो सभी मामलों [मुझे लगता है] में काम कोड की जांच नहीं करेगा)
एचटीएमएल
<div class="wrapper">
<div class="iB"></div>
<div class="iB"></div>
<div class="iB"></div>
<div class="iB"></div>
<div class="iB"></div>
<div class="iB"></div>
<div class="iB"></div>
<div class="iB hide"></div>
<div class="iB hide"></div>
</div>
सीएसएस
.wrapper {
width: 100%;
background: red;
text-align: center;
text-align-last: left;
}
.iB {
display:inline-block;
width: 200px;
height: 100px;
background: green;
}
.iB.hide {
visibility:hidden;
}
jQuery का उपयोग कर त्वरित और गंदे विधि यहां है। यह अदृश्य तत्व जोड़ देगा स्वचालित रूप से
फिडल यहाँ http://jsfiddle.net/fD6fn/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="lib/jquery-1.6.2.min.js"></script>
<style>
.wrapper {
width: 100%;
background: red;
text-align: center;
text-align-last: left;
}
.iB {
display:inline-block;
width: 200px;
height: 100px;
background: green;
}
.iB.hide {
visibility:hidden;
}
</style>
</head>
<body>
<div class="wrapper" id="wrapper">
<div class="iB"></div>
<div class="iB"></div>
<div class="iB"></div>
<div class="iB"></div>
<div class="iB"></div>
<div class="iB"></div>
<div class="iB"></div>
</div>
<script language="javascript">
function findHiddenElementCount() {
var $wrapper = $("#wrapper"),
itemWidth = "200",
count = "",
itemCount = 7;
count = $wrapper.width()/itemWidth;
// Some wild logic below, can be optimized.
return parseInt(count) - (itemCount - (parseInt(itemCount/parseInt(count)) * parseInt(count))) ;
}
function addInvisibleElements()
{
// Delete invisible items
$("#wrapper .iB.hide").remove();
var c = findHiddenElementCount();
for(var i = 0; i < c;i++)
{
$("#wrapper").append('<div class="iB hide"></div>');
}
}
$(window).bind("resize",addInvisibleElements); // resize handler
$(document).ready(addInvisibleElements); // take care during page load
</script>
</body>
</html>
बहुत रोचक, मुझे आश्चर्य है कि यह शुद्ध सीएसएस – Kos
के साथ किया जा सकता है, आपका रैपर कितना विस्तृत है? क्या इससे कोई फर्क पड़ता है कि पंक्ति पर कितनी वस्तुएं हैं? – JohnC
महान सवाल! @ जॉनसी के प्रश्न के विस्तार के रूप में, जब आप कहते हैं कि अपने रैपर पर निश्चित चौड़ाई लागू नहीं करना चाहते हैं तो क्या आपका मतलब है कि आप दो "कॉलम" के लिए निश्चित चौड़ाई निर्धारित नहीं करना चाहेंगे? –