html - 粘条不能做 float :right

标签 html css

我已经将我的 bootstrap-3 网站用于粘性栏,我尝试这样做 How TO - Sticky Social Bar我做了一些修改,

我使用了 float: right; 但它不起作用,

我的冲突是,那个栏不能设置为网站 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> 

最佳答案

当你给出它的位置时使用 right:0; - fixedabsolute

另外 - 一个 codepen 示例 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> 

关于html - 粘条不能做 float :right,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52847333/

相关文章:

html - 头部样式表和谷歌代码

html - 适合边框内的内容

css - 仅对 div 的前 10 个 <a> 标记应用 CSS 效果

php - 在没有插件的情况下使用内置在 thickbox 中的 wordpress

javascript - 水平和垂直可滚动的大表格

css - 使用非 float <div> 创建页面布局

javascript - 如何使用 cookie 保存 menu_toggle 的设置?

php - 导入图片到文件夹,图片路径到数据库

javascript - 如何更改 iframe 中的 body css 元素?

javascript - 在 Google 应用脚本中从 URL 传递参数