Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

inline css style width not able to override computed css style's width value

Tags:

html

css

I'm seeing a strange behaviour which i'm not able to figure out.

The webpage that i'm working on has a lot of css styles. So for one of my div's i'm using inline css to make the width as per my requirement (which shows up in the source code just fine). But when i'm inspecting the element in Google Chrome i see that the computed width as slightly less than my value. How do i override the computed value.

Thanks

like image 838
Raja Avatar asked Jan 21 '11 21:01

Raja


People also ask

How do I override a CSS style with inline?

The only way to override inline style is by using ! important keyword beside the CSS rule.

How do you overwrite width in CSS?

The max-width property in CSS is used to set the maximum width of a specified element. The max-width property overrides the width property, but min-width will always override max-width whether followed before or after width in your declaration.

Do inline styles override stylesheets?

Inline styles added to an element (e.g., style="font-weight: bold;" ) always overwrite any normal styles in author stylesheets, and therefore, can be thought of as having the highest specificity.

Can inline element change width?

The height and width of an inline element cannot be set in CSS. You cannot set the height and width of block-level elements in CSS. Inline elements flow left to right, meaning inline elements appear on the same line unless the line wraps or there's an explicit line break ( <br/> )


2 Answers

Try with !important to override any value.

#div {width:500px !important;}
like image 108
midudev Avatar answered Oct 14 '22 15:10

midudev


Could you please provide more sample code. This is not enough information to answer the question properly. As stated by miduga, !important should be enough to override that style.

Are you certain that this element is of the correct display type? Remember that you can't define a width for inline elements.

like image 25
Exelian Avatar answered Oct 14 '22 13:10

Exelian