Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align <button> inline with text?

Tags:

html

css

I was wondering how one would make it so that they could have text followed by a button then more text, all on one line? This is what it might look like:

<h3>Some</h3>
<button>Text</button>
<h3>!</h3>
like image 730
JohnyNich Avatar asked Feb 12 '17 12:02

JohnyNich


People also ask

How do I align text inside a button?

We can align the buttons horizontally as well as vertically. We can center the button by using the following methods: text-align: center - By setting the value of text-align property of parent div tag to the center. margin: auto - By setting the value of margin property to auto.

Does text-align work on inline?

Even though the property says “text” align, it affects all elements inside the block-level element that are either inline or inline-block elements. The property only affects the content inside the element to which it is applied, and not the element itself.

How do I make an inline button?

If you have multiple buttons that should sit side-by-side on the same line, add the data-inline="true" attribute to each button. This will style the buttons to be the width of their content and float the buttons so they sit on the same line.

Does text-Align Center work with Button?

as i already mentioned, assigning text-align:center to the button itself won't work, you need to put the button inside some other element for example <p> and assign text-align:center to it.


1 Answers

All heading tags such as <h3> are block-level, and a block-level element occupies the entire space of its parent element (container). You can reset it to display: inline, display: inline-block (recommend), display: inline-table, or even using flexbox, float etc., there are many ways.

If you can modify the markup, I suggest not to use <h3> for semantic reason, just use <span> tags or plain text would be a better choice.

h3 {
  display: inline-block;
  margin: 0;
}
<h3>Some</h3>
<button>Text</button>
<h3>!</h3>

<hr>

<span>Some</span>
<button>Text</button>
<span>!</span>

<hr>

Some
<button>Text</button>
!
like image 86
Stickers Avatar answered Sep 21 '22 12:09

Stickers