[英]How can I use span like table?
I have this HTML structure: 我有这个HTML结构:
.subject{ width: 50px; }
<div> <span class = "subject">Name:</span> <span class="content">John</span> </div> <div> <span class = "subject">Age:</span> <span class="content">23</span> </div> <div> <span class="subject">cell phone:</span> <span class="content">+9400321532</span> </div>
As you see, those columns aren't in the same line. 如您所见,这些列不在同一行。 I want this output:
我想要这个输出:
/*
Name: John
Age: 23
cell phone: +9400321532
How can I do that? 我怎样才能做到这一点?
Actually I need a fixed-width for span.subject
the size of biggest content length which is cell phone
in this case. 实际上,我需要一个固定宽度的
span.subject
,在这种情况下,最大内容长度是cell phone
的大小。
Here is my code in reality: 这是我的实际代码:
.notifications_list{ margin-top: 1px; padding-right: 15px; direction: rtl; overflow: scroll; width: 100%; height: 100%; } .notifications_list li{ list-style: none; } .notification_date_title{ font-size: 14px; margin-top: 10px; } .note_icon{ } .note_icon i{ font-size: 20px; margin: 0px; } .note_type{ margin-right: 5px; }
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/> <div class="notifications_list"> <div class="notification_date_title">امروز +5</div> <ul> <li><a><div><span class="note_icon"><i class="fa fa-sort"></i></span><span class="note_type">رای</span><span class="note_date_time">2 ساعت قبل</span></div></a> </li> </ul> <div class="notification_date_title">دیروز +10</div> <ul> <li><a><div><span class="note_icon"><i class="fa fa-sort"></i></span><span class="note_type">رای</span><span class="note_date_time">14 ساعت قبل</span></div></a> </li> </ul> <div class="notification_date_title">در هفته گذشته </div> <ul> <li><a><div><span class="note_icon"><i class="fa fa-check"></i></span><span class="note_type">تایید جواب</span><span class="note_date_time">2 روز قبل</span></div></a> </li> <li><a><div><span class="note_icon"><i class="fa fa-sort"></i></span><span class="note_type">رای</span><span class="note_date_time">3 روز قبل</span></div></a> </li> </ul> </div>
您可以使用display:table
, display:table-row
和display:table-cell
将span
设为table
Use display: table-cell;
使用
display: table-cell;
.subject { display: table-cell; width: 80px; } div { display: table-row; }
<div> <span class="subject">Name:</span> <span class="content">John</span> </div> <div> <span class="subject">Age:</span> <span class="content">23</span> </div> <div> <span class="subject">cell phone:</span> <span class="content">+9400321532</span> </div>
You can make use of display table-row and table-cell to achieve this. 您可以使用display table-row和table-cell实现此目的。 Below code you can see that the width of the longest content is taken as the width if not it will take a min-width of 50px;
在下面的代码中,您可以看到最长内容的宽度被视为宽度,否则,最小宽度为50px。
Hope this is what you are expecting : 希望这是您所期望的:
.notifications_list{ margin-top: 1px; padding-right: 15px; direction: rtl; overflow: scroll; width: 100%; height: 100%; display: table; } .notifications_list div, .notifications_list ul{ display: table-row; } .notifications_list li{ list-style: none; } .notification_date_title{ font-size: 14px; margin-top: 10px; } .note_icon{ } .note_icon i{ font-size: 20px; margin: 0px; } .note_type{ margin-right: 5px; }
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/> <div class="notifications_list"> <div class="notification_date_title">امروز +5</div> <ul> <li><a><div><span class="note_icon"><i class="fa fa-sort"></i></span><span class="note_type">رای</span><span class="note_date_time">2 ساعت قبل</span></div></a> </li> </ul> <div class="notification_date_title">دیروز +10</div> <ul> <li><a><div><span class="note_icon"><i class="fa fa-sort"></i></span><span class="note_type">رای</span><span class="note_date_time">14 ساعت قبل</span></div></a> </li> </ul> <div class="notification_date_title">در هفته گذشته </div> <ul> <li><a><div><span class="note_icon"><i class="fa fa-check"></i></span><span class="note_type">تایید جواب</span><span class="note_date_time">2 روز قبل</span></div></a> </li> <li><a><div><span class="note_icon"><i class="fa fa-sort"></i></span><span class="note_type">رای</span><span class="note_date_time">3 روز قبل</span></div></a> </li> </ul> </div>
Please try this: 请尝试以下方法:
.subject{
width: 82px;
display: table-cell;
float: left;
}
Try this also: 也尝试一下:
.subject{ width: 50%; float:left; } .content{width: 50%; float:right; }
<div> <span class = "subject">Name:</span> <span class="content">John</span> </div> <div> <span class = "subject">Age:</span> <span class="content">23</span> </div> <div> <span class="subject">cell phone:</span> <span class="content">+9400321532</span> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.