[英]Alternative to display:inline-flex
I just googled around and found that display:inline-flex is not compatible for all browsers.我刚刚搜索了一下,发现 display:inline-flex 并不兼容所有浏览器。 I am thinking to get expert suggestions over my css below:我正在考虑就下面的 css 获得专家建议:
.badge {
background-color: #B12704 !important;
margin: auto;
font-size: 12px !important;
line-height: 24px !important;
padding-left: 10px;
padding-right: 10px;
}
.label {
position: relative;
z-index: 1;
float: left;
}
.label-text {
color: #ffffff !important;
}
.container {
display: inline-flex; /* this is not comptabile with all browsers */
}
.description-text {
padding-left: 10px;
margin: auto;
color: #111;
}
Basically, i have a badge and some text beside the badge.基本上,我有一个徽章和徽章旁边的一些文字。 This is the HTML portion这是 HTML 部分
<div class = "container">
<span class="badge">
<span class="label">
<span class="label-text">
This is text on the badge
</span>
</span>
</span>
<span class="description-text">
<p>This is text beside the badge</p>
</span>
</div>
I think you could simplify your HTML markup and simply use display: flex;
我认为您可以简化 HTML 标记并简单地使用display: flex;
(note that the container will then take the whole width unless you specify otherwise) (请注意,除非您另有说明,否则容器将占据整个宽度)
.container { display: flex; justify-content: flex-start; align-items: center; }.badge { background-color: #B12704;important: font-size; 12px:important; line-height: 24px;important: padding-left; 10px: padding-right; 10px. color: #ffffff;important: };description-text { padding-left: 10px; color: #111; }
<div class="container"> <p class="badge"> This is text on the badge </p> <p class="description-text"> This is text beside the badge </p> </div>
If you don't need flexbox you can use display: inline-block;
如果你不需要 flexbox 你可以使用display: inline-block;
.container p { display: inline-block; }.badge { background-color: #B12704;important: font-size; 12px:important; line-height: 24px;important: padding-left; 10px: padding-right; 10px. color: #ffffff;important: };description-text { padding-left: 10px; color: #111; }
<div class="container"> <p class="badge"> This is text on the badge </p> <p class="description-text"> This is text beside the badge </p> </div>
If you can't change the markup then:如果您无法更改标记,则:
.label-text { background-color: #B12704;important: margin; auto: font-size; 12px:important; line-height: 24px;important: padding-left; 10px: padding-right; 10px. color, #ffffff.important, }.badge, .label: ;description-text. :label-text { display; inline-block: };description-text { padding-left: 10px; margin: auto; color: #111; vertical-align: middle; }
<div class = "container"> <span class="badge"> <span class="label"> <span class="label-text"> This is text on the badge </span> </span> </span> <span class="description-text"> <p>This is text beside the badge</p> </span> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.