2017-07-02 155 views
2

我很好奇工作位置:如何在html标记中使用相对位置。谁能解释一下?它是相对于文档对象或类似的东西吗?将html设置为相对位置

<footer class="footer"> 
    <div class="container"> 
     <p class="text-muted">Place sticky footer content here.</p> 
    </div> 
    </footer> 

html { 
    position: relative; 
    min-height: 100%; 
} 
body { 
    /* Margin bottom by footer height */ 
    margin-bottom: 60px; 
} 
.footer { 
    position: absolute; 
    bottom: 0; 
    width: 100%; 
    /* Set the fixed height of the footer here */ 
    height: 60px; 
    background-color: #f5f5f5; 
} 
+1

为什么你不想阅读指南?这总是最好的选择。 https://www.w3schools.com/css/css_positioning.asp –

+2

[这里](http://www.barelyfitz.com/screencast/html-training/css/positioning/)是学习CSS定位的好教程 – Lal

+0

本教程的第4点向我解释了我想知道的很多 – quimak

回答

0

此关键字勾画出的所有元素,就好像元件未定位,并且然后调整元件的位置,而不改变布局(并因此留下间隙对于其中它会一直有它没有被定位在元件)。

0

具有position: relative;的元素相对于其正常位置定位。

设置相对定位元素的顶部属性,右侧属性,底部属性和左侧属性都会导致将其调整到远离其正常位置的位置。其他内容将不会被调整以适应元素留下的任何空白。

来源:https://www.w3schools.com/css/css_positioning.asp

0

其实,如果你使用相对的HTML标签位置将没有任何意义。

position: relative; 

定位孩子相对于其父母或其相邻元素。

你可以试试position:相对于body来定位body相对于父html。

让我知道如果您需要任何进一步的帮助

+1

以及http://getbootstrap.com/examples/sticky-footer-navbar/中的示例,并且没有位置:html标签页脚中的相对位置将无法正常工作。 @Lal发布了很酷的指南。我在第4点找到了答案。你可以尝试一下,用不同大小的浏览器玩一下你会看到不同之处。 – quimak