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.
Related
I am using bootstrap for layout. I have set max-width on the input control to 280px. But this causing input-group-addon not render properly when i use bootstrap's grid column size larger than 280px. input-group-addon does not stick with the control.
I have JSFiddle here
I guess input-group-addon always renders to the right of the column so there is a space between input control and addon.
How do i fix this without messing with max-width and col.
In your fiddle an .input-group-addon has width 32px, and both of .form-control (max-width: 280px;)and .input-group-addon (width: 32px) are included in the .input-group, then you just need to define max-width for .input-group:
.input-group {
max-width: 312px;
}
jsfiddle
I would NOT recommend to set the width of max-width of your inputs (or any other element), within Bootstrap.
Bootstrap elements are designed to fill all the available space. They can be made responsive very easily by using the built-in grid system. My recommendation is to limit their width by limiting the width of their container, like this:
<div class="row">
<div class="col-xs-6"><!-- NOTE THE 'XS' HERE -->
<div class="input-group">
<input name="FirstName" class="form-control" id="FirstName" type="text" value="399035034">
<span class="input-group-addon">+</span>
</div>
</div>
</div>
https://jsfiddle.net/v85wzajr/2/
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.
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.
I'm trying to implement the following scenario, using Twitter Bootstrap and Fluid Layout :
Left sidebar (I don't care whether the width is fixed or not) - occupying the WHOLE HEIGHT (no margins at all, like the sidebar in jsfiddle.net)
The rightmost part of the content, will occupy the remaining part of the window (fluid)
I've tried setting it up like that, but it definitely doesn't work (there are margins everywhere and the columns definitely don't occupy all of the vertical space) :
<div class="container-fluid" style="">
<div class="row-fluid" style="">
<div class="span3" style="">
</div>
<div class="span9" style='background:#fff;'>
</div>
</div>
</div>
Any ideas? How would you go about this?
Not totally sure but I think this might work...
Put height:100% on the html and body elements of your page.
Then give the element that you want to be the full height of the page a min-height:100%
Hope that helps.
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.