0

I have following structure: JSFiddle Demo

enter image description here

HTML & CSS Code is as following:

HTML:

<ul>
    <li class="test"> Hello </li>  
    <li class="test"> Welcome </li>
    <li class="test"> Test Process </li>
    <li class="test"> Text Message </li>
</ul>

CSS

ul{

    width: 100%;
}

.test{
    height:20px;
    width:20%;
    border: 1px solid black;
    border-radius: 3px;
    display: inline-block;
    float: left;
    margin-left: 5px;
    text-align: center;
}

When I resize the browser the <li> tag widget structure is working fine (Not breaking) but the text inside the widget are breaking like:

enter image description here

My question is How can I make the text inside the widget adjustable so that It will not break. Is there any way to fix this using only CSS ?

Vaibhav Jain
  • 3,729
  • 3
  • 25
  • 42

5 Answers5

2

Provide

min-width:20%;

instead of

width:20%;

It should work..

Fiddle: http://jsfiddle.net/ZZa8j/2/

Deepu Sasidharan
  • 5,193
  • 10
  • 40
  • 97
  • +1 for the answer. Yes, This approach is working but My box structure is also change while resizing the browser i.e. the size of box,text containing Hello is become small comparing with the others so not consistance. :) – Vaibhav Jain Jul 14 '14 at 11:26
  • li only have 20% width of ul. As ul's width decreases width of li also decreases.If you provide fixed width (in px), i think this problem can avoid. – Deepu Sasidharan Jul 14 '14 at 11:35
  • Ok. Thanks. Let me check with this approach using pixels. – Vaibhav Jain Jul 14 '14 at 11:38
2

If you want it to expand accordingly, you can simply remove the explicit height and set a min-height like this.

If you want to clip the text and indicate the user that text is clipped, you can use the text-oveflow property like this.

.test{
 white-space:nowrap;
 overflow:hidden;
 text-overflow:ellipsis;
 /*other styles*/
}

If you actually want the content to expand as much as possible and scoll if not, you could use Paulie_D's table-cell approach like he mentioned in comments.

Community
  • 1
  • 1
T J
  • 42,762
  • 13
  • 83
  • 138
1

Your images are blocked by my proxy so I'm not sure if it's the answer that you need, but you can avoid break between 2 words with the css property white-space.

white-space:nowrap;

see fiddle : http://jsfiddle.net/ZZa8j/4/

ylerjen
  • 4,109
  • 2
  • 25
  • 43
1

add min-width:450px; to the <ul>.

check my Fiddle Demo

CSS

ul{
    min-width:450px;
    width: 100%;
}

.test{
    height:20px;
    width:20%;
    border: 1px solid black;
    border-radius: 3px;
    display: inline-block;
    float: left;
    margin-left: 5px;
    text-align: center;

}

HTML

<ul>
    <li class="test"> Hello </li>
    <li class="test"> Welcome </li>
    <li class="test"> Test Process </li>
    <li class="test"> Text Message </li>
</ul>
Ronen Cypis
  • 21,182
  • 1
  • 20
  • 25
1

Result

Code Demo

Try :

overflow: hidden;
 min-width:100px; 

Result Screenshot

user63762453
  • 1,734
  • 2
  • 22
  • 44