Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset a block element's width

Tags:

css

I have a problem using a given CSS file I don't want to change. In this file there is a format for inputs:

input {
  display:inline-block;
  width:60%;
}

Now I want to use an additional CSS file and change this formatting to a normal block element width full width:

input {
  display:block !important;
  width:auto !important;
}

Unfortunately, this doesn't work. Unlike normal block elements, the input does not take all the available horizontal space with this setting. It is only as long as it would be as inline element. Additionally, I cannot use width:100%; due to padding, borders and margin. In my desperation I already tried something like width:none;, but I couldn't find a way to reset the width to a block element's default value.

I really hope that somebody can help me. Thank you in advance.

like image 916
Sebastian vom Meer Avatar asked Aug 06 '11 15:08

Sebastian vom Meer


People also ask

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.

What is the default width of block elements?

The default width of a block-level element is the length of the page.

How do I reset the min-width?

CSS tip: To reset a min-height or min-width declaration, set it to "0", not "auto". For max-height/width, the initial value is "none". Also see nimbupani.com/safe-css-defau… Just used this to solve resetting width on #mobileFirst breakpoints!

How to clear a CSS style?

Answer: Use the CSS all Property You can simply use the CSS all property with the value revert to remove the additional author-defined CSS styling for an element (i.e. reset to browser's default CSS styling).


1 Answers

You must use width: 100%, so my answer shows how to fix the problems you're having with it.

https://developer.mozilla.org/en/CSS/box-sizing

input {
    width: 100%;
    margin: 0;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
}

If margin is required, then wrap the input in another element and apply the margin to that.

like image 77
thirtydot Avatar answered Oct 12 '22 08:10

thirtydot