简体   繁体   中英

Why is my width at 100%?

http://geodit.com:8000/d/4

If you go this site, you'll see that $("#coreimage") is set to width:auto.

However, for some reason, it doesn't maintain the width of the cheerios box (Instead, it's 100%...)

coreimage is a div , which is a block element. Block elements, by default, take the full available width, unless you explicitly set the width (to a value other than auto ), or float the element.

I'm not sure what you want the end result to be, but you can either change the element to an inline element (ie span ) or specify float: left on your element.

I'm not totally sure what you're going for. You want #coreimage to be the width of its containing image? That's not how block level elements work. A div (or any block level element) will automatically expand to fit its parent unless you specify a width, whereas an inline element (ie span) only takes up the space it needs (ie. you can't specify a width on an inline element, it expands to its children)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM