Reputation: 4452
I want to have a nav bar in a div like this
I have an image in the middle of the div and I want to write the css so that my nav elements ( home, about... ) have a relative margin and are not in the image.
html
<div class="nav">
<img id="diamond" src="{% static "blog/img/Diamond.png" %}">
<a id="nav_left" href="{% url 'index' %}">Home</a>
<a id="nav_left" href="{% url 'guides' %}">Guides</a>
<a id="nav_right" href="{% url 'stream' %}">Stream</a>
<a id="nav_right" href="{% url 'about' %}">About</a>
</div>
current css
.nav {
left: 0;
right: 0;
background-color: #FFFFFF;
position: fixed;
bottom 0px;
height: 20vh;
margin: 5px;
}
#nav_left {
float: left;
color: black;
}
#nav_right {
float: right;
color: black;
}
#diamond {
display: block;
margin-left: auto;
margin-right: auto;
max-width: 100%;
max-height: 100%;
}
Upvotes: 1
Views: 205
Reputation: 114989
Just change the source order would be the simplest method...then inline-block
and vertical-align:middle
.
.nav {
left: 0;
right: 0;
background-color: lightblue;
position: fixed;
bottom 0px;
height: 20vh;
margin: 5px;
text-align: center;
}
#diamond {
max-height: 100%;
width: auto;
}
.nav a,
.nav img {
display: inline-block;
vertical-align: middle;
margin: 0 1em;
}
<div class="nav">
<a class="nav_left" href="#">Home</a>
<a class="nav_left" href="#">Guides</a>
<img id="diamond" src="http://lorempixel.com/output/abstract-q-c-100-100-5.jpg" />
<a class="nav_right" href="#">Stream</a>
<a class="nav_right" href="#">About</a>
</div>
flexbox
has been mentioned and it would be possible to retain the original order of the question but the internal order would require some re-jigging.
.nav {
left: 0;
right: 0;
background-color: lightblue;
position: fixed;
bottom 0px;
height: 20vh;
margin: 5px;
text-align: center;
display: flex;
justify-content: space-around;
align-items: center;
}
.nav a {
order: 3
}
.nav a:nth-of-type(1) {
order: -1
}
.nav a:nth-of-type(2) {
order: 1
}
#diamond {
max-height: 100%;
width: auto;
order: 2;
}
<div class="nav">
<img id="diamond" src="http://lorempixel.com/output/abstract-q-c-100-100-5.jpg" />
<a class="nav_left" href="#">Home</a>
<a class="nav_left" href="#">Guides</a>
<a class="nav_right" href="#">Stream</a>
<a class="nav_right" href="#">About</a>
</div>
Upvotes: 1