How do you make a Div with 2 buttons become inline?
<div>
<h2 id="break-label"> Break Length </h2>
<div id="button">
<button id="break-decrement">
handleClickBreakDecrement
</button>
<p id="break-length"> 5 minutes or something </p>
<button id="break-increment">
handleClickBreakIncrement
</button>
</div>
</div>
The div with the ID="button" must be inline like this:
**handleClickBreakDecrement** 5 minutes or something **handleClickBreakIncrement**
Instead of this:
**handleClickBreakDecrement**
5 minutes or something
**handleClickBreakIncrement**
I tried using display : inline but nothing happened
The paragraph element (<p>...</p>) between your two buttons is a block-level element, which accounts for the behavior you're witnessing.
To fix, either set display: inline on the paragraph element, or replace it with an inline element like <span>...</span>:
<div>
<h2 id="break-label"> Break Length </h2>
<div id="button">
<button id="break-decrement">handleClickBreakDecrement</button>
<span id="break-length"> 5 minutes or something </span>
<button id="break-increment">handleClickBreakIncrement</button>
</div>
</div>
To make the inner buttons and paragraph render on the same line, you can set their CSS property display as inline-block, like the following snippet:
#button > button, p {
display: inline-block;
}
<div>
<h2 id="break-label"> Break Length </h2>
<div id="button">
<button id="break-decrement">
handleClickBreakDecrement
</button>
<p id="break-length"> 5 minutes or something </p>
<button id="break-increment">
handleClickBreakIncrement
</button>
</div>
</div>
Three feasible ways to achieve:
#button {
display: flex;
}
<div>
<h2 id="break-label"> Break Length </h2>
<div id="button">
<button id="break-decrement">
handleClickBreakDecrement
</button>
<p id="break-length"> 5 minutes or something </p>
<button id="break-increment">
handleClickBreakIncrement
</button>
</div>
</div>
#button button,
#button p {
display: inline;
}
<div>
<h2 id="break-label"> Break Length </h2>
<div id="button">
<button id="break-decrement">
handleClickBreakDecrement
</button>
<p id="break-length"> 5 minutes or something </p>
<button id="break-increment">
handleClickBreakIncrement
</button>
</div>
</div>
#button {
overflow: hidden;
}
#button button,
#button p {
float: left;
}
<div>
<h2 id="break-label"> Break Length </h2>
<div id="button">
<button id="break-decrement">
handleClickBreakDecrement
</button>
<p id="break-length"> 5 minutes or something </p>
<button id="break-increment">
handleClickBreakIncrement
</button>
</div>
</div>
Related
I have a link button that I need to place to the right of a div. Adding float-left on the div and float-right on the link button does not do it. What am I doing wrong?
https://jsfiddle.net/3v2s4c50/
<div class="container">
<div class="row">
<div class="col">
<div class="card">
<div class="card-header">Today and Tomorrow</div>
<div class="card-body">
<div class="float-left">Someone somewhere is waiting for you.</div>
<a role="button" href="google.com" class="float-right btn btn-primary"> Login</a>
</div>
</div>
</div>
<div class="col">
2 of 2
</div>
</div>
</div>
remove floats and add:
.card-body{
display: flex;
justify-content: space-between;
align-items: center;
}
<div class="card-body d-flex">
<div class="flex-fill">Someone somewhere is waiting for you</div>
<a role="button" href="google.com" class="flex-fill btn btn-primary"> Login</a>
</div>
Well, it is doing it. But the portion of the screen that is showing the results is not wide enough to show both the div with the text and the button in the same row.. then it breaks down.
If you change the text to something smaller, like 'Someone is waiting' you can see the button floating right :)
You can also set a fixed width for your text div (currently it is expanding based on the content).
<div class="card-body">
<div class="float-left" style="width: 50%;">Someone somewhere is waiting for you</div>
<a role="button" href="google.com" class="float-right btn btn-primary"> Login</a>
</div>
You can add your link to a div with any class. Then add style "text-align: right;" into your div like this:
.my-link {
text-align: right;
}
.
<div class="my-link">
<a role="button" href="google.com" class="float-right btn btn-primary"> Login</a>
</div>
.
I hope this will be useful.
My goal is simple: having a label on the left, and a download button on the right.
They should result in the same line, preferably aligned in the middle of the headline.
But at least the following is not working:
<div>
<h1 style="display:inline-block">My Label left</h1>
<div style="float:right">
<a href="/export" target="_blank">
<button type="button" class="btn btn-outline-primary">
<span class="glyphicon glyphicon-download-alt"> Download</span>
</button>
</a>
</div>
</div>
https://jsfiddle.net/Lbav4mhe/
Add a class or id to the outer/wrapper div and then set some css to it, like the below code shows. (Also, you don't need that float: right if using the CSS I provided)
#wrapperDiv {
display: flex;
align-items: center;
justify-content: space-between;
}
<div id="wrapperDiv">
<h1>My Label left</h1>
<div>
<a href="/export" target="_blank">
<button type="button" class="btn btn-outline-primary">
<span class="glyphicon glyphicon-download-alt"> Download</span>
</button>
</a>
</div>
</div>
I am struggling getting my accordion to work. When I collapse the first level, the second one comes up as it should, but it then the first level is still visible.
Accordion, not collapsed:
Accordion collapsed:
I've been staring at this for hours. Probably I am missing something stupid here.
<div class='accordion' id='mainAccordion'>
<div class='card'>
<div class='card-header' id='headingOt'>
<h2 class='mb-0'>
<button aria-controls='collapseOt' aria-expanded='true' class='btn btn-link' data-target='#collapseOt' data-toggle='collapse' type='button'>
<h2>Header</h2>
</button>
<div aria-labelledby='headingOt' class='collapse show' data-parent='#mainAccordion' id='collapseOt'>
<div class='card-body'>
dummy text
</div>
</div>
</h2>
</div>
</div>
<div class='card'>
<div class='card-header' id='heading-nt'>
<h2 class='mb-0'>
<button aria-controls='collapseNt' aria-expanded='false' class='btn btn-link' data-target='#collapseNt' data-toggle='collapse' type='button'>
<h2>header</h2>
</button>
<div aria-labelledby='headingNt' class='collapse show' data-parent='#mainAccordion' id='collapseNt'>
<div class='card-body'>
dummy text
</div>
</div>
</h2>
</div>
</div>
</div>
------------------ Addition, 5 feb 2019 ------------
Attached a little gif that shows what happens. It seems that the accordion works well, it collapses the text below, the second header shifts up, but then the first text pops up again.
I have a problem with floating buttons inside my div. As soon as I set the float property on button, it not only moves left/right, but slightly changes position and moves up which is not what I want...
Here is what I'm working on
http://jsfiddle.net/o1u1cLbm/2/
<div id='wrapper' style='display:flex; height:88px;align-items:center;text-align: center;background-color:yellow'>
<div style="background-color:blue">
<h1>
Some header text
</h1>
</div>
<div style='flex:1;background-color:red'>
<div style='display:block; vertical-align:middle'>
<button style="height:24px;">
Some stuff
</button>
<button style="height:40px">
Other stuff
</button>
</div>
</div>
The buttons must be in a container that will grow to max space after the title text. Now I want the first smaller button to be close to the title, and the big one on the right side like this
http://jsfiddle.net/o1u1cLbm/3/
<div id='wrapper' style='display:flex; height:88px;align-items:center;text-align: center;background-color:yellow'>
<div style="background-color:blue">
<h1>
Some header text
</h1>
</div>
<div style='flex:1;background-color:red'>
<div style='display:block; vertical-align:middle'>
<button style="height:24px;float:left">
Some stuff
</button>
<button style="height:40px;float:right">
Other stuff
</button>
</div>
</div>
</div>
As you can see after I add float property to the button it is not centered in the parent div anymore but attached to top.
How can I float the buttons without changing their vertical position with just css?
Instead of inline-block just make your div a flex container:
display: flex;
align-items: center;
justify-content: space-between;
justify-content: space-between get you the effect of floating - see demo below:
<div id='wrapper' style='display:flex; height:88px;align-items:center;text-align: center;background-color:yellow'>
<div style="background-color:blue">
<h1>
Some header text
</h1>
</div>
<div style='flex:1;background-color:red'>
<div style='display: flex;
align-items: center;
justify-content: space-between;'>
<button style="height:24px;">
Some stuff
</button>
<button style="height:40px">
Other stuff
</button>
</div>
</div>
</div>
There is no need for floats, you can use flexbox and then use margin-left:auto to last flex-item
<div id='wrapper' style='display:flex; height:88px;align-items:center;text-align: center;background-color:yellow'>
<div style="background-color:blue">
<h1>
Some header text
</h1>
</div>
<div style='flex:1;background-color:red'>
<div style='display:flex;align-items:center;'>
<button style="height:24px;">
Some stuff
</button>
<button style="height:40px;margin-left:auto;">
Other stuff
</button>
</div>
</div>
</div>
Or you can use justify-content: space-between; to flex-container
<div id='wrapper' style='display:flex; height:88px;align-items:center;text-align: center;background-color:yellow'>
<div style="background-color:blue">
<h1>
Some header text
</h1>
</div>
<div style='flex:1;background-color:red'>
<div style='display: flex;width: 100%;justify-content: space-between;align-items: center;'>
<button style="height:24px;">
Some stuff
</button>
<button style="height:40px;margin-left:auto;">
Other stuff
</button>
</div>
</div>
</div>
If you use display: flax; don't need use floating in the flax there are native solutions here you can find solution in JS Fiddle
<div id='wrapper' style='display:flex; height:88px;align-items:center;text-align: center;background-color:yellow'>
<div style="background-color:blue">
<h1>
Some header text
</h1>
</div>
<div style='flex:1;background-color:red'>
<div style='display: flex; align-items: center; justify-content: space-between;'>
<button style="height:24px;">
Some stuff
</button>
<button style="height:40px;">
Other stuff
</button>
</div>
</div>
</div>
Hi all I have created two buttons in alligned in the two sides of my web page, one on the left and one the right side. Each button upon its click shows an alert text on its relevant side like in the picture
The code that I have used is the following :
<div class="row">
<div class="col-lg-6">
<div class="previous">
<button type="button" id="button_1" class="btn btn-primary btn-lg">Button1</button>
<span id="alert_info_1" class="alert alert-info">
Alert Info
</span>
</div>
</div>
<div class="col-lg-6 text-left">
<div class="next" >
<button type="button" id="button_2" class="btn btn-primary btn-lg">Button2</button>
<span id="alert_info_2" class="alert alert-info ">
Alert Info
</span>
</div>
</div>
</div>
While the css for the alignment of the buttons :
.previous {
text-align: left;
}
.next {
text-align: right;
}
What I'd like to do is to make the alert info text of the button 2 to appear on the left side of the button and not on the right as it is show on the above picture
I've tried to add text-left in the button class but didn't work.
I also tried to add pull-left class in the span class, it forced the text to the left but the alert text appeared quite far from the button 2 as in the following image:
Does anyone has any idea how to fix this ?
just replace your second button and alert box then it will work and if you do not change your html , so need to add some extra css
.previous {
text-align: left;
}
.next {
text-align: right;
}
<link rel="stylesheet prefetch" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<div class="row">
<div class="col-xs-6">
<div class="previous">
<button type="button" id="button_1" class="btn btn-primary btn-lg">Button1</button>
<span id="alert_info_1" class="alert alert-info">
Alert Info
</span>
</div>
</div>
<div class="col-xs-6 text-left">
<div class="next">
<span id="alert_info_2" class="alert alert-info ">Alert Info</span>
<button type="button" id="button_2" class="btn btn-primary btn-lg">Button2</button>
</div>
</div>
</div>
Swap second span and button:
.previous {
text-align: left;
}
.next {
text-align: right;
}
<link rel="stylesheet prefetch" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<div class="row">
<div class="col-xs-6">
<div class="previous">
<button type="button" id="button_1" class="btn btn-primary btn-lg">Button1</button>
<span id="alert_info_1" class="alert alert-info">
Alert Info
</span>
</div>
</div>
<div class="col-xs-6 text-left">
<div class="next">
<span id="alert_info_2" class="alert alert-info ">Alert Info</span>
<button type="button" id="button_2" class="btn btn-primary btn-lg">Button2</button>
</div>
</div>
</div>