I've use bootstrap in my project, like this below
<div class="input-group">
<input type="text" class="form-control input-lg" autofocus>
<span class="input-group-btn">
<button class="btn btn-primary btn-lg" type="button">search</button>
</span>
</div>
and in Bootstrap, I saw :
.input-group-btn:last-child > .btn {
margin-left: -1px;
}
So I write some CSS to avoid the useless margin-left:-1px; but I still have a problem:
When I click the area outside the <div class="input-group search-bar">, the button still have a effort like margin-left:-1px;
I'm confused, should I write some JavaScript to avoid this?
From the bootstrap source code on Github, these -1px styles are used when having button groups where the buttons align next to each other from doubling the border. If you place 2 buttons with a 1px border next to each other, you create visually a 2px border. The -1px shifts the button over so that the border is not doubled.
Comment from actual github source:
// Prevent double borders when buttons are next to each other
The -1px margin is there to prevent double borders when buttons are next to each other. It's meant to be this way.
If you really need to get rid of this, you may also have to adjust some of the negative margins and/or z-index for .input-group-btn > .btn:hover, :focus, :active, :first-child, and :last-child.
Related
I'm trying to create a Navigation field for my website, and I would like my buttons to be underneath each other with a white line in between. I have managed to get this part working by adding two line breaks next to the button, as seen here:
<button id = "next" onclick="next()">
Volgende
</button><br><br>
I'm wondering if it's possible to have them show up like this, but if I hide the button, have the other buttons jump up, so they fill the gap and jump back down when the button becomes visible again.
Thanks in advance!
Don't use line breaks for layout. That's a misuse of their purpose, which is to break text.
Just put your buttons in block-level (or inline-block level) containers, like divs. Obviously you'd hide and show the containers, not the buttons.
.button-container:not(:first-child) {
border-top: 1px solid red;
padding-top: 4px;
margin-top: 4px;
}
<div id="next-btn-container" class="button-container">
<button id="next" onclick="next()">Volgende</button>
</div>
<div id="other-btn-container" class="button-container">
<button id="other" onclick="next()">Volgende</button>
</div>
<div id="another-btn-container" class="button-container">
<button id="another" onclick="next()">Volgende</button>
</div>
<br> is not a good practice for cross-browser perspective, kindly use the standard way by using margin and display:block property of css.
So your html will be like:
<button class="mb-20px d-block" id = "next" onclick="next()">
Volgende
</button>
And add below line in your css
.mb-20px { margin-bottom: 20px; }
.d-block { display: block; }
I have found how to make it work.
Instead of using
document.getElementById("button").style.visibility = 'hidden'
I have now used
document.getElementById("button").style.display = 'none'
This makes the buttons fill the gaps when they're hidden.
I'm trying to make all my form elements the same height. Normally I'd just set a height on each item and job's a good'n! But the dev's I'm working with are adamant I use padding for the buttons incase they need to wrap so the text doesn't get cut off ...by argument would be that's a problem that needs to be solved as well but anyways...
So I have this CodePen showing all my styles. I've included all the CSS just incase anything is being inherited I've missed. I've managed to get most of them the same height by using the same font-size, padding and line-height.
https://codepen.io/moy/pen/pVeOyQ
The problem is one of the buttons doesn't have a border and everything else does, so it's off by a few pixels. I thought border-box would solve this but obviously not!
I could add a border to that button as well and always make sure it's the same colour as the background - but that's a bit of the pain. Is it the only way though?
I know this is a bit of a minor/simple issue but I just want to get some feedback before making a decision.
I've included the CodePen as I couldn't embed all the CSS as it exceeded the limit. Also I couldn't get all the elements horizontally inline on the embed code as there wasn't enough room.
I could add a border to that button as well and always make sure it's the same colour as the background - but that's a bit of the pain. Is it the only way though?
Instead of that, you could add a transparent border, as shown in the snippet below.
input, select, button {
-ms-box-sizing:content-box;
-moz-box-sizing:content-box;
-webkit-box-sizing:content-box;
box-sizing:content-box;
padding: 15px;
border: 1px solid #1111;
margin: 0;
}
#transparent-border {
border: 1px solid transparent;
}
#no-border {
border: none;
}
<p>How it looks <i>with</i> the transparent border</p>
<input type="text" name="" placeholder="Input field">
<select class="" name="">
<option value="Select">Select field</option>
</select>
<button type="button" name="button">Button</button>
<button id="transparent-border" type="button" name="button">Button with transparent border</button>
<p>How it looks <i>without</i> the transparent border</p>
<button type="button" name="button">Border</button>
<button type="button" id="no-border" name="button">No border</button>
<p>Comparison</p>
<button type="button" id="no-border" name="button">No border</button>
<button id="transparent-border" type="button" name="button">Button with transparent border</button>
How about setting a min-height for all your elements?
Combined with box-sizing: border-box;
Within a div with a non-white background, when I add an input element it gives me this ugly border.
<div class="input-group">
<input type="search" style="height:30px;">
</div>
What can I do to get rid of it?
That is unusual... what browser are you using to view this? Do you have a source page you can show us? I'm wondering whether it's a browser-defined default, or you have some other CSS causing this.
Regardless, there is a simple answer to this: Set your own border.
Like so:
<div class="input-group">
<input type="search" style="height:30px; border: 1px inset grey;">
</div>
You can also use this instead if you want iPhones to render the exact same border too (Apple devices like to style things their own way and this will override that):
<div class="input-group">
<input type="search" style="height:30px; border: 1px inset grey; -webkit-appearance: none;">
</div>
I would still recommend posting a link to a real example (perhaps on jsfiddle.net), just so we can verify what's causing the border issue. There are several possible reasons, though the above code should solve the most common ones.
I have been trying to figure out how I can get input field and a button on the same line inside a table cell without stretching the column too much.
This is what I want to be inline:
<td>
<input type="text" class="input-sm form-control"id="measured_value" name="measured_value" placeholder="Measured value">
<button type="button" class="btn btn-xs btn-primary" onclick="add_measurement();">Submit</button>
</td>
This is what I get:
I have also tried using divs with col-lg-8 and col-lg-4 it did inline them but that in turn stretched the column a lot. It made the column like 1.5 times wider and I am trying to make the table compact.
It seems that form-control is the reason why it wouldn't inline. So I ended up removing form-control and adding this for the borders which came with the form-control.
.input-sm{
border: 1px solid #CCC;
border-radius: 4px;
}
The Easiest way is to make them float. For example:
CSS:
.input_class{
float:left;
}
.btn{
float:left;
}
I am trying to make a button for a message system to show an orange dot if there's a new message. However, i can't quite get it working. Is it possible?
Here's the button
<input type="button" value="Messages •" />
And the button on jsFiddle if anyone feels like trying out :-)
http://jsfiddle.net/ePA47/1/
Use a button element instead.
<button type="button">
Messages <span style="color: orange;">•</span>
</button>
Of course, don't add your stylings inline. I just did for this example's sake.
You could also add a class to the button such as new-messages and then do...
button.new-messages:after {
content: "•";
color: orange;
}
Just keep in mind the latter won't work in older IEs.
Use <button> instead of <input> since it has child elements which you can style.
To add an orange dot to your button, I would recommend using a background-image. This will give you the ability to design the dot however you wish, and not be constrained by font types.
It's also better for accessibility if the orange dot is added as a background image, as this is not content.
<input type="button" value="Messages" class="newmessage" />
.newmessage
{
background-image:url('http://img859.imageshack.us/img859/9611/orangedot.jpg');
background-repeat:no-repeat;
background-position:right center;
padding:5px;
padding-right:25px;
}
See Demo: http://jsfiddle.net/ePA47/3/
As per the question heading, the following will help to add multiple styles in a single style tag
<button type="button" style= "margin-top : 20px; border-radius: 15px"
class="btn btn-primary">View Full Profile
</button>