简体   繁体   English

即使在CSS中设置了宽度,主体的宽度仍在扩大

[英]Body width is expanding even after setting its width in CSS

I have set word-wrap property and width of the body of a HTML page inside CSS section, like this : 我在CSS部分中设置了word-wrap属性和HTML页面主体的宽度,如下所示:

  body { width: 830px ; word-wrap: break-word;} 

This is working fine if I am writing or copying text inside it means no horizontal scrolling. 如果我在其中写入或复制文本,这表示工作正常,这意味着不进行水平滚动。 Like in the below image : 如下图所示:

在此输入图像描述

But when I am copying a table from MS Word document then It's not working means word wrap is not happening with copied data expanded to the right by crossing the body width. 但是,当我从MS Word文档中复制表格时,则无法正常工作,这意味着自动换行不会发生,因为复制的数据通过跨过正文宽度向右扩展。 Like in the below image : 如下图所示:

在此输入图像描述

How can I enable word wrap or disable the horizontal expansion of data? 如何启用自动换行或禁用数据的水平扩展?

Please help. 请帮忙。

select the table and set a width to the table instead of the body 选择表格并为表格设置宽度,而不是正文

table { width: 95%;  }

Hope that helps. 希望有所帮助。

Don't set the body's width, and you can't enable word wrap because tables don't wrap, all you have to do is to create a new div as a table container, and give it (overflow:auto) see the exemple below 不要设置主体的宽度,也不能启用自动换行,因为表格不会自动换行,您要做的就是创建一个新的div作为表格容器,并为其赋予它(overflow:auto),例如下面

http://codepen.io/anon/pen/dGxQRo http://codepen.io/anon/pen/dGxQRo

 .table_container{
   overflow:auto;
 }
 table{
  border:1px solid #000;
  width:100%;
}
table td{
  border:1px solid #000;
}

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

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