Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Pure CSS center-alignment of independent elements without known width is a canonically tricky thing to achieve, so I believe JavaScript is the solution here. The following solution wraps "site" and "chat" into a centered <code>div</code>, augmenting the width of the wrapper to account for the presence of the chat window:</p> <pre><code> #wrapper --------------------------- | ________________ | | | | | | # | | | | | c | | | #site | | h | | | | | a | | | | | t | | ---------------- | | | | | --------------------------- </code></pre> <p>With the following initial styles:</p> <pre><code>#wrapper { margin: 0 auto; width: 800px; // &lt;-- this needs to increase when chat is visible! } #site { float: left; width: 800px; } #chat { display: none; // change to 'display: block;' to to reveal float: right; width: 200px; } </code></pre> <p>Since JavaScript is needed to toggle the chat element, we can dynamically modify the width of <code>#wrapper</code> at the same time. Here's an implementation that uses jQuery, which is recommended for reasons of code-conciseness, x-browser compatibility, and online community:</p> <pre><code>$('#chatbtn').click(function(){ var xcurr = $('#wrapper').width(); var xtend = $('#chat').width(); if ($('#chat').is(":visible")) xtend = -xtend; $('#wrapper').width(xcurr + xtend); $('#chat').toggle(); });​ </code></pre> <p>That should do it!</p> <ul> <li>Please see a <a href="http://jsfiddle.net/paislee/XLv9Q/1/" rel="nofollow"><strong>DEMO</strong></a>.</li> </ul>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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