C
C
ChemAli2011-04-07 16:12:27
css
ChemAli, 2011-04-07 16:12:27

CSS: fixed title in a full-width fluid block

To avoid wasting bytes on explanations, here's a sandbox stub: jsfiddle.net/RYCnH/

If you remove position:fixed; the header normally takes up the entire width, but goes up when scrolling. We want the .header block to take up the entire width of the .container block and remain visible on scroll.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
Fastto, 2011-04-07
@ChemAli

header - position: absolute;
left: 0;

E
ertaquo, 2011-04-07
@ertaquo

A small javascript with jQuery: I think this is about what you need :-)
$(document).ready(function(){
$(window).scroll(function(){
var header = $('.header').detach();
var scrollTop = $(window).scrollTop();
$('.container p').each(function(){
if ($(this).offset().top > scrollTop)
{
$(header).insertBefore(this);
header = null;
return false;
}
});
if (header)
{
$('.container').append(header);
}
});
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question