I am trying to build my website. 1. I am trying to create link in vertical direction in middle of my page; A,B,C,D however it is not working as a link, it works like a paragraph.
I want to make A,B,C,D to have spaces in between them.
Is there a way to make A,B,C,D links covered in circle?
/* navigation */
.navig {
float: left;
margin-top: 150px;
}
.navig a{
text-decoration: none;
color:black;
}
.navig a:hover{
}
.navig li{
list-style-type: none;
position: fixed;
padding-top: 50x;
line-height: 40px;
}
<div class="container">
<nav class="navig">
<ul>
<li><a href="http://google.com">A</a></li>
<li><a href="http://google.com">B</a></li>
<li><a href="http://google.com">C</a></li>
<li><a href="http://google.com">D</a></li>
</ul>
</nav>
Answer: Use the CSS line-height property Suppose you have a div element with the height of 50px and you have placed some link inside the div that you want to align vertically center. The simplest way to do it is — just apply the line-height property with value equal to the height of div which is 50px .
To center both vertically and horizontally, use padding and text-align: center : I am vertically and horizontally centered.
To align two <div> elements vertically in Bootstrap 3, you can try using the CSS Flexible Box Layout. In the example below, we display the needed row as a flex container box with the CSS display property and then, align the flex-items (columns) vertically with the align-items property.
To center text in CSS, use the text-align property and define it with the value 'center.
You can just set text-align to center for an inline element, and margin: 0 auto would do it for a block-level element.
I think this is what you are looking for -> (View snippet behind)
position:fixed
on the li tags, placing them all in the same tiny space.border
and border-radius
to the A tags.display: flex
to the .navig
class and play with the justify-content
and align-items
properties.CCS and HTML (HTML remained untouched)
.navig li {
list-style-type: none;
margin: 30px 0;
}
.navig a {
display: flex;
justify-content: center; /*flex property to center horizontally*/
align-items: center; /*flex property to center vertically*/
width: 50px;
height: 50px;
border: 1px solid black;
border-radius: 50%;
text-decoration: none;
color: black;
}
ul, li, a {
margin: 0;
padding: 0;
}
<div class="container">
<nav class="navig">
<ul>
<li>
<a href="http://google.com">
A
</a>
</li>
<li>
<a href="http://google.com">
B
</a>
</li>
<li>
<a href="http://google.com">
C
</a>
</li>
<li>
<a href="http://google.com">
D
</a>
</li>
</ul>
</nav>
</div>
You could do something like this:
.link {
height: 35px;
width: 35px;
background-color: #FFFFFF;
border-radius: 50%;
border-style: solid;
border-width: 1px;
border-color: black;
list-style-type: none;
text-align: center;
margin: 0 auto;
margin-bottom: 10px;
display: flex; /* establish flex container */
justify-content: center; /* center items vertically, in this case */
align-items: center; /* center items horizontally, in this case */
}
.navig a {
text-decoration: none;
color: black;
}
<form>
<div class="container">
<nav class="navig">
<ul>
<div class=link>
<li><a href="http://google.com">A</a></li>
</div>
<div class=link>
<li><a href="http://google.com">B</a></li>
</div>
<div class=link>
<li><a href="http://google.com">C</a></li>
</div>
<div class=link>
<li><a href="http://google.com">D</a></li>
</div>
</ul>
</nav>
</div>
</form>
Edit: I do agree with Adrian that using Flexbox is better than just aligning items by using {text-align: center} and {vertical-align: middle}, and I have modified my answer accordingly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With