html - 左边距和 100% 宽度插入 float 文本移出浏览器边缘

标签 html css css-float css-position

我有以下 html:

<div class="footer">
  <div class="text">
  This text float to right
  </div>
</div>

以及以下 CSS:

.footer {
  position: fixed;
  top: 0;
  left:0;
  background-color: pink;
  width: 100%;
  margin-left: 50px;
}
.text {
  float: right;
}

这是 jsfiddle 示例:https://jsfiddle.net/mddc/68tgqxpa/4/

问题在于“此文本向右浮动”的某些部分被推到了浏览器边缘之外。如何使用CSS让全文显示到浏览器边缘?

左边距无法删除。

最佳答案

使用页脚的宽度,如下所示:

width: calc(100% - 50px);

就这样吧!让我知道您的反馈。谢谢!

.footer {
  position: fixed;
  top: 0;
  left: 0;
  background-color: pink;
  width: calc(100% - 50px);
  margin-left: 50px;
}
.text {
  float: right;
}
<div class="footer">
  <div class="text">
    This text float to right
  </div>
</div>

关于html - 左边距和 100% 宽度插入 float 文本移出浏览器边缘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38965954/

相关文章:

css - float 的 div 不会完全展开

html - 为什么 margin-top 从网站顶部开始计算,而不是上面的元素?

javascript - 使用 jQuery 将字符串添加到文本区域

jquery - 移动设备上缺少导航栏内容

PHP使用单选按钮的值

html - 如何让我的 CSS 网格居中?

css - Sharepoint 自定义主题表现异常

html - 调整 html 响应模板电子邮件

javascript - 如何调整 react 表中的整个列边框

css - 围绕 CSS-div 定位的文本 float