2016-02-12 6 views
8

Я строю проект в угловом 2, и мне нужен липкий нижний колонтитул, который всегда должен быть внизу страницы, а не фиксирован. Пример: http://codepen.io/chriscoyier/pen/uwJjrЛипкий нижний колонтитул внизу в углу 2

Структура компоненты «приложений», как это:

<header-main></header-main> 
<router-outlet></router-outlet> 
<footer>...</footer> 

Возможно, проблема не связана с самим угловым, но только с помощью CSS. Тем не менее, я попытался его реализация, как это:

app { 
    min-height: 100%; 
    position: relative; 
} 

footer { 
    position: absolute; 
    bottom: 0; 
    left: 0; 
    width: 100%; 
    height: 271px; 
} 

Результат ужасен: enter image description here

Интересно то, что если я выключаю положение колонтитула в инспекторе и снова включу, футер становится OK: enter image description here

РЕШЕНИЕ:

app { 
    min-height: 100%; 
    width: 100%; 
    margin-bottom: -271px; 
    display: table; 
} 

header-main, 
router-outlet, 
footer{ 
    display: table-row; 
} 

header-main { 
height: 60px; 
} 

router-outlet { 
    position: absolute; 
} 

footer { 
    height: 271px; 
} 
+0

Есть какой-либо soluting для этого?. Я столкнулся с тем же вопросом –

+0

любой ответ. Мне нужно ур помощь –

+0

СПАСИБО ВАМ ТАК МНОГО ДЛЯ проводкой РЕШЕНИЕ <3 <3 – Cacoon

ответ

0

См Пример: Link

Добавить CSS:

.page-wrap{position: relative;} 
#add{position: absolute; bottom: 160px;} 
1

Ссылку вы предоставили на самом деле является прекрасным примером того, как сделать то, что это звучит, как вы просите. Я попытался использовать элементы, которые вы упомянули, с необходимым CSS ниже.

Here's a working example.

<div class="app"> 
    <header> 
     Header here 
    </header> 
    Content isn't long enough to push footer to the bottom. 
</div> 
<footer> 
    This is the footer 
</footer> 
html, body { 
    /* make sure the body does not have a margin */ 
    margin: 0; 
    /* this forces the body tag to fill the height of the window */ 
    height: 100%; 
} 
.app { 
    /* the .app div needs to be AT LEAST 100% of the height of the window */ 
    min-height: 100%; 
    /* now that it is 100% the height, we 'pull' the footer up */ 
    /* margin-bottom must be the same height as the footer height below */ 
    margin-bottom: -271px; 
} 
footer{ 
    /* .set the height of the footer */ 
    height: 271px; 
    /* just setting a color so you can see the footer */ 
    background: orange; 
} 

/* the following is not necessary, just showing how a header could be added */ 
header{ 
    height: 30px; 
    background: teal; 
} 
+0

«сноска» внутри «приложения» тег:

+0

Липкие колонтитулы всегда было довольно сложно. Они в значительной степени полагаются на правильную компоновку HTML для одного элемента, чтобы, по крайней мере, заполнить всю высоту страницы, а затем вытащить нижний колонтитул обратно в окно просмотра (используя отрицательное поле внизу). Без изменения HTML, единственный способ, которым я мог бы подумать сделать эту работу, - это писать JavaScript, который устанавливает высоту элементов при загрузке страницы и при изменении размера окна. Я лично хотел бы использовать HTML/CSS для JavaScript для липкого нижнего колонтитула. –

4

Это, как я решаю липкий колонтитул (не фиксирован)

app.component.ts 
..... 
export class AppComponent { 
    clientHeight: number; 

constructor() { 
    this.clientHeight = window.innerHeight; 
} 
} 

app.component.html 

<div [ngStyle]="{'min-height': clientHeight + 'px', 'margin-bottom': '-200px'}"> 
      <!-- 'margin-bootom': '-FooterHeight' --> 
    <app-navbar></app-navbar> 
      <!-- Your Navbar here --> 
    <router-outlet></router-outlet> 
    <div style="height: 200px"></div> 
      <!-- 200px is FooterHeight this will push 
      the footer so it will not overlap if you have very long content --> 
</div> 

<app-footer></app-footer> 
<!-- Your footer here --> 
0

ответа на "Phen" ответа. Вы можете сделать это некоторое более динамичной для поддержки несколько устройств (если сноска изменение высоты):

app.component.ts 
 
..... 
 
export class AppComponent implements AfterViewInit { 
 
    clientHeight: number; 
 
    footerHeight:umber; 
 
    @ViewChild('footer') footerDiv: ElementRef; 
 

 
constructor() { 
 
    this.clientHeight = window.innerHeight; 
 
} 
 
ngAfterViewInit() { 
 
    this.footerHeight=this.footerDiv.nativeElement.offsetHeight; 
 
} 
 
} 
 

 
app.component.html 
 

 
<div [ngStyle]="{'min-height': clientHeight-footerHeight + 'px'}"> 
 
    <app-navbar></app-navbar> 
 
      <!-- Your Navbar here --> 
 
    <router-outlet></router-outlet> 
 
</div> 
 

 
<app-footer #footer></app-footer> 
 
<!-- Your footer here -->

Смежные вопросы