westman Posted October 18, 2013 Share Posted October 18, 2013 (edited) hi all, I am trying to let the text in a div set the div width. I have tried... width: 300px; width:auto; and max-width: 300px; min-width: 300px; but it is not working. any help? Edited October 18, 2013 by westman Link to comment Share on other sites More sharing options...
dsonesuk Posted October 18, 2013 Share Posted October 18, 2013 div is block element it will stretch to width available to it, for it to stretch to content width only, float, display: inline or inline-block should be used. Link to comment Share on other sites More sharing options...
davej Posted October 18, 2013 Share Posted October 18, 2013 I am trying to let the text in a div set the div width. Text won't set a div width. It can only affect a div height. Link to comment Share on other sites More sharing options...
Hadien Posted October 19, 2013 Share Posted October 19, 2013 not only text, but any inline element will ignore the width/height you give them (style:width/height that is, things like img are different), and they set their dimensions to what it think it needs. if you want an inline element to have a say in what it's width is, you switch their display to inline-block. inline-block will act in almost every way a character in a group of text will, but will also have access to properties like width/height. Link to comment Share on other sites More sharing options...
westman Posted October 19, 2013 Author Share Posted October 19, 2013 Dsonesuk thank you display: inline; display: inline-block; works very well Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now