もしあなたがjavascriptの追加を気にかけなければ、ここでは、すべてのリスト項目が整列したままになるように画像に重なるulに余白を追加するjQueryスクリプトがあり、次にそのliにマイナスのマージンを割り当てます重複しない。
$(function(){
//Define a context so we only move lists inside a specified parent
var context = $("#test_div");
//Build a list of images position a size
var imgRects = [];
var imgs = $("img.left", context);
imgs.each(function(i){
var pos = $(this).position();
pos.right = pos.left + $(this).outerWidth(true);
pos.bottom = pos.top + $(this).outerHeight(true);
imgRects.push(pos);
});
//Process each li to see if it is at the same height of an image
var lis = $("li", context);
lis.each(function(i){
var li = $(this);
if(li.parent().css('marginLeft') != "0px"){
return; //Already moved
}
var top = li.position().top;
for(var j in imgRects){
var rect = imgRects[j];
if(top > rect.top && top < rect.bottom){
li.parent().css('marginLeft', rect.right);
return;
} else if(li.parent().css('marginLeft') != "0px"){
li.css('marginLeft', -1 * rect.right);
}
}
});
});
私はあなたのデモページとjQuery 1.3.2でテストしてみた画像は、文書の一番上にあるので、それはFF3.5とIE8で動作します。イメージがulの真ん中に現れた場合、最初のliは埋められたままになります。この問題を解決する必要がある場合は、コメントを残してスクリプトを更新しようとします。
基本的に、私はhttp://tinyurl.com/ku7cckをhttp://tinyurl.com/lph2hjのようにしたいと思っています – caitlin
おそらく重複します:http://stackoverflow.com/q/2759354/854922。 – cooperscreek