简体   繁体   English

如何使第一个元素与右侧对齐,其他元素在左侧对齐?

[英]How to make the first element aligned to the right and the other elements in the left of that first?

I have two HTML elements: label and span inside a div I want the label aligned to the right and the span in the left of the labe;我有两个 HTML 元素: div 中的 label 和 span 我希望标签向右对齐,span 在标签左侧;

like this :像这样 :
在此处输入图片说明

But this is what I have:但这就是我所拥有的:

在此处输入图片说明

this is the HTML and CSS code:这是 HTML 和 CSS 代码:

 .barcode-pdf-body div { text-align: right; border-color: transparent; margin-top: 0; font-size: 10px; margin-bottom: 9px; } .barcode-pdf-body div label { margin-left: 5px; font-weight: bold; font-family: "myFont"; } .barcode-pdf-body div span { font-family: "myFont"; }
 <div> <label> {% trans 'constraint_number' %}: </label> <span> {{ correspondence.number }} </span> </div>

If you can change only CSS file, check code below:如果您只能更改 CSS 文件,请检查以下代码:

 .barcode-pdf-body div { text-align: right; border-color: transparent; margin-top: 0; font-size: 10px; margin-bottom: 9px; display: flex; } .barcode-pdf-body div label { margin-left: 5px; font-weight: bold; font-family: "myFont"; order: 2; } .barcode-pdf-body div span { font-family: "myFont"; order: 1; }
 <div> <label> {% trans 'constraint_number' %}: </label> <span> {{ correspondence.number }} </span> </div>

please try it like this:请像这样尝试:

div label {
float:right;
} 
div span {
float:left;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在表格单元格(td)中定位元素,使得一个元素左对齐而另一个元素对齐? - How can I position elements within a table cell (td) such that one element is left aligned and the other right aligned? 第一行左对齐和右对齐的CSS,包装线右对齐 - CSS for left and right align of the first line, with wrapped lines right aligned 如何使图像左对齐和内容右对齐? - How to make image aligned left and content right? 将第一个div与左对齐,后续div对齐 - Align first div to left with subsequent divs aligned right 如何使用下拉元素进行左对齐导航 - how to make a left aligned navigation with dropdown elements 元素之间的分界线,但第一项左对齐 - Divide line between elements but with first item aligned to left 如何使网格的第一个和最后一个元素与其他元素的大小不同? - How to make first and last element of a grid different sizes from the other elements? 如何将元素的左右两侧居中对齐? - How to center an element with a left and right aligned element on both sides? 可以使用 style="float: right;" 的元素吗? 与一系列“float: left;”中的第一个对齐元素? - Can an element with style="float: right;" be made to align to the FIRST of a series of "float: left;" elements? 如何使2个图标一左一右对齐? - How to make 2 icons to be aligned one to the left and one to the right?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM