css - 修复了 100% 宽度的位置问题

标签 css

我在使用的时候遇到了如下错误

.high-secuity {
    position: fixed;
    top: 0;
    background: #ff782f;
    color: #fff;
    width: 100%;
    border-radius: 0;
    margin-bottom: 0;
    margin-left: -15px;
}

enter image description here

问题是橙色面板超出了屏幕。我该如何解决这个问题?不想使用固定宽度,因为它应该是响应式的

最佳答案

使用 width: inherit; 到我的示例正在运行的橙色 block

body {
  background-color: #ccc;
}

.container {
  position: relative;
  width: 300px;
  background-color: #fff;
  overflow: hidden;
  padding: 50px 15px;
}

.high-secuity {
  position: fixed;
  top: 0;
  background: #ff782f;
  color: #fff;
  width: inherit;
  border-radius: 0;
  margin-bottom: 0;
  margin-left: -15px;
  padding: 15px;
}
<div class="container">
  <h1>Osloskolen</h1>
  <div class="high-secuity">Your message</div>
</div>

关于css - 修复了 100% 宽度的位置问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54556643/

相关文章:

html - 将按钮中的图像与文本居中

css - 如何设置 VW 和 VH 值来选择选项

html - 使用纯 CSS 创建水平可折叠 Accordion

asp.net - 生成动态 Css

javascript - jQuery 滚动和 anchor 初始位置

javascript - 使所有div.obstacles具有相同的功能

css - 如何基于flex或grid设置动态网格

css - 段落自动换行

javascript - 如何将两个小书签合二为一来切换亮度?

css - margin:0 auto 在 Internet Explorer 中不起作用