html - 当我给 margin 0 0 0 auto 时,它应该转到最右边,但输出中没有应用样式
问题描述
在这种情况下,在边距中,最后一个是左,因此在这种情况下它被指定为自动。所以它应该在它的最右边。但它没有发生。我想知道这背后的逻辑。
.follow-btn {
margin: 0 0 0 auto ;
}
<div class="follow-btn">
<button>Follow</button>
</div>
解决方案
您将边距应用于 div,默认情况下填充页面的整个宽度。因此,为了确保auto
左侧的边距将其推到右侧,您可以指定一个指定的宽度,使其实际上浮动到右侧。
所以这改变了你的例子:
.follow-btn {
margin: 0 0 0 auto;
background: red; /* just to show the effect on the div */
}
<div class="follow-btn">
<button>Follow</button>
</div>
对此:
.follow-btn {
margin: 0 0 0 auto;
background: red; /* just to show the effect on the div */
width: 4em;
}
<div class="follow-btn">
<button>Follow</button>
</div>
推荐阅读
- r - R ranger 包中的预测概率
- angular - 在 Angular 2 项目中使用 PureMVC 框架
- java - 当我发布到 HTTP 而不是 HTTPS 时,它会调用 get 路由
- javascript - 如何获取 CSS 3D 转换画布的画布相对鼠标位置?
- octave - 为什么我在 Octave trisurf 中得到奇数 0,0 点
- angularjs - AngularJS - 带有 ng 重复的基本 $index
- javascript - 如何隐藏具有相同类名的特定按钮
- php - 通过 AJAX 将 URL 查询字符串传递给 PHP
- c - 循环优化?如果如果与如果如果
- karate - 空手道包含函数抛出错误否定