2015-10-07 11 views
7

Ho questo html:Come centrare un'immagine tra due colonne in CSS?

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

voglio che il mio testo da dinamicamente divisa in due colonne, quindi sto utilizzando la proprietà column-count:

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

voglio anche per centrare l'immagine tra le due colonne, in larghezza ed altezza, in modo che ottenere questo effetto:

scheme

Come realizzeresti il ​​compito?
È possibile eseguire il lavoro solo con CSS?
In caso contrario, c'è un modo per farlo con javascript, mantenendo la proprietà column-count?

+0

IE9 compatibile o solo i browser moderni ok? – Jay

+0

Una soluzione per i moderni browser sarebbe ancora ok. – pr0gma

+0

Non possibile AFAIK con CSS eccetto CSS Forme/Regioni/Flusso e quelli sono ancora sperimentali. –

risposta

1

Non c'è un modo semplice per farlo. Tuttavia, puoi "falsificare" l'effetto di avvolgimento usando gli pseudo-elementi.

* { 
 
    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

Grazie. Quindi suppongo che non ci sia modo di farlo mantenendo la proprietà del conteggio delle colum? – pr0gma

+0

@ pr0gma Non conosco alcun modo per farlo. –

Problemi correlati