前提条件
- 我有一个 searched 用于重复或关闭的功能请求
- 我已经阅读了 contributing guidelines
建议
参考
这个评论
和 this SO answer,以及
CanIUse inset-inline-end 和其他,
自2020年中以来,似乎所有主要浏览器(或绿色?)都支持以下属性(或绿色?)
inset-inline-start(代替 left 属性)
inset-inline-end(代替 right 属性)
margin-inline-start(代替 margin-left 属性)
margin-inline-end(代替 margin-right 属性)
margin-inline(代替 margin 简写属性)
padding-inline-start(代替 padding-left 属性)
padding-inline-end(代替 padding-right 属性)
padding-inline(代替 padding 简写属性)
text-align: start;(代替 left 值)
text-align: end;(代替 right 值)
float: inline-start;(代替 left 值)
float: inline-end;(代替 right 值)
以下样式仍然使用 left 和 rightme-0
... 'me-auto',ms-0
... ms-auto
,.start
... .start-100
.end
... end-100
然而,使用上述属性和属性将使 LTR 和 RTL 之间的过渡更容易
因此,而不是
LTR .start-0 { left: 0 !important; }
RTL .start-0 { right: 0 !important; }
我们可以只有.start-0 { inset-inline-start: 0 !important; }
等等。
目前我正在使用以下 html 进行这些过渡测试,这使我可以立即在 LTR 和 RTL 之间进行过渡
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<link rel="stylesheet" href="bootstrap-5.3.0/bootstrap.css">
<link rel="stylesheet" href="this/main.css">
<script src="jquery.1.11.3/jquery.min.js"></script>
<script src="bootstrap-5.3.0/bootstrap.bundle.js"></script>
<script>
$(function () {
const $html = $('html');
if (localStorage.getItem('dir') === 'rtl') {
$html.attr('dir', 'rtl');
} else {
$html.removeAttr('dir')
}
$('#btnDir').click(function () {
if ($html.attr('dir') === 'rtl') {
$html.removeAttr('dir');
localStorage.removeItem('dir')
} else {
$html.attr('dir', 'rtl');
localStorage.setItem('dir', 'rtl')
}
});
})
</script>
</head>
<body>
<input type="button" id="btnDir" class="btn btn-primary" value="direction ">
<!-- Elements being tested below-->
<div class="toast-container p-3 bottom-0 end-0" aria-live="polite" aria-atomic="true">
<div class="toast show text-bg-danger" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<strong class="me-auto">Toast-Header</strong>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">Toast Body</div>
</div>
<div class="toast text-bg-danger border-0 show" role="alert" aria-live="assertive" aria-atomic="true">
<div class="d-flex">
<div class="toast-body">
Hello, world! This is a toast message.
</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
</div>
<div class="toast text-bg-primary border-0 show" role="alert" aria-live="assertive" aria-atomic="true">
<div class="d-flex">
<div class="toast-body">Toast Body</div>
<button type="button" class="btn-close btn-close-white m-auto ms-auto me-2" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
</div>
</div>
</body>
</html>
main.css 的内容如下(显然,为了这些能够工作,我需要在 bootstrap.css 中注解它们的对应部分)
.text-start{ text-align:start !important; }
.text-end{ text-align:end !important; }
.me-0{ margin-inline-end:0 !important }
.me-1{ margin-inline-end:0.25rem !important }
.me-2{ margin-inline-end:0.5rem !important }
.me-3{ margin-inline-end:1rem !important }
.me-4{ margin-inline-end:1.5rem !important }
.me-5{ margin-inline-end:3rem !important }
.me-auto{ margin-inline-end:auto !important }
.start-0{ inset-inline-start:0 !important; }
.start-50{ inset-inline-start:50% !important;}
.start-100{ inset-inline-start:100% !important;}
.end-0{ inset-inline-end:0 !important; }
.end-50{ inset-inline-end:50% !important;}
.end-100{ inset-inline-end:100% !important;}
.toast-header .btn-close {
margin-inline-end: calc(-0.5 * var(--bs-toast-padding-x));
margin-inline-start: var(--bs-toast-padding-x);
}
动机和背景
我认为它允许从拥有两个单独的 CSS(LTR 和 RTL)到一个单一文件的过渡。
而且在未来,如果你想支持从上到下的语言;
2条答案
按热度按时间l2osamch1#
在三年前实施v5的RTL时,这已经考虑过了(参见#30918)。当时支持仍然不足,但切换到逻辑属性应该是V6的主要举措之一。
我将此标签标记为v6,因为我注意到目前没有专门的问题!
hvvq6cgz2#
或者更合理的做法是保留选择器,改变属性。这样在从左到右(LTR)的布局中,设计为从左到右(LTR),而在从右到左(RTL)的布局中,它会神奇地切换到从右到左(RTL)。
我真的期待(希望)这一点,不知道为什么你们选择了极端的方法来重命名选择器,而不是保留属性。
为什么?