[英]Replacing tables with unordered lists
I have a requirement to remove the use of tables and replace the code with HTML lists ( <ul>
and <li>
). 我需要删除表的使用,并用HTML列表(
<ul>
和<li>
)替换代码。 The HTML code to be replaced is as below 要替换的HTML代码如下
<table>
<tr>
<td>
<img width="40" height="40" src="../images/johnsmith2.jpg" alt="johnsmith2" />
</td>
<td>
<table>
<tr><td>John Smith</td></tr>
<tr><td>24 years</td></tr>
<tr><td>Chicago</td></tr>
</table>
</td>
</tr>
</table>
Tried multiple options using lists but could not achieve this display. 使用列表尝试了多个选项,但无法实现此显示。 The text on the right always went below the image using lists, I wanted the vertical text list (name, then age, then city) to be adjacent to the image ie the list should produce the same shape as produced by the above table.
右侧的文本始终使用列表位于图像下方,我希望垂直文本列表(名称,年龄,城市)与图像相邻,即列表应具有与上表相同的形状。
Please let me know how this can be done via CSS with HTML lists. 请让我知道如何通过带有HTML列表的CSS来完成此操作。
There are so many tutorials for this. 有这么多的教程。 Keep googling or try in w3schools.com.
继续谷歌搜索或在w3schools.com中尝试。
or may be check this: http://www.javascriptkit.com/script/script2/verticalmenu.shtml 或者可以检查一下: http : //www.javascriptkit.com/script/script2/verticalmenu.shtml
You could try something like this 你可以尝试这样的事情
<style>
.profile li{
float: right;
clear: right;
}
.profile .image{
float: left;
clear: none;
}
</style>
<ul class="profile">
<li class="image"><img width="40" height="40" src="../images/johnsmith2.jpg" alt="johnsmith2" /></li>
<li>John Smith</li>
<li>24 years</li>
<li>Chicago</li>
</ul>
For this you can use display:table property for this. 为此,您可以为此使用display:table属性。 Write like this:
这样写:
CSS 的CSS
.profile > li{
display:table-cell;
}
.profile{
display:table;
}
HTML 的HTML
<ul class="profile">
<li><img width="40" height="40" src="../images/johnsmith2.jpg" alt="johnsmith2" /></li>
<li>
<ul>
<li>John Smith</li>
<li>24 years</li>
<li>Chicago</li>
</ul>
</li>
</ul>
Check this http://jsfiddle.net/GCfSx/1/ 检查此http://jsfiddle.net/GCfSx/1/
Here is an example on jsFiddle
, which contains your required solution... 这是
jsFiddle
上的jsFiddle
,其中包含您所需的解决方案...
http://jsfiddle.net/ZHbxr/16/ http://jsfiddle.net/ZHbxr/16/
You need to mark the parent <ul> display as table
and the inner <li> display as table-cell
您需要将
parent <ul> display as table
标记parent <ul> display as table
,将inner <li> display as table-cell
标记inner <li> display as table-cell
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.