代码之家  ›  专栏  ›  技术社区  ›  core114

粘条做不到float:right

  •  6
  • core114  · 技术社区  · 6 年前

    我用我的bootstrap-3网站的贴条,我试着这样做 How TO - Sticky Social Bar

    float: right; 但它不起作用,

    我的矛盾是, that bar cant set to the web site float:right ,我想走右边

    谢谢。

      position: fixed;
      top: 50%;  float: right;
    
    }
    
    .icon-bar a {
      display: block;
      text-align: center;
      padding: 16px;
      transition: all 0.3s ease;
      color: white;
      font-size: 20px;
    }
    
    .icon-bar a:hover {
      background-color: #000;
    }
    
    .facebook {
      background: #3B5998;
      color: white;
    }
    <!DOCTYPE html>
    <html>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <style>
    body {margin:0;height:2000px;}
    
    .icon-bar {
      position: fixed;
      top: 50%;
      -webkit-transform: translateY(-50%);
      -ms-transform: translateY(-50%);
      transform: translateY(-50%);
    }
    
    .icon-bar a {
      display: block;
      text-align: center;
      padding: 16px;
      transition: all 0.3s ease;
      color: white;
      font-size: 20px;
    }
    
    .icon-bar a:hover {
      background-color: #000;
    }
    
    .facebook {
      background: #3B5998;
      color: white;
    }
    
    .twitter {
      background: #55ACEE;
      color: white;
    }
    
    .google {
      background: #dd4b39;
      color: white;
    }
    
    .linkedin {
      background: #007bb5;
      color: white;
    }
    
    .youtube {
      background: #bb0000;
      color: white;
    }
    
    .content {
      margin-left: 75px;
      font-size: 30px;
    }
    </style>
    <body>
    
    
    <div class="icon-bar">
      <a href="#" class="facebook">RFQ</a>
    
    </div>
    
    
    <div class="content">
     </div>
    
    </body>
    </html> 
    4 回复  |  直到 6 年前
        1
  •  7
  •   Viira    6 年前

    使用 right:0; fixed absolute

    还有一个代码笔的例子 https://codepen.io/anon/pen/aRqvqG (你在问题中提到的例子)

    .icon-bar a {
      display: block;
      text-align: center;
      padding: 16px;
      transition: all 0.3s ease;
      color: white;
      font-size: 20px;
    }
    
    .icon-bar a:hover {
      background-color: #000;
    }
    
    .facebook {
      background: #3B5998;
      color: white;
    }
    <!DOCTYPE html>
    <html>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <style>
    body {margin:0;height:2000px;}
    
    .icon-bar {
      position: fixed;
      top: 50%;
       right: 0;
      -webkit-transform: translateY(-50%);
      -ms-transform: translateY(-50%);
      transform: translateY(-50%);
    }
    
    .icon-bar a {
      display: block;
      text-align: center;
      padding: 16px;
      transition: all 0.3s ease;
      color: white;
      font-size: 20px;
    }
    
    .icon-bar a:hover {
      background-color: #000;
    }
    
    .facebook {
      background: #3B5998;
      color: white;
    }
    
    .twitter {
      background: #55ACEE;
      color: white;
    }
    
    .google {
      background: #dd4b39;
      color: white;
    }
    
    .linkedin {
      background: #007bb5;
      color: white;
    }
    
    .youtube {
      background: #bb0000;
      color: white;
    }
    
    .content {
      margin-left: 75px;
      font-size: 30px;
    }
    </style>
    <body>
    
    
    <div class="icon-bar">
      <a href="#" class="facebook">RFQ</a>
    
    </div>
    
    
    <div class="content">
     </div>
    
    </body>
    </html> 
        2
  •  2
  •   Vikas Jadhav    6 年前

    right:0; float:right float:right 不适用于 position:fixed;

        3
  •  2
  •   Learning    6 年前

    你必须使用 right:0;

    .icon-bar {
    right:0;
    }
    

    HTML格式

    <!DOCTYPE html>
    <html>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <style>
    body {margin:0;height:2000px;}
    
    .icon-bar {
    right:0;
      position: fixed;
      top: 50%;
      -webkit-transform: translateY(-50%);
      -ms-transform: translateY(-50%);
      transform: translateY(-50%);
    }
    
    .icon-bar a {
      display: block;
      text-align: center;
      padding: 16px;
      transition: all 0.3s ease;
      color: white;
      font-size: 20px;
    }
    
    .icon-bar a:hover {
      background-color: #000;
    }
    
    .facebook {
      background: #3B5998;
      color: white;
    }
    
    .twitter {
      background: #55ACEE;
      color: white;
    }
    
    .google {
      background: #dd4b39;
      color: white;
    }
    
    .linkedin {
      background: #007bb5;
      color: white;
    }
    
    .youtube {
      background: #bb0000;
      color: white;
    }
    
    .content {
      margin-left: 75px;
      font-size: 30px;
    }
    </style>
    <body>
    
    
    <div class="icon-bar">
      <a href="#" class="facebook">RFQ</a>
    
    </div>
    
    
    <div class="content">
     </div>
    
    </body>
    </html>
        4
  •  2
  •   Raymond Natio    6 年前

    position: fixed;
      top: 50%;  float: right;
    
    }
    
    .icon-bar a {
      display: block;
      text-align: center;
      padding: 16px;
      transition: all 0.3s ease;
      color: white;
      font-size: 20px;
    }
    
    .icon-bar a:hover {
      background-color: #000;
    }
    
    .facebook {
      background: #3B5998;
      color: white;
    }
    <!DOCTYPE html>
    <html>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <style>
    body {margin:0;height:2000px;}
    
    .icon-bar {
      /*position: fixed;
      top: 50%;
       right: 0;
      -webkit-transform: translateY(-50%);
      -ms-transform: translateY(-50%);
      transform: translateY(-50%);*/
      float: right;
    }
    
    .icon-bar a {
      display: block;
      text-align: center;
      padding: 16px;
      transition: all 0.3s ease;
      color: white;
      font-size: 20px;
    }
    
    .icon-bar a:hover {
      background-color: #000;
    }
    
    .facebook {
      background: #3B5998;
      color: white;
    }
    
    .twitter {
      background: #55ACEE;
      color: white;
    }
    
    .google {
      background: #dd4b39;
      color: white;
    }
    
    .linkedin {
      background: #007bb5;
      color: white;
    }
    
    .youtube {
      background: #bb0000;
      color: white;
    }
    
    .content {
      margin-left: 75px;
      font-size: 30px;
    }
    </style>
    <body>
    
    
    <div class="icon-bar">
      <a href="#" class="facebook">RFQ</a>
    
    </div>
    
    
    <div class="content">
     </div>
    
    </body>
    </html> 

    或者如果你想让它粘在右边就这样做

    <!DOCTYPE html>
    <html>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <style>
    body {margin:0;height:2000px;}
    
    .icon-bar {
      position: fixed;
      top: 50%;
       right: 0;
      -webkit-transform: translateY(-50%);
      -ms-transform: translateY(-50%);
      transform: translateY(-50%);
    }
    
    .icon-bar a {
      display: block;
      text-align: center;
      padding: 16px;
      transition: all 0.3s ease;
      color: white;
      font-size: 20px;
    }
    
    .icon-bar a:hover {
      background-color: #000;
    }
    
    .facebook {
      background: #3B5998;
      color: white;
    }
    
    .twitter {
      background: #55ACEE;
      color: white;
    }
    
    .google {
      background: #dd4b39;
      color: white;
    }
    
    .linkedin {
      background: #007bb5;
      color: white;
    }
    
    .youtube {
      background: #bb0000;
      color: white;
    }
    
    .content {
      margin-left: 75px;
      font-size: 30px;
    }
    </style>
    <body>
    
    
    <div class="icon-bar">
      <a href="#" class="facebook">RFQ</a>
    
    </div>
    
    
    <div class="content">
     </div>
    
    </body>
    </html>