简体   繁体   English

限制CSS中的文字区域

[英]Restrict text area in css

I tried to restrict the area where I can write text on my website. 我试图限制我可以在网站上写文本的区域。

<div id="header">
<div id="text"> 
     sample text 
</div>
</div>

When I try to write many characters in text , there is no line break when the given space is exceeded. 当我尝试在text写入许多字符时,如果超过给定的空格,则不会出现换行符。

#header
{
 background-color: #fff;
 height: 100px;

}

#text
{
 margin-left: 200px;
 width: 200px;
}

What is my mistake? 我怎么了

Do this way:- 这样做:

#text
{
    margin-left: 200px;
    width: 200px;
    border: 1px solid;
    word-wrap: break-word;  
}​

Refer LIVE DEMO 请参考现场演示

If you are trying to perform word-wrapping, the following will work. 如果您尝试执行自动换行,则可以执行以下操作。

#text{ 
   word-wrap: break-word;      /* Most modern browsers */       
   white-space: pre-wrap;      /* CSS3 */   
   white-space: -moz-pre-wrap; /* Firefox */    
   white-space: -pre-wrap;     /* older versions of Opera */   

}

The word-wrap property isn't limited to newer browsers only. word-wrap属性不仅限于较新的浏览器。 Older browsers seem to support it as well. 较旧的浏览器似乎也支持它。

From the CSS3 draft, 根据CSS3草案,

For legacy reasons, certain experimental CSS properties do not follow this prefixing convention. 由于遗留原因,某些实验性CSS属性未遵循此前缀约定。 Two common examples are the 'word-wrap' and 'text-overflow' properties, which were introduced unprefixed by Microsoft Internet Explorer prior to the introduction of the vendor prefixing policy in CSS2.1 and were subsequently implemented unprefixed by other browsers, creating a dependency on the unprefixed names despite the lack of a W3C spec. 两个常见的示例是'word-wrap'和'text-overflow'属性,它们是由Microsoft Internet Explorer引入的,而不是在CSS2.1中引入供应商前缀策略之前,随后又由其他浏览器实现的,没有创建前缀。尽管缺少W3C规范,但仍依赖未前缀名称。

See article here and w3c reference . 请参阅此处的文章和w3c参考

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

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