简体   繁体   English

word-wrap属性在CSS中似乎不起作用

[英]The word-wrap property does not seem to work in CSS

I have designed an html iframe where I want to use the word-wrap property, ie, it should break long words onto the next line. 我设计了一个html iframe,我想在其中使用word-wrap属性,即,它应该将长单词分解为下一行。 But what happens instead is that for long words, it adds a horizontal scroll-bar rather than breaking the word onto the next line. 但是,发生的是,对于长单词,它添加了一个水平滚动条,而不是将单词拆分到下一行。

I tried hiding the scroll bar by using "overflow:hidden" property , but nothing happens. 我尝试使用“ overflow:hidden”属性隐藏滚动条,但是什么也没有发生。

I could use some help here. 我可以在这里使用一些帮助。

Here's the html code for iframe: 这是iframe的html代码:

<div id="main_frame" >
<iframe id="main_frame" src="homedept.php" name="iframe_a"></iframe>
</div>

The CSS is: CSS是:

div#main_frame
{
 float: left;
margin-top:198px;
margin-left:5px;
float:left;
position:relative;
width:100%;
height:900px;
z-index: 0;
word-wrap:break-word;
}

iframe#main_frame
{
float:left;
margin-left: 30px;
margin-right: 300px;
float:left;
border:none;
word-wrap:break-word;
width: 78%;
height:70%;
z-index: 1;

}

Thanks for the reply @tyriar, I have set the word-wrap property to the original page now. 感谢@tyriar的回复,我现在将word-wrap属性设置为原始页面。 Still nothing happens. 仍然没有任何反应。

<div id="display_posts">


<?php //php echoes some text here ?>

</div>

The CSS code is: CSS代码为:

#display_posts
{
word-wrap:break-word;
}

You can't apply word-wrap to an iframe , it's a completely separate page and styles from your original page won't apply. 您无法将word-wrap应用于iframe ,这是一个完全独立的页面,与原始页面的样式将不适用。 You would need to change the styles on the page where the iframe points. 您需要在iframe指向的页面上更改样式。

Also id attributes must be unique, you have set id="main_frame" on both an iframe and a div . 同样, id属性必须唯一,您在iframediv上都设置了id="main_frame"

Update 更新资料

If word-wrap:break-all is on the iframe then maybe the width of the page is introducing the scroll bar. 如果word-wrap:break-all位于iframe上,则页面的宽度可能正在引入滚动条。 Make sure that your elements scale down correctly with the page. 确保您的元素随页面正确缩小。 If you load up the page in your iframe in your browser you should be able to reduce the window size without a horizontal scroll bar appearing. 如果您在浏览器中的iframe中加载页面,则应该能够减小窗口大小而不会出现水平滚动条。 If one does then it's an issue with the minimum width of that page. 如果这样做的话,那是该页面最小宽度的问题。

You defined same ID 2 times , but ID must be unique , you can not declare it twice. 您定义了ID 2 times相同的ID 2 times ,但ID必须是unique ,不能两次声明。

So use class instead of using ID 因此,请使用class而不是ID

Also iframe call other page and you defined word-wrap in original page so its not apply. iframe还会调用其他页面,并且您在原始页面中定义了word-wrap ,因此该设置不适用。

Try 尝试

word-break:break-word

or 要么

word-break:break-all

And try using class instead of ID because ID should be unique. 并尝试使用类而不是ID,因为ID应该是唯一的。

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

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