Home >Web Front-end >Layui Tutorial >How to display pictures in layui table

How to display pictures in layui table

angryTom
angryTomOriginal
2019-08-01 09:23:2316243browse

How to display pictures in layui table

The use of layui's tables is still very simple. The layui document is very detailed. The code is directly below.

If you want to know more about layui, You can click: layui tutorial

1, jsp code

<div class="demoTable">
   		<button class="layui-btn" data-type="publish">发布Banner</button>
	</div>
	<table class="layui-hide" id="banner"></table>

2, and then js code

layui.use(&#39;table&#39;, function(){
    var table = layui.table;
		  
	table.render({
	    elem: &#39;#banner&#39;
		,url:&#39;../banner/list&#39;
		,cols: [[
		     {field:&#39;ban_id&#39;,width:20,title: &#39;ID&#39;, sort: true}
	            ,{field:&#39;ban_img&#39;,title: &#39;图片&#39;,templet:&#39;<div><img   src="{{ d.ban_img }}" alt="How to display pictures in layui table" ></div>&#39;}
		    ,{field:&#39;ban_content&#39;, title: &#39;备注&#39;}
		    ,{field:&#39;ban_href&#39;, title: &#39;地址&#39;}
		 ]]
	});
});

Note: What needs to be noted here is that template is added, here is the addition of form elements and other templates. For details, please refer to:

https://www.layui.com/doc/modules/table.html#templet

Among them This d represents the data returned by the server, ban_img is the field name corresponding to the data

This is not enough, the next thing is the key, because at this moment your table looks like this

How to display pictures in layui table

This picture is not fully displayed at all. You can solve it like this

<div class="demoTable">
   		<button class="layui-btn" data-type="publish">发布Banner</button>
	</div>
	<table class="layui-hide" id="banner"></table>
 

You can see that I added the style at the bottom. There is a priority issue here, so it must be It is placed at the bottom, remember! ! !

But the current effect is like this:

How to display pictures in layui table

It seems that the height is better, but what the hell is this width, so I pressed F12

How to display pictures in layui table

So that’s it, layui has such a style defined internally, so without further ado, let’s change it!

<style type="text/css">
.layui-table-cell{
	text-align:center;
	height: auto;
	white-space: normal;
}
.layui-table img{
	max-width:300px
}

After adding the .layui-table img style, everything is done. I just set a fixed size here, you can do whatever you want~

Final effect:

How to display pictures in layui table

The above is the detailed content of How to display pictures in layui table. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn