I want to display 3 buttons on the same line in html. I tried two options:
This one:
<div style="width:500px;">
<div style="float: left; width: 130px"><button type="submit" class="msgBtn" onClick="return false;" >Save</button></div>
<div style ="float: none; width: 130px"><button type="submit" class="msgBtn2" onClick="return false;">Publish</button></div>
<div style ="float: right; width: 130px"><button class="msgBtnBack">Back</button></div>
</div>
And this one:
<p style="float: left; width: 130px"><button type="submit" class="msgBtn" onClick="return false;" >Save</button></p>
<p style ="float: none; width: 130px"><button type="submit" class="msgBtn2" onClick="return false;">Publish</button></p>
<p style ="float: right; width: 130px"><button class="msgBtnBack">Back</button></p>
For the second option I used a styling for the paragraph:
<style>
p {display:inline}
</style>
Sadly, none of them were ok, and I can't seem to find out any other option. The first and second button are displayed on same line, but the third is displayed lower...
Can you help me?
Here is the Answer
CSS
#outer
{
width:100%;
text-align: center;
}
.inner
{
display: inline-block;
}
HTML
<div id="outer">
<div class="inner"><button type="submit" class="msgBtn" onClick="return false;" >Save</button></div>
<div class="inner"><button type="submit" class="msgBtn2" onClick="return false;">Publish</button></div>
<div class="inner"><button class="msgBtnBack">Back</button></div>
</div>
Fiddle
Do something like this,
HTML :
<div style="width:500px;">
<button type="submit" class="msgBtn" onClick="return false;" >Save</button>
<button type="submit" class="msgBtn2" onClick="return false;">Publish</button>
<button class="msgBtnBack">Back</button>
</div>
CSS :
div button{
display:inline-block;
}
Fiddle Demo
Or
HTML :
<div style="width:500px;" id="container">
<div><button type="submit" class="msgBtn" onClick="return false;" >Save</button></div>
<div><button type="submit" class="msgBtn2" onClick="return false;">Publish</button></div>
<div><button class="msgBtnBack">Back</button></div>
</div>
CSS :
#container div{
display:inline-block;
width:130px;
}
Fiddle Demo
This will serve the purpose. There is no need for any divs or paragraph. If you want the spaces between them to be specified, use margin-left or margin-right in the css classes.
<div style="width:500px;">
<button type="submit" class="msgBtn" onClick="return false;" >Save</button>
<button type="submit" class="msgBtn2" onClick="return false;">Publish</button>
<button class="msgBtnBack">Back</button>
</div>
You need to float all the buttons to left and make sure its width to fit within outer container.
CSS:
.btn{
float:left;
}
HTML:
<button type="submit" class="btn" onClick="return false;" >Save</button>
<button type="submit" class="btn" onClick="return false;">Publish</button>
<button class="btn">Back</button>
If you are using bootstrap then call a simple btn-group class in the outer div
<div class="btn-group">
View
Edit
Delete
</div>
The following will display all 3 buttons on the same line provided there is enough horizontal space to display them:
<button type="submit" class="msgBtn" onClick="return false;" >Save</button>
<button type="submit" class="msgBtn2" onClick="return false;">Publish</button>
<button class="msgBtnBack">Back</button>
// Note the lack of unnecessary divs, floats, etc.
The only reason the buttons wouldn't display inline is if they have had display:block applied to them within your css.
Related
I'm trying to have a paragraph tag in between two buttons with spacing. The small issue is the weird symbol when I add the " " command. I just need to take it out, or I'd like to know if there is an alternate way in adding space.
HTML:
<div class="col-md-12 text-align-center">
<button type="submit" href="../cards" class="fb_btn registerbtn">LOGIN</button>
<span class="color-gray small"> or </span>
<button type="submit" href="cards/register.php" class="fb_btn registerbtn">REGISTER</button>
<p>to claim this coupon</p>
</div>
Suggest you to use padding (left & right) instead of space( ). Check out the preview at https://jsfiddle.net/jwe8h49z/9/
I don't see any grey marks with just your code and boostrap in this codepen. Seems like something else is going on?
Also, as #Erik Philips suggested, a better way would be to use margins.
Here's an example:
<div class="col-md-12 text-align-center" >
<button type="submit" href="../cards" class="fb_btn registerbtn" style="margin-right: 10px;">LOGIN</button>
<span class="color-gray small">or</span>
<button type="submit" href="cards/register.php" class="fb_btn registerbtn" style="margin-left: 10px;">REGISTER</button>
<p>to claim this coupon</p>
</div>
.fb_btn{
padding:5px;
margin-right:5px;
margin-left:5px;
}
<div class="col-md-12 text-align-center">
<button type="submit" href="../cards" class="fb_btn registerbtn">LOGIN</button>
<span class="color-gray small">or</span>
<button type="submit" href="cards/register.php" class="fb_btn registerbtn">REGISTER</button>
<p>to claim this coupon</p>
</div>
Use CSS to add spaces between controls.
This code will work for you --
button{background:#f2901a; color:#fff; border:0; padding:15px; width:120px;}
.color-gray{padding:0 20px; position:relative; }
.color-gray::before{content:'---'; position:absolute; left:0px; top:0px;}
.color-gray::after{content:'---'; position:absolute; right:0px; top:0px;}
.text-align-center{text-align:center;}
<div class="col-md-12 text-align-center">
<button type="submit" href="../cards" class="fb_btn registerbtn">LOGIN</button>
<span class="color-gray small">or</span>
<button type="submit" href="cards/register.php" class="fb_btn registerbtn">REGISTER</button>
<p>to claim this coupon</p>
</div>
Apply CSS Box Modeling and apply margin or padding instead of using  
<style>
button{
margin: 10px;
}
</style>
<div class="col-md-12 text-align-center">
<button type="submit" href="../cards" class="fb_btn registerbtn">LOGIN</button>
<span class="color-gray small">or</span>
<button type="submit" href="cards/register.php" class="fb_btn registerbtn">REGISTER</button>
<p>to claim this coupon</p>
</div>
Here is our desperate try to make the buttons work. The BUTTON worked before i added the other one. please help. We also had difficulties with making the buttons look different but that is fixed now. (Its just telling me to text some more so thats the reason im writing this. this aint important. How are you doing today?)
.Button {
background-color: darkcyan;
border: none;
color: black;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
font-family: hacked;
}
.sub {
position: relative;
}
.itmHolder {
position: relative;
}
.itmHolder:nth-child(2),
.itmHolder:nth-child(3) {
position: absolute;
top: 0;
}
.og {
margin-top: 50px;
position: center;
text-align: center;
}
<title>Our Future</title>
</head>
<!--Baggrunds farve-->
<body bgcolor="#212f3c">
<!--Hovedskriften-->
<font size=40><center><h1 style="font-family:blowbrush;">Future</font></center></h1><form action="side2.html">
<div class="og">
<div class="itmHolder">
<div class="sub">
<button type="button" class="Button">About us<form action="side2.html"></button>
<button type="button" class="Button">Buy now<form action="buynow.html"></button>
</div>
</div>
<br></br>
</body>
</html>
<picture>
<!--Billede-->
<br></br>
<br></br>
<center><img src="CSfU23PXAAEA8et.jpg" alt="Matrix" style="width:auto;" border="5"><center/>
<br></br>
<br></br>
<!--Youtube video-->
<center><iframe width="700" height="400"src="https://www.youtube.com/embed/XGSy3_Czz8k?playlist=XGSy3_Czz8k&loop=1"></center></iframe>
</picture>
You havnt closed your form tag and you have it in the wrong place. Adjust your code:
<div class="sub">
<form action="side2.html" method="POST">
<input type="submit" class="Button" value="About us">
</form>
<form action="buynow.html" method="POST">
<input type="submit" class="Button" value="Buy now">
</form>
</div>
OR If you prefer not to use forms, use the <a> tag:
<div class="sub">
<button type="button" class="Button">About us</button>
<button type="button" class="Button">Buy now</button>
</div>
You haven't used the <form> tag in the right way in the below code part
<div class="sub">
<button type="button" class="Button">About us<form action="side2.html"></button>
<button type="button" class="Button">Buy now<form action="buynow.html"></button>
</div>
Try this way
<div class="sub">
<form action="side2.html">
<button type="submit" class="Button">About us</button>
</form>
<form action="buynow.html">
<button type="submit" class="Button">Buy now</button>
</form>
</div>
else try this alternate way
<div class="sub">
About us
Buy now
</div>
Hope this helps.
No need to use buttons to navigate through pages. You can do this instead:
Buy Now
Then style a however much you like.
Buttons are used with JavaScript in case you need to pass an onClick action.
How do I remove the line break between two <input> tags so that two buttons will display on the same line?
<td colspan="1" style="width:1%;padding-left:50px;">
<div style="display:inline-block">
<input type="submit" name="btnEdit" id="btnEdit" class="btn btn-success" style="width:50px;" value="Edit" />
<input type="submit" name="btnEdit" id="btnDel" class="btn btn-success" style="width:50px;" value="Del" />
#*<button type="submit" name="btnEdit" id="btnEdit" class="btn btn-success" style="width:50px;">Edit</button>
<button type="submit" name="btnDel" id="btnDel" class="btn btn-danger" style="width:50px;">Del</button>*#
</div>
</td>
The <input> and <button> elements are inline (inline-block) level by default - MDN, so they should be aligned next to each other, and there is no <br> between them in your code snippet.
As far I as see the problem is likely to be the width:1% on the container <td>, which makes it to not have enough room for the buttons to grow. The answer is simple: increase the container's width. Although, you can also use white-space: nowrap; if necessary.
Side note, ID must be unique on a page. You use id=btnEdit and id=btnDel multiple times there, it's likely to cause trouble later, so better to fix that too.
div{
display:inline-block
}
input,button {
width: 30px;
height: 30px;
background-color: #aaa;
color: white;
border: none;
}
<td colspan="1" style="width:1%;padding-left:50px;">
<div>
<input type="submit" name="btnEdit" id="btnEdit" class="btn btn-success" style="width:50px;" value="Edit" />
<input type="submit" name="btnEdit" id="btnDel" class="btn btn-success" style="width:50px;" value="Del" />
<button type="submit" name="btnEdit" id="btnEdit" class="btn btn-success" style="width:50px;">Edit</button>
<button type="submit" name="btnDel" id="btnDel" class="btn btn-danger" style="width:50px;">Del</button>
</div>
</td>
I would like to put a (2 button) radio btn-group inside of an input-group-addon. The trouble I'm having there is that the buttons do not stay on one line.
The common patterns to keep elements on the same line did not work for me.
Do you know how I could fix this? Thx
Here's the jsfiddle: http://jsfiddle.net/DTcHh/144/
<div id="filter_criteria_date">
<div class="input-group" style='margin-top:15px'> <span class="input-group-addon">
<input type="checkbox">
<div class="btn-group" data-toggle="buttons-radio">
<button type="button" class="btn btn-xs btn-primary">And</button>
<button type="button" class="btn btn-xs btn-primary">Or</button>
</div>
</span>
<input type="text" class="form-control filter_text" placeholder="Filter">
</div>
They do not stay on one line due to no width being set. Set a width for the parent of the buttons and they will fit.
.btn-group {
width: 100px;
}
DEMO HERE
.input-group-addon { width:auto; }
Working Demo http://jsfiddle.net/DTcHh/148/
I have the following HTML:
<div id="Container">
<input type="button" value="button" id="button1" />
<div id="text1">
some text here
</div>
<div id="TheButtons">
<input type="button" value="button" class="MyButtons" id="button2" />
<input type="button" value="button" class="MyButtons" id="button3" />
<input type="button" value="button" class="MyButtons" id="button4" />
<input type="button" value="button" class="MyButtons" id="button5" />
</div>
</div>
And the following CSS:
#Container{
background:red;
width:500px;
height:50px;}
#button1{
margin:7px;
float:left;}
#text1{
margin:7px;
text-align:center;
float:left;}
#TheButtons{
float:right;
margin:7px;}
.MyButtons{
margin:0px 3px;
float: left;}
As you can see in the JsFiddle here, the text is aligned to the left. The buttons on the right will have different text for different languages so I can't explicitly define the width of the third div TheButtons. How can I get the text to be centered between button1 and TheButtons?
Thanks.
Place the theButtons div before the text1 div in your HTML. Then remove the float from text1 and add overflow:auto to your Container div.
jsFiddle example