edit: 2 ways to achieve this. Relatively positioned (optional) element in an absolutely positioned one or (new) absolutely positioned element and transform .
You can achieve this by using position: absolute in the error message container and an additional div, relatively located between the container and the message.
The DOM is slightly modified, but without moving entire blocks of code, maybe everything is fine with your requirements?
Relevant HTML :
<div id="msgErreur"> <div>Error</div> </div>
Matching CSS :
#msgErreur { position: absolute; z-index: 5; color: white; } #msgErreur > div { position: relative; top: 30px; left: -10px; width: 150px; height: 30px; background: #942911; }
Fiddle
EDIT: it is 2016 and transform: translate(X, Y) compatible with a wide range of browsers (IE9 + by caniuse.com ). Here's another way to achieve what the OP requires without an extra element:
#div1 { width : 48%; border: 1px solid red; height: 150px; float:left; } #div2 { width : 48%; border: 1px solid blue; height: 150px; float:right; overflow-y:scroll; } #msgErreur { background:#942911; color:white; width : 150px; height : 30px; position: absolute; transform: translate(-10px, 30px); }
<div> <div id="div1"> div 1 </div> <div id="div2"> div 2 <div id="msgErreur"> Error </div> </div> </div>
Codepen
Felipeals
source share