看一下链接。它的父元素中的p元素具有更多宽度。我想在对话框中显示p。怎么做?
.dialog-box {
margin:0 auto;
width:300px;
height:200px;
background-color:#326A16;
-webkit-filter:drop-shadow(0px 0px 5px #000000);
border-radius:20%/34%;
}
.dialog-box:before {
content:"";
position: absolute;
width: 0px;
height: 0px;
border-right: 21px solid transparent;
border-left: 18px solid transparent;
border-top: 42px solid #326A16;
margin:195.71428571428572px 90px;
}
.dialog-box p {
display:inline;
margin:10% 14%;
text-wrap:normal;
}
答案 0 :(得分:3)
更新.dialog-box
:
.dialog-box p {
display: block;
margin:10% 14%;
width: 200px;
word-wrap: wrap;
word-break: break-all;
padding-top: 30px;
}
这里要做的3件事:
display: inline
不适用于您的情况;你必须使用宽度& p
元素的高度word-wrap
和word-break
padding-top
旁注:
没有必要设置带有这么多小数位的边距。仅使用整数。
答案 1 :(得分:2)
之所以发生这种情况是因为你放入了没有任何空格的文本,因此浏览器不确定如何打破这些长线。您可以使用word-wrap
属性
.dialog-box {
/* ... */
word-wrap: break-word;
}
答案 2 :(得分:0)
尝试此操作我将p
更改为block
元素并为其指定宽度
.dialog-box {
margin:0 auto;
width:300px;
height:200px;
background-color:#326A16;
-webkit-filter:drop-shadow(0px 0px 5px #000000);
border-radius:20%/34%;
}
.dialog-box:before {
content:"";
position: absolute;
width: 0px;
height: 0px;
border-right: 21px solid transparent;
border-left: 18px solid transparent;
border-top: 42px solid #326A16;
margin:195.71428571428572px 90px;
}
.dialog-box p {
display:inline-block;
width:260px;
margin:20px;
text-wrap:normal;
word-break:break-all;
}
<div class="dialog-box">
<p>hi there?kjhkjhkgygyfyjfffhjvhvvjhjassasasasa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa c c vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv</p>
</div>
答案 3 :(得分:0)
请尝试以下操作: Demo
CSS:
.dialog-box p {
display:block;
margin:10% 14%;
width:80%;
word-wrap: break-word;
}
答案 4 :(得分:0)
.dialog-box p {
display: block;
height: 180px;
margin: 10% 14%;
overflow: hidden;
word-wrap: break-word;
}
答案 5 :(得分:0)
使用此
dialog-box p {
margin: 10% 10%;
padding: 13px 0px 0px 0px;
word-wrap: break-word;
}
答案 6 :(得分:0)
的jsfiddle
http://jsfiddle.net/2y1wj0mm/4/
.dialog-box p {
//you can use inline-block also but you need to adjust the margin and padding
display:block;
margin:10%;
width:80%;
word-wrap: break-word;
padding:5%;
}
默认情况下,p是块级元素。所以默认css将在这里应用 所以你不能用作内联元素