Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why word-break doesn't work here?

Tags:

css

http://codepen.io/rick-li/pen/oshCb

<div class="wrapper">
  <div class="left"></div>
  <span>lfjaslkjasldjfaljdfaldflasjflasjdfldasfsdafafasdfsdafadsfazxcvzvzxv</span>
</div>
.wrapper{
  width: 400px;
  height: 300px;
  border: solid 1px;
}

.wrapper .left{
  float: left;
  width: 200px;
  height: 200px;
  border: solid 1px;
  background-color: #111111
}

.wrapper span{
  word-wrap: break-word;
}

you will notice the text dropped to the bottom,

if there're spaces exist in the text, it will wrap correct and lies on the wright, so I wonder why the word-wrap: break-word or word-wrap: break-all doesn't work?

like image 511
Rick Li Avatar asked May 14 '26 04:05

Rick Li


2 Answers

You could also use, word-wrap: break-word;

.wrapper .right{
  display: block;
  width:200px;
}
.wrapper .right{
  word-wrap:break-word;
}
like image 69
msapkal Avatar answered May 15 '26 16:05

msapkal


.right should not be inline. Also, assign some width to it.

.wrapper .right{
  display: block;
  width: 200px;
}
.wrapper .right{
  word-break: break-all;
}

DEMO here.

like image 36
codingrose Avatar answered May 15 '26 16:05

codingrose



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!