Note that there are some explanatory texts on larger screens.

plurals
  1. POCentering a background image in the left of two columns
    primarykey
    data
    text
    <p>I have a big image, and some text that I would like to lay out in two columns, both 50% width, with the text in the right hand column and the image in the left hand column. I'd like the left hand column to take its height from the text in the right, and for the centre of the image to be in the centre of the left hand column, both vertically, and horizontally.</p> <p>So something like this:</p> <pre><code>[ ]|[----Text-----] [ ]|[-------------] [ ]|[-------------] [ Image ]|[-------------] [ Centre ]|[-------------] [ ]|[-------------] [ ]|[-------------] [ ]|[-------------] </code></pre> <p>The standard trick to get the height of the left hand column to match that of the right hand column is to put a container div around both columns so the left column can be full height in that, and to allow the right column to sit on top of the left. So something like this.</p> <pre><code>&lt;div class="container"&gt; &lt;div class="right-column"&gt;Lorem ipsum dolor sit...&lt;/div&gt; &lt;/div&gt; div.container { background-image: url(my_big_image.jpeg); background-position: ?; float: left; width: 100%; } div.right-column { float: right; background: white; width: 50%; } </code></pre> <p>But then how do I get the centre of my image to the centre of the column on the left? It seems I need the container div to include the right column in order to get the height right, but I need to exclude it in order to get the image centered horizontally in the left column.</p> <p>Ideally, I'd like to do this without using JavaScript!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload