2011-04-18 20 views
10

साथ इनलाइन अगर मैं किसी भी तत्व के लिए display:inline सेट तो margin, padding, width, height उस तत्व पर कोई असर नहीं पड़ेगा?प्रदर्शन: मार्जिन, गद्दी, चौड़ाई, ऊँचाई

यह float:left या display:block या display:inline-block उपयोग करने के लिए margin, padding, width, उस तत्व पर height उपयोग करने के लिए आवश्यक है?

+0

'padding' रूप में अच्छी तरह इनलाइन तत्वों के लिए काम करेंगे। –

उत्तर

13

कृपया "Inline formatting contexts" पूरी जानकारी के लिए सीएसएस कल्पना पर देखते हैं।

असल में मार्जिन, पैडिंग और सीमा इनलाइन-स्तर तत्वों पर सेट की जा सकती है, लेकिन वे आपकी अपेक्षा के अनुसार व्यवहार नहीं कर सकते हैं। व्यवहार केवल तभी ठीक होगा यदि केवल एक पंक्ति है, लेकिन उसी प्रवाह में अन्य रेखाएं आपकी उम्मीदों से भिन्न व्यवहार प्रदर्शित करती हैं (यानी पैडिंग का सम्मान नहीं किया जाएगा)। इसके अतिरिक्त, यदि आपके ब्रेक करने योग्य तत्व होते हैं और युक्त तत्व के मार्जिन तक पहुंचते हैं तो आपका इनलाइन बॉक्स टूटा जा सकता है; उस मामले में, ब्रेक के बिंदु पर, मार्जिन और पैडिंग का भी सम्मान नहीं किया जाएगा।

सूचियों के साथ मिले इस बात का एक अच्छा उदाहरण: http://www.maxdesign.com.au/articles/inline/

0

पैडिंग inline के लिए काम करेगा। ऊंचाई और चौड़ाई हालांकि नहीं होगी।

http://jsfiddle.net/d89Wd/

संपादित करें: ठीक किया

0

मैं जानता हूँ कि यह काफी देर से जवाब है, लेकिन मैं जो (शब्द को तोड़ने के साथ) इनलाइन तत्वों पर गद्दी का समर्थन एक jQuery प्लगइन देखना लिखा था इस JSfiddle:

http://jsfiddle.net/RxKek/

प्लगइन कोड:

$.fn.outerHTML = function() { 
// IE, Chrome & Safari will comply with the non-standard outerHTML, all others (FF) will have a fall-back for cloning 
return (!this.length) ? this : (this[0].outerHTML || (
    function (el) { 
     var div = document.createElement('div'); 
     div.appendChild(el.cloneNode(true)); 
     var contents = div.innerHTML; 
     div = null; 
     return contents; 
    })(this[0])); 
}; 

/* 
Requirements: 

1. The container must NOT have a width! 
2. The element needs to be formatted like this: 

<div>text</div> 

in stead of this: 

<div> 
    text 
</div> 
*/ 

$.fn.fixInlineText = function (opt) { 
return this.each(function() { 
    //First get the container width 
    var maxWidth = opt.width; 

    //Then get the width of the inline element 
    //To calculate the correct width the element needs to 
    //be 100% visible that's why we make it absolute first. 
    //We also do this to the container. 
    $(this).css("position", "absolute"); 
    $(this).parent().css("position", "absolute").css("width", "200%"); 

    var width = $(this).width(); 

    $(this).css("position", ""); 
    $(this).parent().css("position", "").css("width", ""); 

    //Don't do anything if it fits 
    if (width < maxWidth) { 
     return; 
    } 

    //Check how many times the container fits within the box 
    var times = Math.ceil(width/maxWidth); 

    //Function for cleaning chunks 
    var cleanChunk = function (chunk) { 
     var thisChunkLength = chunk.length - 1; 

     if (chunk[0] == " ") chunk = chunk.substring(1); 
     if (chunk[thisChunkLength] == " ") chunk = chunk.substring(0, thisChunkLength); 

     return chunk; 
    }; 

    //Divide the text into chunks 
    var text = $(this).html(); 
    var textArr = text.split(" "); 

    var chunkLength = Math.ceil((textArr.length - 1)/times); 
    var chunks = []; 

    var curChunk = ""; 
    var curChunkCount = 0; 

    var isParsingHtml = false; 

    //Loop through the text array and split it into chunks 
    for (var i in textArr) { 
     //When we are parsing HTML we don't want to count the 
     //spaces since the user doesn't see it. 
     if (isParsingHtml) { 
      //Check for a HTML end tag 
      if (/<\/[a-zA-Z]*>/.test(textArr[i]) || /[a-zA-Z]*>/.test(textArr[i])) { 
       isParsingHtml = false; 
      } 
     } else { 
      //Check for a HTML begin tag 
      if (/<[a-zA-Z]*/.test(textArr[i])) { 
       isParsingHtml = true; 
      } 
     } 

     //Calculate chunks 
     if (curChunkCount == (chunkLength - 1) && !isParsingHtml) { 
      curChunk += textArr[i] + " "; 
      chunks.push(cleanChunk(curChunk)); 
      curChunk = ""; 
      curChunkCount = -1; 
     } else if ((i == (textArr.length - 1))) { 
      curChunk += textArr[i]; 
      chunks.push(cleanChunk(curChunk)); 
      break; 
     } else { 
      curChunk += textArr[i] + " "; 
     } 

     if (!isParsingHtml) { 
      curChunkCount++; 
     } 
    } 

    //Convert chunks to new elements 
    var el = $($(this).html("").outerHTML()); 

    for (var x in chunks) { 
     var new_el = el.clone().html(chunks[x]).addClass("text-render-el"); 
     var new_el_container = $("<div/>").addClass("text-render-container"); 

     new_el_container.append(new_el); 

     $(this).before(new_el_container); 
    } 

    //Finally remove the current element 
    $(this).remove(); 
}); 
}; 
संबंधित मुद्दे