2014-09-19 41 views
1

其實我懶得問這個問題,因爲這應該是我最基本的東西。但是因爲我仍然無法解決這個問題,所以這對我來說很重要,但我無法幫助它。最小寬度不起作用的CSS樣式

是的,最小寬度也不適合我(也有一些對待有類似的問題)。我已經設置了內聯風格,向左浮動和溢出隱藏或不隱藏。但它仍然不能解決它。在%

<style> 
    div { 
     width:300px; 
     min-width:150px; 
     overflow:hidden; 
     background:yellow; 
     float:left; 
     display:inline; 
    } 
    </style> 

    <body> 

     <div> 
      This/is what I want 
      is/everything in this world beautiful to see for me 
      a/love is more happiness thing than money 
      text/me to say I miss you too 
     </div> 

    </body> 
+1

我認爲你應該檢查:http://stackoverflow.com/questions/8263543/ css-min-width-property-is-not-working – 2014-09-19 07:56:57

+3

如果寬度爲300,則最小寬度150始終爲真。你期望什麼? – 2014-09-19 07:57:49

+0

最小寬度值應該大於寬度。 – Jaison 2014-09-19 07:58:30

回答

1

您的div的寬度設置爲300像素。所以這個div始終是300px寬。將其更改爲 max-width:300px;,它將起作用。

Fiddle

而且現在也沒有必要宣佈floatinline你只需要:

div { 
    max-width:300px; 
    min-width:150px; 
    background:yellow; 
} 
+0

謝謝,夥計。解決了它。 – 2014-09-19 09:17:52

+0

歡迎您:) – 2014-09-19 09:18:23

2
div { 
     width:30%; 
     min-width:150px; 
     overflow:hidden; 
     background:yellow; 
     float:left; 
     display:inline; 
    } 

使用寬度,使最小寬度有效,否則將只需要300像素的設定值

+0

你能給我一個小提琴來證明它有效嗎?我只是不確定你是否嘗試過。它不適用於我。 – 2014-09-19 09:21:05

+0

http://jsfiddle.net/2x7fd12h/ – himanshu 2014-09-19 09:23:04

+0

它將流動到150px,然後在那裏停止 – himanshu 2014-09-19 09:23:37