方法如下:
1)图片及图片说明代码如下:
<table class="mod_img">
Home Web Front-end JS Tutorial Implementing text adaptive image width in CSS Table image and text mixing (super simple, crosses all browsers)_javascript skills

Implementing text adaptive image width in CSS Table image and text mixing (super simple, crosses all browsers)_javascript skills

May 16, 2016 pm 06:56 PM
css table

This creates a problem. If the picture is too small, or the text is too long, the text will stretch out the entire table, which takes up a lot of space and the display effect is very unsightly.
There are many solutions on the Internet, but they are either complicated, cannot solve cross-browser issues, or cannot adapt to changes in image size.
In my method, I solved: No need to specify the image size in the code, cross-browser, very simple. The final effect is shown in the picture below. When the text is too long, it will automatically wrap to fit the width of the picture:
基于表格的图文混排
The method is as follows:
1) The picture and picture description code are as follows:

Implementing text adaptive image width in CSS Table image and text mixing (super simple, crosses all browsers)_javascript skills
香港殖民地最后的一面旗帜,由英国蓝旗和代表香港的殖民地徽所组成,1959年-1997年
2) "mod_img" is defined as follows, which specifies the CSS style of the table and image borders:
.mod_img {margin:6px; border:1px solid #AAAAAA; padding: 3px; }
.mod_img img{margin:3px; border:1px solid #AAAAAA; padding:0px; }
3) "mod_img_desc" is defined as follows, which specifies the CSS style of the description text:
.mod_img_desc {font-size:12px ;word-break:break-all;width:100%; overflow:auto;}
The key here is the width="10" above. This is the key to the text adaptive image width. In fact, 10 is a A very small value. Generally, pictures are larger than this value. When a picture is displayed in a table, the picture will expand the table according to its actual size. Therefore, this width will not affect the display of the picture. However, in 3) The width of the text is specified as 100%, which means that the text is displayed according to the actual width, regardless of the width. When the text exceeds the width, it will automatically wrap.
After testing, this method can work perfectly in IE/Firefox/Safari/Opera and other browsers! Have a nice day.
Statement of this Website
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What does placeholder mean in vue What does placeholder mean in vue May 07, 2024 am 09:57 AM

What does placeholder mean in vue

How to write spaces in vue How to write spaces in vue Apr 30, 2024 am 05:42 AM

How to write spaces in vue

How to get dom in vue How to get dom in vue Apr 30, 2024 am 05:36 AM

How to get dom in vue

What does span mean in js What does span mean in js May 06, 2024 am 11:42 AM

What does span mean in js

What does rem mean in js What does rem mean in js May 06, 2024 am 11:30 AM

What does rem mean in js

How to introduce images into vue How to introduce images into vue May 02, 2024 pm 10:48 PM

How to introduce images into vue

What is the function of span tag What is the function of span tag Apr 30, 2024 pm 01:54 PM

What is the function of span tag

What language is the browser plug-in written in? What language is the browser plug-in written in? May 08, 2024 pm 09:36 PM

What language is the browser plug-in written in?

See all articles