I have a requirement to remove the use of tables and replace the code with HTML lists (<ul> and <li>). The HTML code to be replaced is as below
<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 i.e. 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.
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>
Here is an example on jsFiddle, which contains your required solution...
http://jsfiddle.net/ZHbxr/16/
You need to mark the parent <ul> display as table and the inner <li> display as table-cell
For this you can use display:table property for this. Write like this:
CSS
.profile > li{
display:table-cell;
}
.profile{
display:table;
}
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/
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I am currently displaying images on my website that are also links to different pages.
How can I add a text description below each of the clickable links?
The code I have written is below.
Thank you for your help!
<section>
<ul class="film_strip">
<li><img src="Img\drawing.png" width="130" height="130" alt="Learn to draw" /></li>
<li><img src="Img\art.png" width="130" height="130" alt="art Design and creation" /></li>
<li><img src="Img\designart.png" width="130" height="130" alt="design" /></li>
</ul>
</section>
.film_strip li {
float: left;
list-style-type: none;
}
.film_strip li img {
float: left;
background: #DEE0E3;
padding: 10px;
margin: 5px;
border: 1px solid #AAA;
color: #3C3C3D;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
}
The question asks how to display a description below the link. The link is the img.
First to note a couple of errors in the given code:
An unordered list (ul) element only has list (li) elements as its children, so the anchor (a) element must be nested inside the li
The CSS for the imgs has 4 settings which apply to text. img elements do not themselves have children so the styling of text is not relevant to them.
Then to note one possible infelicity - the use of float. Although it works, the li elements rest next to each other on a line, float was not originally intended for this purpose. Using inline-block is probably preferable. See Advantages of using display:inline-block vs float:left in CSS for discussion of this.
Now we can add text after the link, that is, after the closing tag. This snippet puts the text in a div (as that gives flexibility if the description actually contains other element types) and the text-related CSS that was given for the img is moved to this div.
.film_strip li {
display: inline-block;
list-style-type: none;
}
.film_strip li img {
float: left;
background: #DEE0E3;
padding: 10px;
margin: 5px;
border: 1px solid #AAA;
}
.film_strip li div {
color: #3C3C3D;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
}
<section>
<ul class="film_strip">
<li>
<img src="https://picsum.photos/id/1015/200/300" width="130" height="130" alt="Learn to draw" />
<div>Drawing</div>
</li>
<li>
<img src="https://picsum.photos/id/1015/200/300" width="130" height="130" alt="art Design and creation" />
<div>Art</div>
</li>
<li>
<img src="https://picsum.photos/id/1015/200/300" width="130" height="130" alt="design" />
<div>Design</div>
</li>
</ul>
</section>
<section>
<ul class="film_strip" style="list-style:none;">
<li><img src="https://picsum.photos/id/237/200/300" width="130" height="130" alt="Learn to draw" /><br>Description 1</li>
<li><img src="https://picsum.photos/id/238/200/300" width="130" height="130" alt="art Design and creation" /><br>Description 2</li>
<li><img src="https://picsum.photos/id/239/200/300" width="130" height="130" alt="design" /><br>Description 3</li>
</ul>
</section>
I want to place an image between the bullet point and the text in an unordered list, I have tried several ways but the last one closest to the point was this:
<ul>
<li>
<img src="../2/question/img/zeplin.png" alt="zeplin" style="float: left;">
<p>Zeplin</p>
</li>
<br>
<li>
<img src="../2/question/img/dropbox.png" alt="dropbox" style="float: left;">
<p>Dropbox</p>
</li>
</ul>
This is a photo of the goal:
How can I write this?
li img {
height: 50px;
display: flex;
margin-right: 10px;
}
<ul>
<li>
<img src="https://i.picsum.photos/id/103/2592/1936.jpg?hmac=aC1FT3vX9bCVMIT-KXjHLhP6vImAcsyGCH49vVkAjPQ"
alt="zeplin" style="float: left;">
<p>Zeplin</p>
</li>
<br>
<li>
<img src="https://i.picsum.photos/id/1029/4887/2759.jpg?hmac=uMSExsgG8_PWwP9he9Y0LQ4bFDLlij7voa9lU9KMXDE"
alt="dropbox" style="float: left;">
<p>Dropbox</p>
</li>
</ul>
Simply use list-style-image property in your unordered list and put the image url inside url method. Example:
ul {
list-style-image: url('your_image.png');
}
li img, p {
display: inline-block;
}
<ul>
<li><img src="https://i.stack.imgur.com/wlm3P.png"><p>Zeplin</p>
<li><img src="https://i.stack.imgur.com/DgOJ5.png"><p>Dropbox</p>
</ul>
I am trying to make my list horizontally and I saw that I need to type: display:inline; inside style argument but when I tried it, it didn't work. I will attach my code here maybe I did something wrong. thanks for the helpers!
<body style="font-family:Calibri; font-size:20px">
<center>
<img src="Images/Logo.jpg" style ="margin-top:100px; border:5px solid black;" alt="GameReview" title="Game Review"/>
<br />
<br />
<ul style="list-style-type:none; display:inline;">
<li>
Details
</li>
<li>
On me
</li>
<li>
Gallery
</li>
<li>
Links
</li>
<li>
Conatact me
</li>
</ul>
</center>
</body>
this is for a school project.
The inline style needs to be on the li element.
<style>
ul li {
display: inline;
}
</style>
This question already has answers here:
Unwanted margin in inline-block list items [duplicate]
(10 answers)
Closed 9 years ago.
So I'm a little stumped. I'm trying to make a page to display images. I want there to be 5 images per row spaced with maximum amount when the window is at max width (~950 px), but I want them to get closer as you make it smaller and then, when there's 0 px between them, there will only be 4 images per row, and that will continue until a specific width. Kind of like Instagram, but I don't want the pictures to get smaller. Here's what I have:
HTML
<ul>
<li>
<img src="0.png">
</li>
</ul>
<ul>
<li>
<img src="1.png">
</li>
</ul>
<ul>
<li>
<img src="2.png">
</li>
</ul>
CSS
ul
{
padding: 0;
margin: 0;
list-style-type: none;
}
ul li
{
display: inline;
}
//the images are also float left, so they are horizontal
Basically, as you can see, I have nothing and I don't really know what to do. I'd appreciate any help. Thanks!
Can you do me a favor and try this fix (I know there is an obnoxious invisible-spacing bug related to lis written on newlines in the HTML, not sure if it applies to UL's in order too but it's worth a shot) --
<ul><li><img src="0.png"></li></ul><ul><li><img src="1.png"></li></ul><ul><li><img src="2.png"></li></ul>
this may get you closer to where you want to go:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<style>
ul {
padding: 0;
margin: 0;
list-style-type: none;
min-width:450px;
}
ul li {
display: inline;
float:left;
width:20%;
}
</style>
</head>
<body>
<ul>
<li> <img src="0.png" width="150" height="50"> </li>
<li> <img src="1.png" width="150" height="50"> </li>
<li> <img src="2.png" width="150" height="50"> </li>
<li> <img src="0.png" width="150" height="50"> </li>
<li> <img src="1.png" width="150" height="50"> </li>
<li> <img src="2.png" width="150" height="50"> </li>
</ul>
</body>
</html>
It is more "proper" markup to put all the images into one list, and opens the door for setting a hard minimum width on the ul but a % on the li... which is what makes the whitespace vary with the window sizing. I am not sure if this gets you all the way there, but hopefully it will help!
Your unordered list should look like this:
<ul><li><img src="0.png"></li><li><img src="1.png"></li><li><img src="2.png"></li></ul>
Super unconventional, but it works.
Fiddle here: http://jsfiddle.net/QMs93/
http://jsfiddle.net/AgLMp/1
CSS
ul {
padding: 0;
margin: 0;
list-style-type: none;
max-width: 950px;
min-width: 600px;
}
ul li {
float: left;
width: 33%;
min-width: 200px;
}
HTML
<ul>
<li>
<img src="http://placehold.it/200x200/ff0000/00ffff&text=Image+1" />
</li>
<li>
<img src="http://placehold.it/200x200/00ff00/ff00ff&text=Image+2" />
</li>
<li>
<img src="http://placehold.it/200x200/0000ff/ffff00&text=Image+3" />
</li>
</ul>
like this? http://jsfiddle.net/fqTsN/
remove the float:left from your pictures by the way! I fixed that too (it's horizontal without float:left;
your best and fastest bet for more control is to use media queries, or you could also use Bootstrap.
As everyone else has said:
<ul>
<li>Stuff</li>
<li> Other Stuff</li>
</ul>
I am using jQuery mobile and I am trying to center some image icons within a list. The problem I am having is that the images are not vertically centered within a list item.
Can someone kindly point me in the right direction since I am not a CSS expert by far. I know I can get them using tables but I do not want to do that. Thanks.
Oh and I am using EJS in the code below. Please see the screenshot:
Here is my code:
<li data-icon="false">
<a href="#">
<img src="images/img_trans.gif" class='largePlatform platform_<%= releases[i].platform_abbr %>_large' width='30' height='30' style="position:absolute; top:25%; left:10px"/>
<h2 style="position:absolute; top:25%; left:50px"><%= releases[i].platform_abbr %></h2>
<div data-role="controlgroup" data-type="horizontal" style="float:right" >
<% if (purchaseText != "") { %>
<img src="images/game_detail/<%= releases[i].purchase_button_icon %>-purchase.png" width="35" height="35" onclick="window.open('<%= releases[i].purchase_button_url %>');" alt="<%= purchaseText %>" style="position:relative; top:10px;"/>
<% } %>
<div data-role="button" data-icon="reminder" data-theme="<%= buttonTheme %>" onclick="<%= buttonAction %>(<%= releases[i].id %>)">
<%= buttonText %>
</div>
</div>
</a>
</li>
Live Example:
http://jsfiddle.net/B6Z9N/
HTML
<li>
<img src="http://dummyimage.com/20x20/000/000000.png" />
</li>
CSS
li {
border: 1px dotted black; /* Just to illustrate height */
height: 100px;
line-height: 100px;
vertical-align: middle;
}
Found this article: http://css-tricks.com/snippets/css/absolute-center-vertical-horizontal-an-image/
I know I'm late to the party but I always use this and thought someone might find it useful.
HTML:
<ul>
<li class="logo_bar"><img src="img/1" /></li>
<li class="logo_bar"><img src="img/2" /></li>
<li class="logo_bar"><img src="img/3" /></li>
<li class="logo_bar"><img src="img/4" /></li>
<li class="logo_bar"><img src="img/5" /></li>
</ul>
CSS:
.logo_bar {
display: inline-block;
vertical-align: middle;
}
Just apply margin on img.
<li>
<img class="image-style" src="https://dummyimage.com/20x20/000/111fed" />
</li>
.image-style {
margin : 10px -10px;
}
li {
border : 1px solid black
}
JSFiddle