javascript - 列内的绝对位置

标签 javascript html css

我有一个包含 3 列正文的页面。第一列和第三列内有按钮。我尝试正确放置它们。

特别是,第一列的按钮必须显示在页面底部(靠近页脚),我有一个问题。

但是我用的样式没有效果。我想这是因为该列是空的,并且相对于其高度进行定位。我尝试使用 height:100%; 属性,但没有用。

我该如何解决?

     <!DOCTYPE html>
    <html lang="en">
    <head>
      <title>Bootstrap Example</title>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="stylesheet"                                        href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
      <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
 html {
         position: relative;
         min-height: 100%;
      }
 body {
        margin-bottom: 20vh;
        background-color:#f2f2f2;
        }
       footer {
            position: absolute;
            bottom: 0;
            width: 100%;
            height: 10vh; 
       }

        footer {
           background-color: black;
           color:white;
          }  </style>
         <style>
              #upButton {position:absolute; left:0px; bottom:0px;}
         </style>

         <style>
              .col1 {height:100%;}
         </style>
</head>
 <body>
             <div id="header" class="header" align="center">
                            <h1 align="center">Some header
                            <small>some subheader</smalll>
               </div>                         
           <div class="container">
                       <div class="row">
                                 <div  class="col-md-2 col1"> 
                                                  <a id="upButton" 
                                      href="#header" class="btn btn-success" 
                                      role="button">Up
                                                   </a>
                                 </div>
                                 <div class="col-md-8">...</div>
                                 <div class="col-md-2">
                                     <a href="#f" align="right" class="btn 
                                 btn-danger" role="button">Down
                                     </a>
                                 </div>
                      </div>
          </div>  
     <footer>
         <div class="container-fluid">
            <p><a id="f">All right unreserved</a></p>
         </div>
      </footer>
</body>

所以现在我的解决方案只有在我在第一列中放置大量文本时才有效——然后向上按钮就在页脚附近,这是应该的。但是没有文字它会向上..

编辑:我设法通过将两个按钮都放在正文中来解决这个问题,但是如果有一个解决方案可以让它们保留在各自的列中,我想知道。 upbutton downbutton 在图片上,向上按钮靠近页脚,而向下按钮靠近页眉。

编辑:建议解决方案的代码:

     <!DOCTYPE html>
    <html lang="en">
    <head>
      <title>Bootstrap Example</title>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="stylesheet"                                        href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
      <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
 html {
         position: relative;
         min-height: 100%;
      }
 body {
        margin-bottom: 20vh;
        background-color:#f2f2f2;
        }
       footer {
            position: absolute;
            bottom: 0;
            width: 100%;
            height: 10vh; 
       }

        footer {
           background-color: black;
           color:white;
          }  </style>


         <style>
                  #upButton {position:fixed; left:0px; bottom:100px;}
                  .col1 {height:100%;}
         </style>


</head>
 <body>
             <div id="header" class="header" align="center">
                            <h1 align="center">Some header
                            <small>some subheader</smalll>
               </div>                         
           <div class="container">
                       <div class="row">
                                 <div  class="col-md-2 col1"> 
                                                  <a id="upButton" 
                                      href="#header" class="btn btn-success" 
                                      role="button">Up
                                                   </a>
                                 </div>
                                 <div class="col-md-8">.This book must have been revolutionary when it came out in the 1930s. The language, the style, the unbashed uncaring for literary norms must have been like a fresh air of rebellion to the stifled people of the 1930s who just few decades ago were under the moral oppression of the Victorian age. The book begins with an ode to Tanya's cunt. And it continues in the same manner. The word cunt is probably the most used word in the entire book. Today it would be called vulgar, but at the time it was revolutionary and brave. Miller describes multiple women he's had sex with while living in Paris, mostly on the money of other people, or as a vagrant and homeless on the streets. Most of the women he sleeps with are prostitutes (and he goes at length discussing the different types of prostitutes), but there is also the Jewish adulteress, the Russian princess with gonorrhea, the strange french woman to whom he gives 100 francs and then takes them out of her purse after having sex with her in her house above the room of her sick mother. Chapters of lucid description of characters (mostly Miller's friends whose money he uses, at whose houses he sleeps and whose women he has sex with) and some semblance of story lines are alternated with chapters of stream-of-consciousness monologues with prophetic statements and deep insights into life and living that usually come only after a very heavy intoxication with various substances. The book finishes in a middle of an action, just like it starts. Nothing really happens throughout and there's no sustained plot or even any novel-long characters (except the author-narrator) but it does give an entertaining and fascinating view into the life of the American emigres to Paris between the two wars in a much different way than Hemingway. POSTED BY MR.B. AT 2:12 PM NO COMMENTS: THURSDAY, JULY 7, 2016 "Mount Analogue" by Rene Daumal It ends in mid-sentence in the fifth chapter. Rene Daumal died days later of tubercolosis. He was in his 36th year of his life. Peradams. Only Father Sogol (Logos, took me a while to figure it out without anyone pointing it out to me) found one and very low, below the mountain where no Peradams are usually found, but he had an epiphany about himself. The book has an extensive intro section where the future planned chapters by Daumal are explained and it is a real shame that they were not written. Or maybe the book is more effective this way? After all Gurdjieff's "Life is real only when I AM" also stops in a middle of a sentence, and some who have seen the original manuscripts say that the published version is a much smaller selection from what was available. "Mount Analogue" is a very readable and well written book, to be expected from a writer of Daumal's caliber, and although Gurdjieff's name is never explicitly mentioned - it is based on the ideas and understanding of Gurdjieff's system (not to be called "The Fourth Way", but simply the "Gurdjieff System") and contains the personal thoughts and development of a person working on themselves according to the system. The explanation on how Mount Analogue This book must have been revolutionary when it came out in the 1930s. The language, the style, the unbashed uncaring for literary norms must have been like a fresh air of rebellion to the stifled people of the 1930s who just few decades ago were under the moral oppression of the Victorian age. The book begins with an ode to Tanya's cunt. And it continues in the same manner. The word cunt is probably the most used word in the entire book. Today it would be called vulgar, but at the time it was revolutionary and brave. Miller describes multiple women he's had sex with while living in Paris, mostly on the money of other people, or as a vagrant and homeless on the streets. Most of the women he sleeps with are prostitutes (and he goes at length discussing the different types of prostitutes), but there is also the Jewish adulteress, the Russian princess with gonorrhea, the strange french woman to whom he gives 100 francs and then takes them out of her purse after having sex with her in her house above the room of her sick mother. Chapters of lucid description of characters (mostly Miller's friends whose money he uses, at whose houses he sleeps and whose women he has sex with) and some semblance of story lines are alternated with chapters of stream-of-consciousness monologues with prophetic statements and deep insights into life and living that usually come only after a very heavy intoxication with various substances. The book finishes in a middle of an action, just like it starts. Nothing really happens throughout and there's no sustained plot or even any novel-long characters (except the author-narrator) but it does give an entertaining and fascinating view into the life of the American emigres to Paris between the two wars in a much different way than Hemingway. POSTED BY MR.B. AT 2:12 PM NO COMMENTS: THURSDAY, JULY 7, 2016 "Mount Analogue" by Rene Daumal It ends in mid-sentence in the fifth chapter. Rene Daumal died days later of tubercolosis. He was in his 36th year of his life. Peradams. Only Father Sogol (Logos, took me a while to figure it out without anyone pointing it out to me) found one and very low, below the mountain where no Peradams are usually found, but he had an epiphany about himself. The book has an extensive intro section where the future planned chapters by Daumal are explained and it is a real shame that they were not written. Or maybe the book is more effective this way? After all Gurdjieff's "Life is real only when I AM" also stops in a middle of a sentence, and some who have seen the original manuscripts say that the published version is a much smaller selection from what was available. "Mount Analogue" is a very readable and well written book, to be expected from a writer of Daumal's caliber, and although Gurdjieff's name is never explicitly mentioned - it is based on the ideas and understanding of Gurdjieff's system (not to be called "The Fourth Way", but simply the "Gurdjieff System") and contains the personal thoughts and development of a person working on themselves according to the system. The explanation on how Mount Analogue would have been physically hidden from anyone for so long is definitely done by the latest science available at that period (1930s), but with today's satellites and space observation does not hold well at all, although it was probably ingenious for the time. Also getting there, getting in and discovering no new technology (based on electricity) works on the mountain is also very interesting, especially connected to Gurdjieff's notion that electricity was discovered before and is not an inexhaustible resource. Of course, Father Sogol is no one but Alexandre de (von) Saltzmann, one of the foremost Gurdjieff's students, of whom not as much is known, compared to the other students like Alexandre's wife Jeanne, and the de (von) Hartmann's. He must have been a formidable personality to have left such an impression on Daumal. This book is a gem, even in its unfinished form, or maybe because of it.This book must have been revolutionary when it came out in the 1930s. The language, the style, the unbashed uncaring for literary norms must have been like a fresh air of rebellion to the stifled people of the 1930s who just few decades ago were under the moral oppression of the Victorian age. The book begins with an ode to Tanya's cunt. And it continues in the same manner. The word cunt is probably the most used word in the entire book. Today it would be called vulgar, but at the time it was revolutionary and brave. Miller describes multiple women he's had sex with while living in Paris, mostly on the money of other people, or as a vagrant and homeless on the streets. Most of the women he sleeps with are prostitutes (and he goes at length discussing the different types of prostitutes), but there is also the Jewish adulteress, the Russian princess with gonorrhea, the strange french woman to whom he gives 100 francs and then takes them out of her purse after having sex with her in her house above the room of her sick mother. Chapters of lucid description of characters (mostly Miller's friends whose money he uses, at whose houses he sleeps and whose women he has sex with) and some semblance of story lines are alternated with chapters of stream-of-consciousness monologues with prophetic statements and deep insights into life and living that usually come only after a very heavy intoxication with various substances. The book finishes in a middle of an action, just like it starts. Nothing really happens throughout and there's no sustained plot or even any novel-long characters (except the author-narrator) but it does give an entertaining and fascinating view into the life of the American emigres to Paris between the two wars in a much different way than Hemingway. POSTED BY MR.B. AT 2:12 PM NO COMMENTS: THURSDAY, JULY 7, 2016 "Mount Analogue" by Rene Daumal It ends in mid-sentence in the fifth chapter. Rene Daumal died days later of tubercolosis. He was in his 36th year of his life. Peradams. Only Father Sogol (Logos, took me a while to figure it out without anyone pointing it out to me) found one and very low, below the mountain where no Peradams are usually found, but he had an epiphany about himself. The book has an extensive intro section where the future planned chapters by Daumal are explained and it is a real shame that they were not written. Or maybe the book is more effective this way? After all Gurdjieff's "Life is real only when I AM" also stops in a middle of a sentence, and some who have seen the original manuscripts say that the published version is a much smaller selection from what was available. "Mount Analogue" is a very readable and well written book, to be expected from a writer of Daumal's caliber, and although Gurdjieff's name is never explicitly mentioned - it is based on the ideas and understanding of Gurdjieff's system (not to be called "The Fourth Way", but simply the "Gurdjieff System") and contains the personal thoughts and development of a person working on themselves according to the system. The explanation on how Mount Analogue would have been physically hidden from anyone for so long is definitely done by the latest science available at that period (1930s), but with today's satellites and space observation does not hold well at all, although it was probably ingenious for the time. Also getting there, getting in and discovering no new technology (based on electricity) works on the mountain is also very interesting, especially connected to Gurdjieff's notion that electricity was discovered before and is not an inexhaustible resource. Of course, Father Sogol is no one but Alexandre de (von) Saltzmann, one of the foremost Gurdjieff's students, of whom not as much is known, compared to the other students like Alexandre's wife Jeanne, and the de (von) Hartmann's. He must have been a formidable personality to have left such an impression on Daumal. This book is a gem, even in its unfinished form, or maybe because of it.This book must have been revolutionary when it came out in the 1930s. The language, the style, the unbashed uncaring for literary norms must have been like a fresh air of rebellion to the stifled people of the 1930s who just few decades ago were under the moral oppression of the Victorian age. The book begins with an ode to Tanya's cunt. And it continues in the same manner. The word cunt is probably the most used word in the entire book. Today it would be called vulgar, but at the time it was revolutionary and brave. Miller describes multiple women he's had sex with while living in Paris, mostly on the money of other people, or as a vagrant and homeless on the streets. Most of the women he sleeps with are prostitutes (and he goes at length discussing the different types of prostitutes), but there is also the Jewish adulteress, the Russian princess with gonorrhea, the strange french woman to whom he gives 100 francs and then takes them out of her purse after having sex with her in her house above the room of her sick mother. Chapters of lucid description of characters (mostly Miller's friends whose money he uses, at whose houses he sleeps and whose women he has sex with) and some semblance of story lines are alternated with chapters of stream-of-consciousness monologues with prophetic statements and deep insights into life and living that usually come only after a very heavy intoxication with various substances. The book finishes in a middle of an action, just like it starts. Nothing really happens throughout and there's no sustained plot or even any novel-long characters (except the author-narrator) but it does give an entertaining and fascinating view into the life of the American emigres to Paris between the two wars in a much different way than Hemingway. POSTED BY MR.B. AT 2:12 PM NO COMMENTS: THURSDAY, JULY 7, 2016 "Mount Analogue" by Rene Daumal It ends in mid-sentence in the fifth chapter. Rene Daumal died days later of tubercolosis. He was in his 36th year of his life. Peradams. Only Father Sogol (Logos, took me a while to figure it out without anyone pointing it out to me) found one and very low, below the mountain where no Peradams are usually found, but he had an epiphany about himself. The book has an extensive intro section where the future planned chapters by Daumal are explained and it is a real shame that they were not written. Or maybe the book is more effective this way? After all Gurdjieff's "Life is real only when I AM" also stops in a middle of a sentence, and some who have seen the original manuscripts say that the published version is a much smaller selection from what was available. "Mount Analogue" is a very readable and well written book, to be expected from a writer of Daumal's caliber, and although Gurdjieff's name is never explicitly mentioned - it is based on the ideas and understanding of Gurdjieff's system (not to be called "The Fourth Way", but simply the "Gurdjieff System") and contains the personal thoughts and development of a person working on themselves according to the system. The explanation on how Mount Analogue would have been physically hidden from anyone for so long is definitely done by the latest science available at that period (1930s), but ..</div>
                                 <div class="col-md-2">
                                     <a href="#f" align="right" class="btn 
                                 btn-danger" role="button">Down
                                     </a>
                                 </div>
                      </div>
          </div>  
     <footer>
         <div class="container-fluid">
            <p><a id="f">All right unreserved</a></p>
         </div>
      </footer>
</body>
</html>

最佳答案

我推荐的一种方法是使用 flex

首先确保 bodycontainerrowcol1 都占据完整的高度,即使是空的 (检查以确认)。

如果是,则将 col1 设置为 display:flex。然后,您可以轻松地使用 flex 子项的 flex-end 属性使其保持向下。

#upButton {
 align-self: flex-end
}

关于javascript - 列内的绝对位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39480328/

相关文章:

javascript - SharePoint 聊天图标嵌入 iframe 问题

html - 在 HTML 代码中嵌入 SVG 文件时,如何在不同的浏览器上产生相同的结果?

html - 根据内容维护li宽度

javascript - 对具有 ID 的元素的 HTML href

javascript - 根据事件选项卡更改文本颜色

javascript - 如何将变量传递给数组JS

javascript - 在同一个按钮上滑入和滑出内容

html - 透明 block 中的非透明图像

javascript - 从 github url 中查找用户、repo 和路径

html - 将父 div 相对的 div 居中