Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

not able to do max width

Tags:

css

I have a page which has a content like this...

<div id="content">
testingtestingtestingtestingtestingtestingtestingtestingtesting
testingtestingtestingtestingtestingtestingtestingtesting
testingtestingtestingtestingtesting
</div>

How do i apply a max-width on it . I m using this code in the css

#content {
    max-width:50px; /* for standards-compliant browsers */
   /*width:expression(document.body.clientwidth > 650? "650px": "auto" );*/ 
   /* max-width expression for IE only */
}

but i m not getting the results in firefox... http://pradyut.dyndns.org/WebApplicationSecurity/width.jsp

Are there any JavaScript solutions?
Any help
thanks
Pradyut

like image 339
Pradyut Bhattacharya Avatar asked Mar 24 '10 20:03

Pradyut Bhattacharya


People also ask

Can we give width more than 100%?

Yes, as per the CSS 2.1 Specification, all non-negative values are valid for width, that includes percentage values above 100%. Show activity on this post. Percentage values simply represent a percentage of the length of the element's container.

How do I force a div to full width?

What you could do is set your div to be position: absolute so your div is independent of the rest of the layout. Then say width: 100% to have it fill the screen width. Now just use margin-left: 30px (or whatever px you need) and you should be done.

Can Max-Width be a percentage?

Setting max-widthThe max-width can be specified in length values, like px, cm, etc., or in percent (%) of the containing block, or set to none (this is default. Means that there is no maximum width).


3 Answers

Well the reason why you not getting the expected result on the page you provided by the link is that you are using a span instead of a div.

Add

display: block;

to you style.

like image 70
AxelEckenberger Avatar answered Oct 06 '22 23:10

AxelEckenberger


So, in your CSS, you can set the word-wrap property to break-word so that your string of text (w/ no whitespace) will be made to fit into the max-width:

E.g.

<style type="text/css">

#content {
    max-width: 50px;
    word-wrap: break-word;
}

</style>
like image 36
kafuchau Avatar answered Oct 07 '22 00:10

kafuchau


#content {
    max-width: 50px;
    display: inline-block;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

You may like to remove display: inline-block; depending on the context of your element.

like image 27
ekerner Avatar answered Oct 06 '22 23:10

ekerner