Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Centering and positioning elements on the same row

Tags:

i have a question about centering and positioning elements behind one another. I have a block of text on the left and only one word in this case about, which should be centered and on the same line as the e-mail.

nav {
	text-align: center;
}
<address>
  <a href="#">Some text</a>
  <br>
  hi(at)mail.com
</address>

<nav>
  <a href="#">about</a>
</nav>

I tried to float the address to the left, but then the nav isn't in the center anymore. Any ideas how to accomplish this? It has to be easy, but i just don't know how.

Edit

The nav should be centered for the entire viewport, my current answer would be to absolute position the nav and set left and right to 0. but i don't know if this would be the best way to do it.

what it should look like:

enter image description here

like image 949
kay Avatar asked Apr 13 '16 21:04

kay


People also ask

How can you center an element horizontally and vertically using the position property?

For vertical alignment, set the parent element's width / height to 100% and add display: table . Then for the child element, change the display to table-cell and add vertical-align: middle . For horizontal centering, you could either add text-align: center to center the text and any other inline children elements.

Which positioning is used to set the element at fixed position?

Static positioning is the default that every element gets. It just means "put the element into its normal position in the document flow — nothing special to see here."

What type of positioning is used to fix the position of an element to a particular spot on the page regardless of scrolling?

Fixed positioning This can be used to create a "floating" element that stays in the same position regardless of scrolling. In the example below, box "One" is fixed at 80 pixels from the top of the page and 10 pixels from the left.


1 Answers

I dont know if it is the best way but it looks like what you want to do

nav {
left:50%;
	text-align: center;
}
address{
  float:left;
}
<address>
  <a href="#">Some text</a>
  <br>
  hi(at)mail.com
</address>

<nav>
<br/>
  <a href="#">about</a>
</nav>
like image 89
CodeWeis Avatar answered Sep 28 '22 04:09

CodeWeis