Cannot Resize DIV to anything smaller than maximum width - css

Quick CSS Question. I cannot seem to figure out a very simple CSS/HTML problem. Here's a JSFiddle.
http://jsfiddle.net/BmM6t/
Basically, these two divs are not resizing to anything less than 100% width:
<div id="main_pic" class="main_div">
THIS IS WHERE THE MAIN PIC WILL GO.
</div>
<div id="signin" class="main_div">
SIGN IN TO THE SITE!
<form>
<label for="name">EMAIL/USERNAME:</label>
<input type="text" name="name" id="name">
<label for="email">PASSWORD:</label>
<input type="text" name="email" id="email">
<br />
<input type="submit" value="Let's Play!">
</form>
</div>
You'll see that the two divs with class main_div actually take up the entire width of the screen for some reason (you can see that if you inspect the element) even though their widths are clearly written. When you try to change the width of one of the main_div's it changes the width but if you inspect the element, it just changes the width of the object and adds padding around it to make sure it still takes up the entire width of the screen.
I'm sure it's some little error I've made but I can't find it. Thanks for the help!

That's how divs work, they are block level elements. If you don't want them to take up the entire with of its container element you can float it or make it inline-block

Use a overflow: hidden; to the .main_div so that you can see that it is resizing but not hiding the contents.

Related

Textarea max-width got no respect

The textarea in this codepen and the code below overflows in slim viewports. It has max-width: 100% from .preset-box but when the textarea is larger than the viewport it causes the viewport to overflow horizontally. I tried both changing and removing cols both to no avail. I tried restricting the resize to vertical and that had no effect on this issue either. How can I adjust the CSS to respect max-width?
<label class="preset-box block-table font-os">
<span class="preset-box block-table" data-spacing="mb1">Ask</span>
<textarea aria-invalid="false" class="preset-textarea p1 pl2 pr2 font-textarea round-medium border-1px border-solid" cols="100" rows="4" data-spacing="mb1 mb0-last">Am I overflowing?</textarea>
</label>
Remove this class:
block-table
max-width applies to block elements only, but block-table makes these table elements.

Bootstrap input-append overflows in small containers

It appears that it's awkward if you need a fluid-width text field with an add-on in Bootstrap 2.3.2.
If the containing div becomes smaller than the input field, an input with a span12 class on it will resize quite happily.
However, doing the same to this snippet is a bit more difficult
<div class="input-append">
<input type="text">
<span class="add-on">Sheep</span>
</div>
Does anyone have a solution to this?
Here's a fiddle: http://jsfiddle.net/KFr2z/149/
If you have input alone it is very easy to expand it to fit parent. It is also easy for more than one element if other has % width. Problem become if you have more than one element and other elements has fixed width or no explicitly determined width at all. Then you need an element which fit all parent's remaining space. From what I know it is impossible to make input to behave that way. But any native block-level element enclosing input should do the trick:
<div class="input-append">
<span class="add-on" style="float: right;">Sheep</span>
<div style="overflow: hidden;">
<input type="text" class="span12">
</div>
</div>
Bootstrap use some styles based on childs' order so you should also setborder-radius: 0 3px 3px 0 because it doesn't apply to add-on any more.

Alignment of <input type="submit"> in Chrome changes if value=""

I have a simple HTML form with only two elements -- a text box and a submit button -- that need to be horizontally aligned.
The button has a background image, and I would like to set its value="".
In Safari and Firefox, the alignment is maintained if I set the line-height on the elements.
In Chrome, however, this is not enough. I have to set the value=" " (note the space), or give it another text value. Otherwise, the elements shift.
This is the HTML and css
<form>
<input type="text" id="email" class="textBox" />
<input type="submit" id="submitSubscribe" class="submitButton" value="" />
</form>
.submitButton{
width:30px;
line-height:30px;
background:url('');
}
.textBox{
line-height:30px;
}
#email{
width:146px;
}
Here is my jsfiddle:
http://jsfiddle.net/EmCQJ/5/
Does anybody know why Chrome calculates the alignment differently with the text in the value attribute than when the value is blank? Leaving that space in the value feels like a hack solution to me, but I've tried all the obvious css fixes and still can't get it working. Any input is greatly appreciated. Thanks!
This should do it: http://jsfiddle.net/EmCQJ/38/
The key here was
vertical-align: text-top;
It seems the input-text and input-image elements have different baselines (the default setting for vertical-align) but the same text-top line.
You should manually set the margin, padding, and border of the input-text element because different browsers have different defaults. When doing this, remember height is the size of the element less the margin, padding, and border so if you want a total height of 30px make sure to subtract 1px from the top and 1px from the bottom giving you a CSS height of 28px.

Why doesn't div start after previous div?

I'm modifying the header portion of a WordPress theme and I'm trying to nest a couple divs within another div. I'm not very experienced with HTML/CSS, but what I'm observing seems weird to me.
My code looks like this:
<div class="extras">
<div id="search">
<form role="search" method="get" id="searchform" action="http://mentatescholars.com/" >
<input type="search" placeholder="Search" value="" name="s" id="s" />
<input type="submit" id="searchsubmit" value="Search" />
</form>
</div><!-- end #search -->
<div class="phone-number">
<div class="phone-number-main">1-885-MENTATE</div>
<div class="phone-number-sub">1-885-636-8283</div>
</div>
</div>
And in the picture I have the phone-number div selected with Firefox's inspector (selecting extras looks the same). What strikes me as odd is why it's starting at the top of the extras div and not after the search div. search even has a set height of 40px.
If I select the third div, then the it shows the div starting right after the previous div.
What also strikes me as odd is how, while the top of the phone-number-main div is flush with extras, the text shifts down perfectly without me doing anything.
My question is this: How can I make it so that the phone-number div starts right after the search div?
Here's the site, if you want to look at it: http://mentatescholars.com/.
#search is floated and the .phone-number isn't.
If you add clear:both to the .phone-number <div /> you will see the correct layout.
float removes elements from the flow of the document. Check uot this link for more info: http://www.alistapart.com/articles/css-floats-101/
that is because you have floated element. your "search" div is floated and has no clear. Use clear:both in the CSS of the phone-number element and it will work fine
And if you want the number to be right after search make the height of search 30px and get rid of the submit button's margin bottom.
make #search block smaller by reducing height, lets say to 30px.

How to center an item that has a variable width?

I'd like to center a submit button. How do I accomplish this? I dont know the width of the button, it may be flexible based on the text inside it. I'm trying not to use float and set the margin auto on it because that will require a width.
<input type="submit" value="may vary" />
If the width is variable, your best bet is to use the text-align property of the container. If that would effect other sibling elements in an undesirable way, consider wrapping the input in a div.
<div style="text-align: center">
<input type="submit" value="may vary" />
</div>
NOTE: The inline CSS above is just an example, feel free to create a css rule for the div.

Resources