This question already has answers here:
How can i Display div Elements in one row
(7 answers)
How to float 3 divs side by side using CSS?
(16 answers)
Closed 2 years ago.
I have 3 buttons that display in a vertical line and I want them to display horizontally
<form method="twitch" action= "https://www.twitch.tv/">
<button type="submit"><img src="img/twitch.png" alt="Twitch"></button>
</form>
<form method="Instagram" action="https://www.instagram.com/">
<button type="submit"><img src="img/instagram.png" alt="Instagram" > </button>
</form>
<form method="linkedin" action="https://www.linkedin.com/">
<button type="submit"><img src="img/linkedin.png" alt="Linkedin" ></button>
</form>
Wrap them in a parent div and, in your CSS, set that div to display: flex.
In css add to each one of them float: left;
You can put each form and button inside individual <div>'s, wrap those <div>'s in a parent <div>, and then use flex: https://jsfiddle.net/HappyHands31/hnkqsjba/2/
.container {
display: flex;
}
.first, .second, .third {
display: flex;
}
<div class="container">
<div class="first">
<form method="twitch" action= "https://www.twitch.tv/">
<button type="submit"><img src="img/twitch.png" alt="Twitch">
</button>
</form>
</div>
<div class="second">
<form method="Instagram" action="https://www.instagram.com/">
<button type="submit"><img src="img/instagram.png" alt="Instagram" ></button>
</form>
</div>
<div class="third">
<form method="linkedin" action="https://www.linkedin.com/">
<button type="submit"><img src="img/linkedin.png" alt="Linkedin" > </button>
</form>
</div>
Use display:inline-block;
most people use flex but its not good becasue some of the old browsers can't understand flex.!
but all of the browsers support inline block
Related
I'm trying to align an input text and all the buttons you see in the following image to the bottom of "My text".
The bottom should be the bottom of the M not the bottom of the y.
Edit: as a second choice, all the elements can be aligned to the vertical center of `my text'.
Buttons 3 and 4 have to be aligned to the right.
If there isn't enough space, My text should remain on the first line, and the rest should go into a new line.
I tried using float: right with no luck, because button 3 and 4 go to the right upper edge. I tried displaying them inline, but that way they are not aligned on the right. I don't know what else to try.
My current code is the following, which gives me bottom alignment with Firefox but not with Chrome (as you can see, buttons 3 and 4 are not aligned with buttons 1 and 2)
I hope someone can help me.
div.inline {
display: inline-block;
}
<div id="titleBar">
<div class="inline" style="position: relative; width: 100%;">
<div class="inline" style="font-weight: bold; font-size: 2em; color: #D00000;">My text</div>
<div class="inline">
<form>
<div class="inline">
<input type="text" style="width: 16em" value="input text">
</div>
<div class="inline">
<input type="submit" value="button 1"></input>
<button>button 2</button>
</div>
</form>
</div>
<div style="position: absolute; bottom: 0px; right: 0px;">
<button >button 3</button>
<button >button 4</button>
</div>
</div>
</div>
Here is my code.I have minimized it as short as I can. In that text-align:right; is not working
.forgot {
color: red;
text-align: right;
}
<div class="content">
<center>
<h3><u>LOREM IPSUM</u></h3><br>
<button class="btn btn-primary">Login as Guest</button>
</center>
<br>
Forgot details?
</div>
As #TreyBake pointed out, center and u are not supposed to be used instead, you should use the text-align and em.
Also, here's the solution with setting right align to parent.
.forgot {
color: red;
}
.center-aligned{
text-align: center;
}
.right-aligned{
text-align: right;
}
<div class="content">
<div class="center-aligned">
<h3><em>LOREM IPSUM</em></h3><br>
<button class="btn btn-primary">Login as Guest</button>
</div>
<br>
<div class="right-aligned">
Forgot details?
</div>
</div>
The align is set on the parent element. Not on the element itself.
.forgot {
color: red;
}
.content {
text-align: right;
}
<div class="content">
<center>
<h3><u>LOREM IPSUM</u></h3><br>
<button class="btn btn-primary">Login as Guest</button>
</center>
<br>
Forgot details?
</div>
You can use text-align: right on a parent element. Create a div wrapping your link and give him the class. See example below:
html:
<div class="content">
<center>
<h3><u>LOREM IPSUM</u></h3><br>
<button class="btn btn-primary">Login as Guest</button>
</center>
<br>
<div class="text-right">
Forgot details?
</div>
</div>
css:
.forgot {
color: red;
}
.text-right {
text-align: right;
}
If you have Bootstrap installed, you can do all of this without css. Your html would look like this:
<div class="content">
<center>
<h3><u>LOREM IPSUM</u></h3><br>
<button class="btn btn-primary">Login as Guest</button>
</center>
<br>
<div class="text-right">
Forgot details?
</div>
</div>
Please note at time of writing, this is Bootstrap v4.2.1
Here's Why It's Not Aligning
You have your <a class="forgot"> element with the "Forgot Details" text inside of it. Since it's an <a> element, by default it will only stretch to be as wide as the text you place inside it. So as you can see in the screenshot below, your <a class="forgot"> element (highlit) is only as wide as the "Forgot Details" text. So your "text-align: right;" technically is aligning the text to the right, but since the parent container (the <a class="forgot"> element) is only as wide as the text, horizontally aligning it doesn't make a difference.
How To Fix It
Where an <a> element stretches only to fit its contents, a <div> element by default stretches horizontally to fill its parent container. So what you can do is enclose your <a class="forgot"> in a <div class="forgot-parent">, and then apply the "text-align: right" to the <div class="forgot-parent"> so that the <a class="forgot"> gets aligned to the right.
So the code will look like this:
.forgot {
color: red;
}
.forgot-parent {
text-align: right;
}
<div class="content">
<center>
<h3><u>LOREM IPSUM</u></h3><br>
<button class="btn btn-primary">Login as Guest</button>
</center>
<br>
<div class="forgot-parent">
Forgot details?
</div>
</div>
Note how I removed "text-align: right;" from '.forgot' and added it to '.forgot-parent'. The result is shown below. First, here is the parent <a class="forgot-parent"> div highlit.
Note how the <div class="forgot-parent"> has stretched to the full screen width. Next the <a class="forgot"> is highlit:
Note that the <a class="forgot"> is still only the width of its contents (the "Forgot Details" text), but it's now aligned to the right within its parent div.
I've been brushing up on html, css and javascript by working on a little project that I thought would be useful. It is a recipe finder based on what recipes I have in home. Anyways, my question is about lining up a few of the elements in the html page.
The part of the html page in question is:
<form>
<select size=10 id="first"></select>
<button type="button" id="addAll" onclick="rightAll()">
Add All
</button>
<button type="button" id="removeAll" onclick="leftAll()">
Remove All
</button>
<button type="button" id="add" onclick="right()">
>>
</button>
<button type="button" id="remove" onclick="left()">
<<
</button>
<select size=10 id="second"></select>
</form>
My css document:
html, body {
height: 100%;
min-height: 100%;
}
select{
width: 300px;
}
Because all the elements are in a form tag they all appear inline. I tried putting the buttons in a table, but the tables formatting put the first select on one line, the table on a new line, and the second select on a new line.
Here is what my formatting looks like now:
and here is what I want it to look like (thanks to paint)
I'm sure I could figure out how to center the buttons vertically in the form, but if you could help me out with that too then I would really appreciate it!
HTML
<form>
<div id="sel1">
<select size=10 id="first"></select>
</div>
<div id="buttons">
<div id="buttons1">
<button type="button" id="addAll" onclick="rightAll()">
Add All
</button>
<button type="button" id="removeAll" onclick="leftAll()">
Remove All
</button>
</div>
<div id="buttons2">
<button type="button" id="add" onclick="right()">
>>
</button>
<button type="button" id="remove" onclick="left()">
<<
</button>
</div>
</div>
<div id="sel2">
<select size=10 id="second"></select>
</div>
</form>
CSS
html, body {
height: 100%;
min-height: 100%;
}
select{
width: 300px;
}
div {
float: left;
}
#buttons1, #buttons2 {
float: none;
text-align: center;
}
It is up to you to tweak paddings and margins to leave it at your desire.
you should use div if you want to extent your design further, table is not responsive directly and type of fixed layout with messy code , you may try use div and other css property .
anyway just for that middle section , you may try div inside your table td like this :
<div style="width:100%;">
<div style="width:50%;float:left;">
<button type="button" id="addAll" onclick="rightAll()">
Add All
</button>
<div>
<div style="width:50%;float:right;">
<button type="button" id="removeAll" onclick="leftAll()">
Remove All
</button>
<div>
<div style="clear:both;"></div>
</div>
<div style="width:100%;">
<div style="width:50%;float:left;">
<button type="button" id="add" onclick="right()">
>>
</button>
<div>
<div style="width:50%;float:right;">
<button type="button" id="remove" onclick="left()">
<<
</button>
<div>
<div style="clear:both;"></div>
</div>
Cheers !
This question already has answers here:
CSS side by side div's auto equal widths
(5 answers)
Closed 8 years ago.
I have a container width some buttons in it:
<div class="button-container">
<button type="button" class="edit-quantity">Edit Quantity</button>
<button type="button" class="edit-price">Edit Price</button>
<button type="button" class="remove-item">Remove</button>
<button type="button" class="remove-all">Remove All</button>
</div>
http://jsfiddle.net/gRzAB/
How can I style the buttons and the container in a way that the buttons fill the container width equally, even if there is just 1 or 2 or 3 buttons?
Use display: flex from CSS3: Check my fiddle.
.button-container{
width:100%;
display: flex;
}
.button-container button{
width:100%;
}
You can use display:table; and display:table-cell; if you add a wrapping div around your buttons :
FIDDLE
HTML :
<div class="button-container">
<div>
<button type="button" class="edit-quantity">...</button>
</div>
<div>
<button type="button" class="edit-price">...</button>
</div>
<div>
<button type="button" class="remove-item">...</button>
</div>
<div>
<button type="button" class="remove-all">...</button>
</div>
</div>
CSS :
.button-container {
width:100%;
height:100px;
display:table;
}
.button-container >div {
display:table-cell;
}
.button-container button {
height:100%;
width:100%;
}
I'm trying to put two buttons one inside the other with html. I have tried this:
<div id="photoShow" style="width: 190px; height: 212px">
<input type="button" runat="server" id="btn_ShowImage" style =" background-image: url('photos/Analog50.jpg'); width: 55px; height: 54px;"
onclick="return btn_ShowImage_onclick()" /><asp:Button
ID="btn_AddProductToReservation" Height="180px" Width="194px"
runat="server" style="margin-top: 0px; margin-left: 0px;" />
</div>
Would love to get some help, Thank you
put them in a div like that:
<div style="float:left"><button></button><button></button></div>
so you can put them aside eachother, there is no sense putting buttons in each other!
if you use twitter bootstrap you can put those buttons one inside another:
<div class="btn btn-primary btn-large">
out out
<div class="btn btn-primary btn-large">
in in
</div>
out out
<div class="btn btn-primary btn-large">
in in
</div>
out out
</div>
and it will render as expected