Keep buttons alignment in HTML
up vote
2
down vote
favorite
Everytime when I press on Button 1
, Button 2
and Button 3
are going below Button 1
(same with Button 2
). Here is a working snippet
I want something like this to happen (everytime I press on a new button, the new text overrides the previous text, and the alignment is kept).
What do I need to change in order to achieve what I want? Thank you for your time!
html angular
|
show 2 more comments
up vote
2
down vote
favorite
Everytime when I press on Button 1
, Button 2
and Button 3
are going below Button 1
(same with Button 2
). Here is a working snippet
I want something like this to happen (everytime I press on a new button, the new text overrides the previous text, and the alignment is kept).
What do I need to change in order to achieve what I want? Thank you for your time!
html angular
Your code does not run
– mplungjan
Nov 8 at 9:16
What about now, @mplungjan ?
– Tenzolinho
Nov 8 at 9:18
No. Localhost errors and(index):12 Uncaught ReferenceError: _preboot is not defined
– mplungjan
Nov 8 at 9:20
I don't know, it's working fine. I tried on a different browser.
– Tenzolinho
Nov 8 at 9:21
1
@Nik I do, I just wanted to keep it simple.
– Tenzolinho
Nov 8 at 9:44
|
show 2 more comments
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Everytime when I press on Button 1
, Button 2
and Button 3
are going below Button 1
(same with Button 2
). Here is a working snippet
I want something like this to happen (everytime I press on a new button, the new text overrides the previous text, and the alignment is kept).
What do I need to change in order to achieve what I want? Thank you for your time!
html angular
Everytime when I press on Button 1
, Button 2
and Button 3
are going below Button 1
(same with Button 2
). Here is a working snippet
I want something like this to happen (everytime I press on a new button, the new text overrides the previous text, and the alignment is kept).
What do I need to change in order to achieve what I want? Thank you for your time!
html angular
html angular
edited Nov 8 at 9:24
asked Nov 8 at 9:14
Tenzolinho
21510
21510
Your code does not run
– mplungjan
Nov 8 at 9:16
What about now, @mplungjan ?
– Tenzolinho
Nov 8 at 9:18
No. Localhost errors and(index):12 Uncaught ReferenceError: _preboot is not defined
– mplungjan
Nov 8 at 9:20
I don't know, it's working fine. I tried on a different browser.
– Tenzolinho
Nov 8 at 9:21
1
@Nik I do, I just wanted to keep it simple.
– Tenzolinho
Nov 8 at 9:44
|
show 2 more comments
Your code does not run
– mplungjan
Nov 8 at 9:16
What about now, @mplungjan ?
– Tenzolinho
Nov 8 at 9:18
No. Localhost errors and(index):12 Uncaught ReferenceError: _preboot is not defined
– mplungjan
Nov 8 at 9:20
I don't know, it's working fine. I tried on a different browser.
– Tenzolinho
Nov 8 at 9:21
1
@Nik I do, I just wanted to keep it simple.
– Tenzolinho
Nov 8 at 9:44
Your code does not run
– mplungjan
Nov 8 at 9:16
Your code does not run
– mplungjan
Nov 8 at 9:16
What about now, @mplungjan ?
– Tenzolinho
Nov 8 at 9:18
What about now, @mplungjan ?
– Tenzolinho
Nov 8 at 9:18
No. Localhost errors and
(index):12 Uncaught ReferenceError: _preboot is not defined
– mplungjan
Nov 8 at 9:20
No. Localhost errors and
(index):12 Uncaught ReferenceError: _preboot is not defined
– mplungjan
Nov 8 at 9:20
I don't know, it's working fine. I tried on a different browser.
– Tenzolinho
Nov 8 at 9:21
I don't know, it's working fine. I tried on a different browser.
– Tenzolinho
Nov 8 at 9:21
1
1
@Nik I do, I just wanted to keep it simple.
– Tenzolinho
Nov 8 at 9:44
@Nik I do, I just wanted to keep it simple.
– Tenzolinho
Nov 8 at 9:44
|
show 2 more comments
4 Answers
4
active
oldest
votes
up vote
1
down vote
accepted
Structure you html like this.
Place the text inside the container element for each button.
Set the container elements display to inline-block
add a comment |
up vote
1
down vote
You need to set the div's which are containing the text to display: inline-block;
div {
display: inline-block
}
add a comment |
up vote
1
down vote
Here is the updated code snippet. I've restructured the html and took the text div at the end after buttons are added. This way the buttons remain in same position. For replacing the text, I've used a variable which is changed on button click and the value is updated on html.
Hope this is what you wanted to achieve.
add a comment |
up vote
1
down vote
Here is the code for you :
function openCity(evt, cityName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(cityName).style.display = "block";
evt.currentTarget.className += " active";
}
body {
font-family: Arial;
}
.tab {
overflow: hidden;
}
.tab button {
cursor: pointer;
padding: 6px 10px;
transition: 0.3s;
font-size: 17px;
}
.tabcontent {
display: none;
padding: 6px 12px;
border-top: none;
}
<meta name="viewport" content="width=device-width, initial-scale=1">
<div class="tab">
<button class="tablinks" onclick="openCity(event, 'London')">London</button>
<button class="tablinks" onclick="openCity(event, 'Paris')">Paris</button>
<button class="tablinks" onclick="openCity(event, 'Tokyo')">Tokyo</button>
</div>
<div id="London" class="tabcontent">
<h3>London</h3>
<p>London is the capital city of England.</p>
</div>
<div id="Paris" class="tabcontent">
<h3>Paris</h3>
<p>Paris is the capital of France.</p>
</div>
<div id="Tokyo" class="tabcontent">
<h3>Tokyo</h3>
<p>Tokyo is the capital of Japan.</p>
</div>
ya just changed through javascript and simply taken tabs using bootstarp @mplungjan
– Iswarya Swaminadhan
Nov 8 at 9:58
yeah Mr. @mplungjan sure for every time i post the answer thank you for your feedback
– Iswarya Swaminadhan
Nov 8 at 10:36
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Structure you html like this.
Place the text inside the container element for each button.
Set the container elements display to inline-block
add a comment |
up vote
1
down vote
accepted
Structure you html like this.
Place the text inside the container element for each button.
Set the container elements display to inline-block
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Structure you html like this.
Place the text inside the container element for each button.
Set the container elements display to inline-block
Structure you html like this.
Place the text inside the container element for each button.
Set the container elements display to inline-block
answered Nov 8 at 9:24
Dimensionless
126210
126210
add a comment |
add a comment |
up vote
1
down vote
You need to set the div's which are containing the text to display: inline-block;
div {
display: inline-block
}
add a comment |
up vote
1
down vote
You need to set the div's which are containing the text to display: inline-block;
div {
display: inline-block
}
add a comment |
up vote
1
down vote
up vote
1
down vote
You need to set the div's which are containing the text to display: inline-block;
div {
display: inline-block
}
You need to set the div's which are containing the text to display: inline-block;
div {
display: inline-block
}
answered Nov 8 at 9:26
Mikkel Fennefoss
404315
404315
add a comment |
add a comment |
up vote
1
down vote
Here is the updated code snippet. I've restructured the html and took the text div at the end after buttons are added. This way the buttons remain in same position. For replacing the text, I've used a variable which is changed on button click and the value is updated on html.
Hope this is what you wanted to achieve.
add a comment |
up vote
1
down vote
Here is the updated code snippet. I've restructured the html and took the text div at the end after buttons are added. This way the buttons remain in same position. For replacing the text, I've used a variable which is changed on button click and the value is updated on html.
Hope this is what you wanted to achieve.
add a comment |
up vote
1
down vote
up vote
1
down vote
Here is the updated code snippet. I've restructured the html and took the text div at the end after buttons are added. This way the buttons remain in same position. For replacing the text, I've used a variable which is changed on button click and the value is updated on html.
Hope this is what you wanted to achieve.
Here is the updated code snippet. I've restructured the html and took the text div at the end after buttons are added. This way the buttons remain in same position. For replacing the text, I've used a variable which is changed on button click and the value is updated on html.
Hope this is what you wanted to achieve.
answered Nov 8 at 9:48
Nik
1169
1169
add a comment |
add a comment |
up vote
1
down vote
Here is the code for you :
function openCity(evt, cityName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(cityName).style.display = "block";
evt.currentTarget.className += " active";
}
body {
font-family: Arial;
}
.tab {
overflow: hidden;
}
.tab button {
cursor: pointer;
padding: 6px 10px;
transition: 0.3s;
font-size: 17px;
}
.tabcontent {
display: none;
padding: 6px 12px;
border-top: none;
}
<meta name="viewport" content="width=device-width, initial-scale=1">
<div class="tab">
<button class="tablinks" onclick="openCity(event, 'London')">London</button>
<button class="tablinks" onclick="openCity(event, 'Paris')">Paris</button>
<button class="tablinks" onclick="openCity(event, 'Tokyo')">Tokyo</button>
</div>
<div id="London" class="tabcontent">
<h3>London</h3>
<p>London is the capital city of England.</p>
</div>
<div id="Paris" class="tabcontent">
<h3>Paris</h3>
<p>Paris is the capital of France.</p>
</div>
<div id="Tokyo" class="tabcontent">
<h3>Tokyo</h3>
<p>Tokyo is the capital of Japan.</p>
</div>
ya just changed through javascript and simply taken tabs using bootstarp @mplungjan
– Iswarya Swaminadhan
Nov 8 at 9:58
yeah Mr. @mplungjan sure for every time i post the answer thank you for your feedback
– Iswarya Swaminadhan
Nov 8 at 10:36
add a comment |
up vote
1
down vote
Here is the code for you :
function openCity(evt, cityName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(cityName).style.display = "block";
evt.currentTarget.className += " active";
}
body {
font-family: Arial;
}
.tab {
overflow: hidden;
}
.tab button {
cursor: pointer;
padding: 6px 10px;
transition: 0.3s;
font-size: 17px;
}
.tabcontent {
display: none;
padding: 6px 12px;
border-top: none;
}
<meta name="viewport" content="width=device-width, initial-scale=1">
<div class="tab">
<button class="tablinks" onclick="openCity(event, 'London')">London</button>
<button class="tablinks" onclick="openCity(event, 'Paris')">Paris</button>
<button class="tablinks" onclick="openCity(event, 'Tokyo')">Tokyo</button>
</div>
<div id="London" class="tabcontent">
<h3>London</h3>
<p>London is the capital city of England.</p>
</div>
<div id="Paris" class="tabcontent">
<h3>Paris</h3>
<p>Paris is the capital of France.</p>
</div>
<div id="Tokyo" class="tabcontent">
<h3>Tokyo</h3>
<p>Tokyo is the capital of Japan.</p>
</div>
ya just changed through javascript and simply taken tabs using bootstarp @mplungjan
– Iswarya Swaminadhan
Nov 8 at 9:58
yeah Mr. @mplungjan sure for every time i post the answer thank you for your feedback
– Iswarya Swaminadhan
Nov 8 at 10:36
add a comment |
up vote
1
down vote
up vote
1
down vote
Here is the code for you :
function openCity(evt, cityName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(cityName).style.display = "block";
evt.currentTarget.className += " active";
}
body {
font-family: Arial;
}
.tab {
overflow: hidden;
}
.tab button {
cursor: pointer;
padding: 6px 10px;
transition: 0.3s;
font-size: 17px;
}
.tabcontent {
display: none;
padding: 6px 12px;
border-top: none;
}
<meta name="viewport" content="width=device-width, initial-scale=1">
<div class="tab">
<button class="tablinks" onclick="openCity(event, 'London')">London</button>
<button class="tablinks" onclick="openCity(event, 'Paris')">Paris</button>
<button class="tablinks" onclick="openCity(event, 'Tokyo')">Tokyo</button>
</div>
<div id="London" class="tabcontent">
<h3>London</h3>
<p>London is the capital city of England.</p>
</div>
<div id="Paris" class="tabcontent">
<h3>Paris</h3>
<p>Paris is the capital of France.</p>
</div>
<div id="Tokyo" class="tabcontent">
<h3>Tokyo</h3>
<p>Tokyo is the capital of Japan.</p>
</div>
Here is the code for you :
function openCity(evt, cityName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(cityName).style.display = "block";
evt.currentTarget.className += " active";
}
body {
font-family: Arial;
}
.tab {
overflow: hidden;
}
.tab button {
cursor: pointer;
padding: 6px 10px;
transition: 0.3s;
font-size: 17px;
}
.tabcontent {
display: none;
padding: 6px 12px;
border-top: none;
}
<meta name="viewport" content="width=device-width, initial-scale=1">
<div class="tab">
<button class="tablinks" onclick="openCity(event, 'London')">London</button>
<button class="tablinks" onclick="openCity(event, 'Paris')">Paris</button>
<button class="tablinks" onclick="openCity(event, 'Tokyo')">Tokyo</button>
</div>
<div id="London" class="tabcontent">
<h3>London</h3>
<p>London is the capital city of England.</p>
</div>
<div id="Paris" class="tabcontent">
<h3>Paris</h3>
<p>Paris is the capital of France.</p>
</div>
<div id="Tokyo" class="tabcontent">
<h3>Tokyo</h3>
<p>Tokyo is the capital of Japan.</p>
</div>
function openCity(evt, cityName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(cityName).style.display = "block";
evt.currentTarget.className += " active";
}
body {
font-family: Arial;
}
.tab {
overflow: hidden;
}
.tab button {
cursor: pointer;
padding: 6px 10px;
transition: 0.3s;
font-size: 17px;
}
.tabcontent {
display: none;
padding: 6px 12px;
border-top: none;
}
<meta name="viewport" content="width=device-width, initial-scale=1">
<div class="tab">
<button class="tablinks" onclick="openCity(event, 'London')">London</button>
<button class="tablinks" onclick="openCity(event, 'Paris')">Paris</button>
<button class="tablinks" onclick="openCity(event, 'Tokyo')">Tokyo</button>
</div>
<div id="London" class="tabcontent">
<h3>London</h3>
<p>London is the capital city of England.</p>
</div>
<div id="Paris" class="tabcontent">
<h3>Paris</h3>
<p>Paris is the capital of France.</p>
</div>
<div id="Tokyo" class="tabcontent">
<h3>Tokyo</h3>
<p>Tokyo is the capital of Japan.</p>
</div>
function openCity(evt, cityName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(cityName).style.display = "block";
evt.currentTarget.className += " active";
}
body {
font-family: Arial;
}
.tab {
overflow: hidden;
}
.tab button {
cursor: pointer;
padding: 6px 10px;
transition: 0.3s;
font-size: 17px;
}
.tabcontent {
display: none;
padding: 6px 12px;
border-top: none;
}
<meta name="viewport" content="width=device-width, initial-scale=1">
<div class="tab">
<button class="tablinks" onclick="openCity(event, 'London')">London</button>
<button class="tablinks" onclick="openCity(event, 'Paris')">Paris</button>
<button class="tablinks" onclick="openCity(event, 'Tokyo')">Tokyo</button>
</div>
<div id="London" class="tabcontent">
<h3>London</h3>
<p>London is the capital city of England.</p>
</div>
<div id="Paris" class="tabcontent">
<h3>Paris</h3>
<p>Paris is the capital of France.</p>
</div>
<div id="Tokyo" class="tabcontent">
<h3>Tokyo</h3>
<p>Tokyo is the capital of Japan.</p>
</div>
edited Nov 8 at 9:56
mplungjan
86.1k20121181
86.1k20121181
answered Nov 8 at 9:25
Iswarya Swaminadhan
8210
8210
ya just changed through javascript and simply taken tabs using bootstarp @mplungjan
– Iswarya Swaminadhan
Nov 8 at 9:58
yeah Mr. @mplungjan sure for every time i post the answer thank you for your feedback
– Iswarya Swaminadhan
Nov 8 at 10:36
add a comment |
ya just changed through javascript and simply taken tabs using bootstarp @mplungjan
– Iswarya Swaminadhan
Nov 8 at 9:58
yeah Mr. @mplungjan sure for every time i post the answer thank you for your feedback
– Iswarya Swaminadhan
Nov 8 at 10:36
ya just changed through javascript and simply taken tabs using bootstarp @mplungjan
– Iswarya Swaminadhan
Nov 8 at 9:58
ya just changed through javascript and simply taken tabs using bootstarp @mplungjan
– Iswarya Swaminadhan
Nov 8 at 9:58
yeah Mr. @mplungjan sure for every time i post the answer thank you for your feedback
– Iswarya Swaminadhan
Nov 8 at 10:36
yeah Mr. @mplungjan sure for every time i post the answer thank you for your feedback
– Iswarya Swaminadhan
Nov 8 at 10:36
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53204592%2fkeep-buttons-alignment-in-html%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Your code does not run
– mplungjan
Nov 8 at 9:16
What about now, @mplungjan ?
– Tenzolinho
Nov 8 at 9:18
No. Localhost errors and
(index):12 Uncaught ReferenceError: _preboot is not defined
– mplungjan
Nov 8 at 9:20
I don't know, it's working fine. I tried on a different browser.
– Tenzolinho
Nov 8 at 9:21
1
@Nik I do, I just wanted to keep it simple.
– Tenzolinho
Nov 8 at 9:44