自适应的两端对齐:text-align:justify

本文介绍了一种实现文本两端对齐的方法,通过CSS样式设置,包括inline-block元素的使用及IE浏览器兼容性处理。文中详细解释了如何通过justify_fix元素解决末行对齐问题,并针对不同版本IE提供了text-justify属性的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 1  
 2 
 3 <!DOCTYPE HTML>
 4 <html>
 5     <head>
 6         <title>文本两端对齐 by hongchenok</title>
 7         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 8         <style>
 9             .box{
10                 width:50%; 
11                 padding:20px; 
12                 margin:20px auto; 
13                 background-color:#f0f3f9; 
14                 text-align:justify;                
15                 text-justify:distribute-all-lines;/*ie6-8*/
16             }
17             .list{
18                 width:120px; 
19                 display:inline-block;
20                 *display: inline; 
21                 *zoom:1;
22                 padding-bottom:20px; 
23                 text-align:center; 
24                 vertical-align:top;
25             }
26             .justify_fix{
27                 display:inline-block; 
28                 *display: inline; 
29                 *zoom:1; width:100%; 
30                 height:0; 
31                 overflow:hidden;
32             }
33 
34             .list_head{
35                 height: 50px;
36                 width: 50px;
37                 background-color: red;
38                 float: left;
39             }
40 
41             .list_content{
42                 width: 70px;
43                 height: 50px;
44                 float: left;
45             }
46             .clearfix:after {
47                 content: "."; 
48                 display: block; 
49                 height: 0; 
50                 clear: both; 
51                 visibility: hidden;
52             }
53             * html .clearfix {height: 1%;}
54         </style>
55 
56     </head>
57     <body>
58         <div class="box">
59             <div class="list clearfix">
60                 <div class="list_head"></div>
61                 <div class="list_content">这是内容</div>
62             </div>
63             <div class="list clearfix">
64                 <div class="list_head"></div>
65                 <div class="list_content">这是内容</div>
66             </div>
67 
68             <span class="justify_fix"></span>
69         </div>
70         <div class="box">
71             <div class="list clearfix">
72                 <div class="list_head"></div>
73                 <div class="list_content">这是内容</div>
74             </div>
75             <div class="list clearfix">
76                 <div class="list_head"></div>
77                 <div class="list_content">这是内容</div>
78             </div>
79             <div class="list clearfix">
80                 <div class="list_head"></div>
81                 <div class="list_content">这是内容</div>
82             </div>
83             <div class="list clearfix">
84                 <div class="list_head"></div>
85                 <div class="list_content">这是内容</div>
86             </div>
87             <span class="justify_fix"></span>
88         </div>
89 
90     </body>
91 </html>

要点:

1. inline-block使用及ie兼容

2. 末行填充justify_fix元素

3. ie兼容:text-justify:distribute-all-lines;

转载于:https://www.cnblogs.com/hongchenok/p/3913596.html

.signature-trace-drawer display: flex; -webkit-box-orient: vertical; -webkit-box-direction: reverse; -webkit-flex-direction: column-reverse; -moz-box-orient: vertical; -moz-box-direction: reverse; -ms-flex-direction: column-reverse; flex-direction: column-reverse; position: fixed; height: 100%; width: 100%; left: 0; top: 0; z-index: 1001; background: rgba(0, 0, 0, 0.5); justify-content: center align-items: center overflow: scroll .signature-trace-content width 100% justify-content: center align-items: center .signature-trace-wrapper-body position relative background: white margin-left 20px margin-right 20px padding 0 20px border-radius: 12px .signature-trace-wrapper-close position: absolute left 50% bottom -50px height 24px width 24px @extends button.close // background: url(../images/close_lt.png) no-repeat center / cover background-size: 20px background-color: white; opacity: 1 border-radius: 100% transform: translate(-50%, -50%) text-align: center color : rgb(166,166,166) span font-size 20px line-height 24px .signature-trace-title font-size: 17px font-weight bold padding-top: 15px margin-bottom: 10px text-align: center color #202020 .signature-trace-image-container background: url('../images/miziGrid.png') no-repeat center/cover; background-size: 100% 100% background-repeat: repeat; position relative aspect-ratio 1 border-radius: 12px; background-color: #F5F5F5; display: flex justify-content: center align-items: center overflow hidden .ps-sign position absolute height 100% min-width 100% aspect-ratio 1 z-index 1002 .canvas height 100% width 100% .signature-trace-spinner display: none width 24px height 24px position: absolute top: 50% left 50% background: url('../images/loading.gif') no-repeat center/cover; transform translate(-50%, -50%) .signature-trace-template-img display: none; width 100% opacity: 0.4; background: no-repeat center/cover; .signature-trace-template-text display: none; justify-content: center align-items: center width: calc(100% - 50px); height: calc(100% - 50px) position: absolute top: 45% left 50% transform: translate(-50%, -50%) opacity: 0.4; .signature-trace-reload-content display: flex align-items: center justify-content: center position: absolute top: 50% left 50% transform: translate(-50%, -50%) .signature-trace-reload font-size 14px color #808080 white-space: nowrap; span color #808080 .signature-trace-button display: flex; justify-content: space-between; align-items: center; margin: 20px 20px 0 padding-bottom: 20px .signature-trace-resetting font-size 14px flex-grow:1; width 100px height 36px line-height 36px text-align: center background: #F5F5F5; margin-right: 10px border-radius: 16px color #202020 opacity: 0.3; .signature-trace-determine font-size 14px background-color: #ED5151 flex-grow:1; height 36px; width 100px line-height 36px text-align: center color #FFFFFF border-radius: 16px opacity: 0.3; .signature-trace-determine.center-block height 35px width 182px flex-grow 0 position relative left 50% transform translateX(-50%) @media only screen and (min-device-aspect-ratio:3/4) .signature-trace-drawer .signature-trace-content .signature-trace-wrapper-body margin-left 60px margin-right 60px .signature-trace-title font-size 12px 如上的样式,我在特别宽的屏幕上打开比如说平板上,signature-trace-wrapper-body就会变的很大,导致他的子元素signature-trace-wrapper-close关闭按钮看不到,signature-trace-button按钮区域也在屏幕上看不到,滚动也滚动不了,应该如何解决呢?能让这个signature-trace-content这个元素及其子元素整个展示在页面中自适应,宽高比例不变吗?应该如何修改呢
05-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值