2015-10-07 4 views
7

मैं इस एचटीएमएल है:सीएसएस में दो कॉलम के बीच एक छवि को कैसे केन्द्रित करें?

<div> 
    <img class="image"> 
    <p class="text"></p> 
</div> 

मैं अपने पाठ dinamically दो कॉलम में विभाजित किया जा करना चाहते हैं, तो मैं column-count संपत्ति का उपयोग कर रहा:

p.text 
{ 
    -webkit-column-count: 2; 
    -moz-column-count: 2; 
    column-count: 2; 
} 

मैं भी बीच छवि केंद्रित करने के लिए चाहते हैं दो कॉलम, चौड़ाई और ऊंचाई में, ताकि मैं इस आशय प्राप्त:

scheme

आप कार्य को कैसे पूरा करेंगे?
यह काम केवल सीएसएस के साथ किया पाने के लिए संभव है?
यदि नहीं, तो वहाँ जावास्क्रिप्ट के साथ यह करने के लिए, column-count संपत्ति रखने के लिए एक रास्ता है?

+0

IE9 संगत या सिर्फ आधुनिक ब्राउज़रों ठीक? – Jay

+0

आधुनिक ब्राउज़रों के लिए एक समाधान केवल ठीक रहेगा। – pr0gma

+0

सीएसएस आकार/क्षेत्र/प्रवाह के अलावा सीएसएस के साथ AFAIK संभव नहीं है और वे अभी भी प्रयोगात्मक हैं। –

उत्तर

1

कोई बस यह करने के लिए तरीका है। हालांकि, आप छद्म-तत्वों का उपयोग करके रैपिंग प्रभाव को "नकली" बना सकते हैं।

* { 
 
    margin: 0px; 
 
    padding: 0px; 
 
} 
 

 
.text { 
 
    width: 49%; 
 
} 
 

 
#text-l { 
 
    float: left; 
 
} 
 

 
#text-r { 
 
    float: right; 
 
} 
 

 
#text-l:before, #text-r:before { 
 
    content: ""; 
 
    width: 125px; 
 
    height: 250px; 
 
} 
 

 
#text-l:before { 
 
    float: right; 
 
} 
 

 
#text-r:before { 
 
    float: left; 
 
} 
 

 
.image { 
 
    height: 250px; 
 
    width: 250px; 
 
    position: absolute; 
 
    left: 50%; 
 
    margin-left: -125px; 
 
    background-color: yellow; 
 
}
<div> 
 
    <img class="image" src="http://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"> 
 
    <p class="text" id="text-l"> 
 
     How to create a Minimal, Complete, and Verifiable example 
 

 
When asking a question about a problem caused by your code, you will get much better answers if you provide code people can use to reproduce the problem. That code should be… 
 

 
…Minimal – Use as little code as possible that still produces the same problem 
 
…Complete – Provide all parts needed to reproduce the problem 
 
…Verifiable - Test the code you're about to provide to make sure it reproduces the problem 
 
Minimal 
 
    </p> 
 
    <p class="text" id="text-r"> 
 
     The more code there is to go through, the less likely people can find your problem. Streamline your example in one of two ways: 
 

 
Restart from scratch. Create a new program, adding in only what is needed to see the problem. This can be faster for vast systems where you think you already know the source of the problem. Also useful if you can't post the original code publicly for legal or ethical reasons. 
 
Divide and conquer. When you have a small amount of code, but the source of the problem is entirely unclear, start removing code a bit at a time until the problem disappears – then add the last part back. 
 
Minimal and readable 
 

 
Minimal does not mean terse - don't sacrifice communication to brevity. Use consistent naming and indentation, and include comments if needed to explain portions of the code. Most code editors have a shortcut for formatting code - find it, and use it! Also, don't use tabs - they may look good in your editor, but they'll just make a mess on Stack Overflow. 
 
    </p> 
 
</div>

+0

धन्यवाद। तो मुझे लगता है कि कॉलम-गिनती संपत्ति को रखते हुए इसे करने का कोई तरीका नहीं है? – pr0gma

+0

@ pr0gma मुझे ऐसा करने का कोई तरीका नहीं पता। –

संबंधित मुद्दे