简体   繁体   English

将照片样式设置为其所在元素的大小

[英]Styling a photo to be the size of the element it is in

i have made this ListView, that has a photo in it: 我做了这个ListView,里面有一张照片:

在此处输入图片说明

this is a <ul> and each person is a <li> , inside each <li> there is a <table> and the photo is in one <td> and the name and the buttons are in the other <td> . 这是一个<ul> ,每个人都是一个<li> ,每个<li>都有一个<table> ,照片位于一个<td> ,名称和按钮位于另一个<td>

now as you can see the photo isnt the size of the <li> . 现在,您可以看到照片不是<li>的大小。 it's smaller. 它更小。 the <li> 's height is determined by the name and the buttons size. <li>的高度取决于名称和按钮的大小。

here is my code: 这是我的代码:

<ul style="width:250px; word-wrap: break-word; overflow:auto; max-height:100px;">
<asp:ListView ID="FriendRequests" runat="server" GroupItemCount="1" OnItemDataBound="FriendRequests_ItemDataBound">
<LayoutTemplate>
<div style="border-bottom:1px solid #33b3b7; font-size:9px;">Friend Requests:</div>
<asp:PlaceHolder ID="groupPlaceHolder" runat="server" />
</LayoutTemplate>
<GroupTemplate>
<li>
<table cellpadding="0" cellspacing="0">
<tr valign="top" >
<asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
</tr>
</table>
</li>
</GroupTemplate>
<ItemTemplate>
<td title='<%# Eval("email") %>'>
<img style="border:1px solid gray"  Width="35px" Height="35px" src='<%# Eval("photo") %>' />
</td>
<td align="center" title='<%# Eval("email") %>'>
<asp:HyperLink ID="Link1" runat="server" CssClass="LinkToUser">
<span style="font-size:14px; text-decoration:underline;"><%# Eval("name") %></span><br />
</asp:HyperLink>
    <asp:Button ID="Accept" Font-Size="9px" runat="server" Text="Accept"/>
    <asp:Button ID="Button2" Font-Size="9px" runat="server" Text="Deny"/>
</td>
</ItemTemplate>
</asp:ListView>

I want that the photo's height will be the height of the <li> and the width to be the same as the height . 我希望照片的高度将是<li>height ,而width应与height相同。

How can i do this? 我怎样才能做到这一点?

*i only know javascript, html and asp.net so in your solution please use those. *我只知道javascript,html和asp.net,因此在您的解决方案中请使用那些。 Thanks for the help 谢谢您的帮助

Give in image style as 输入图像样式为

height:100%;
width:100%;

Check this fiddle . 检查这个小提琴 Though the image is invalid it has the width of the div it is contained in. 尽管图片无效,但图片的宽度为div的宽度。

This will make the image as large as the container is or in other words the image will spread to 100% x 100% of the container. 这将使图像与容器一样大,换句话说,图像将扩展到容器的100%x 100%。

Please let me know if this was helpful. 请告诉我这是否有帮助。

Define 限定

li {
 width:100px;
 height:100px;}

li img {
 width:100%;
 height:100%;}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM