I've got an SVG that I want to place next to some inline text as part of a navbar like so:
The problem now is that it's not inline with the SVG. It looks like this, overflowing out from the navbar:
Here's a snippet of my HTML (it's a bit large so click 'Show code snippet'):
.navbar {
height: 95px;
margin: 0;
padding-left: 50px;
padding-right: 50px;
box-shadow: 0 3px 4px grey;
list-style-type: none;
}
.navbar > li {
height: 100%;
float: right;
}
.navbar > .navbar-logo {
width: 75px;
height: 75px;
margin: 10px;
float: left;
font-family: 'Oswald', sans-serif;
font-size: 50px;
}
.logo-compass-frame {
fill: none;
stroke: black;
stroke-width: 20;
stroke-linecap: round;
stroke-miterlimit: 10;
}
.logo-compass-north, .logo-compass-south {
stroke: black;
stroke-width: 8;
stroke-miterlimit: 10;
}
.logo-compass-south {
fill: none;
}
.logo-compass-center {
fill: black;
stroke: black;
stroke-width: 3;
stroke-linecap: round;
stroke-miterlimit: 10;
}
<ul class="navbar">
<li class="navbar-logo">
<svg x="0px" y="0px" viewBox="0 0 272.6 272.6">
<circle class="logo-compass-frame" cx="136.3" cy="136.3" r="105.8"></circle>
<polygon class="logo-compass-north" points="138,63.6 123.8,110.5 138,134.5 152.2,110.5"></polygon>
<polygon class="logo-compass-south" points="138,209 152.2,162.1 138,138.1 123.8,162.1"></polygon>
<circle class="logo-compass-center" cx="138" cy="136.6" r="5.7"></circle>
</svg>
<span>Text</span>
</li>
</ul>
I got it to the desired inline state with position: absolute
on the span
of text. But that leaves the text outside the bounds of the li
.
How can I position the text inline with the SVG (without position: absolute
)? I want the li
to contain both the SVG and text within its bounds.
One possible solution could be to use
white-space: nowrap;
inside your .navbar-logo class. This avoid the line break you have.UPDATE
Here a solution using flex box model. This gives you more flexibility.
You can remove the middle and also the end wrapper if not need.
One of many possible solutions:
li
width larger, I made it 100%.float: left
.padding-top
to get it where you want to be.Your main problem is that you were, for some reason, setting the
<li>
to a narrow width:Just get rid of those width and height values. You don't need them. That width and height should be applied to the SVG instead.
The
vertical-align
is there to make the top of the text align with the top of the SVG. Plus we give the textline-height: 75px;
so that it automatically centres itself vertically with the SVG.End result
(After stripping out some other unnecessary bits)
Your issue is that either you put the
navbar-logo
class in the wrong place, or you put your height and width in the wrong place. You're applying your75px
dimensions on the container of the logo AND the text. Doing this is making the text wrap to the next line. Move the dimensions to the SVG and the text will want to sit next to it:Notable code being:
Sidenote: Text needs to be adjusted a bit, but it seemed outside the scope of the question.