Home  >  Article  >  Web Front-end  >  Problem with underline alignment in Chinese and English fonts under IE

Problem with underline alignment in Chinese and English fonts under IE

巴扎黑
巴扎黑Original
2017-08-21 12:01:581473browse
First describe the problem: As shown in the picture, when a line of text contains both English and Chinese under IE, the link underline will break, which means that the Chinese and English are not aligned at this time! (FIREFOX is not affected by this problem)

Problem with underline alignment in Chinese and English fonts under IE

However, after testing, this situation will not occur when the link is set directly on the page by default!

Code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head> 
  <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> 
  <title>php中文网</title> 
  <style type="text/css">
   * { 
          margin:0; 
          padding:0; 
      } 
   html { 
   background:#fff; 
   } 
   body { 
   position:relative; 
   font:12px/1.6em Verdana, Lucida, Arial, Helvetica, 宋体,sans-serif; 
   color:#333; 
   } 
   </style> 
 </head> 
 <body> 
  <div> 
   <a href="http://www.php.cn" id="aa" title="php中文网"><img src="http://i.mtime.cn/20080731114455/images/logo_main.png" 
   style="vertical-align:middle;" alt="php中文网" />
   </a> 
   <a href="">为什么我老是对不齐呢?why??</a> 
  </div>  
 </body>
</html>

Problem with underline alignment in Chinese and English fonts under IE

Then the doubt comes again, what causes the deviation between Chinese and English? ! What's the solution? ! So after my testing, I found two situations (of course there may be more causing situations. You can try it yourself). The adjacent elements of the Chinese and English objects have the vertical-align attribute setting (such as the previous small picture, or the text box , we need to align them vertically. Generally, when we set vertical-align:middle; for pictures and text boxes (any other inline block elements)), it will affect the misalignment of Chinese and English.

Another situation is that when the parent element (except the table) has the vertical-align attribute set, the Chinese and English of the child elements inside will not be aligned.

Code

##
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head> 
  <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> 
  <title>php中文网</title> 
  <style type="text/css">
   * { margin:0; padding:0; } 
   html { background:#fff; } 
   body { position:relative; font:12px/1.6em Verdana, Lucida, Arial, Helvetica, 宋体,sans-serif; color:#333; } 
   </style> 
 </head> 
 <body> 
  <div style="vertical-align:middle;"> 
   <a href="http://www.php.cn" id="aa" title="php中文网"><img src="http://i.mtime.cn/20080731114455/images/logo_main.png" alt="php中文网" /></a> 
   <a href="">为什么我老是对不齐呢?why??</a> 
  </div>  
 </body>
</html>
How to solve this problem? !
Let’s talk about the first one, which is the solution to the deviation problem that cannot be aligned due to the vertical-middle of adjacent elements: Add a zoom:1 to the Chinese and English objects to trigger its haslayout. Through research, we found that once it has a haslayout, There will be no misalignment between Chinese and English.

Code box


##
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head> 
  <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> 
  <title>php中文网</title> 
  <style type="text/css"> * { margin:0; padding:0; } html { background:#fff; } body { position:relative; font:12px/1.6em Verdana, Lucida, Arial, Helvetica, 宋体,sans-serif; color:#333; } </style> 
 </head> 
 <body> 
  <div> 
   <a href="http://www.php.cn" id="aa" title="php中文网">
   <img src="http://i.mtime.cn/20080731114455/images/logo_main.png"   style="max-width:90%" alt="php中文网" /></a> 
   <a href="" style="zoom:1;">为什么我老是对不齐呢?why??</a> 
  </div>  
 </body>
</html>
The second case is The solution to the misalignment problem caused by the vertical-middle of the parent element: Add the sentence vertical-align:baseline to the Chinese and English objects to solve the problem!

Code box


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head> 
  <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> 
  <title>php中文网</title> 
  <style type="text/css"> * { margin:0; padding:0; } html { background:#fff; } body { position:relative; font:12px/1.6em Verdana, Lucida, Arial, Helvetica, 宋体,sans-serif; color:#333; } </style> 
 </head> 
 <body> 
  <div style="vertical-align:middle;"> 
   <a href="http://www.php.cn" id="aa" title="php中文网"><img src="http://i.mtime.cn/20080731114455/images/logo_main.png" alt="php中文网" /></a> 
   <a href="" style="vertical-align:baseline;">为什么我老是对不齐呢?why??</a> 
  </div>  
 </body>
</html>
But we can see that the underline looks like If it is too tight, we still need to add zoom:1; to trigger its hasLayout to avoid being too tight!
Code box


##
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head> 
  <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> 
  <title>php中文网</title> 
  <style type="text/css"> * { margin:0; padding:0; } html { background:#fff; } body { position:relative; font:12px/1.6em Verdana, Lucida, Arial, Helvetica, 宋体,sans-serif; color:#333; } </style> 
 </head> 
 <body> 
  <div style="vertical-align:middle;"> 
   <a href="http://www.php.cn" id="aa" title="php中文网"><img src="http://i.mtime.cn/20080731114455/images/logo_main.png" alt="php中文网" /></a> 
   <a href="" style="zoom:1; vertical-align:baseline;">为什么我老是对不齐呢?why??</a> 
  </div>  
 </body>
</html>
If you encounter other situations, is it correct in Chinese and English? If the situation is uneven, you can also try to use the above two methods to solve the problem. Of course, the safest and most effective thing is to use Song font in both Chinese and English.

-->

The above is the detailed content of Problem with underline alignment in Chinese and English fonts under IE. 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