Reputation: 2205
I have this <span>
that creates this below image output:
<li>
<a onClick={onSearchPageClick} role="presentation">
<span className="icon is-medium">
<i className="fas fa-search" />
</span>{' '}
Search
</a>
</li>
Image output:
Then I have this code using span
but text is under the icon:
<li>
<a onClick={onProfilePageClick} role="presentation">
<span className="icon is-medium">
<i className="fas fa-user" />
</span>{' '}
<div>
{authUser && Array.isArray(authUser.roles) && authUser.roles.includes(ROLES.USER) ? (
<div>Dashboard</div>
) : (
<div>Sign in</div>
)}
</div>
</a>
</li>
Please advice how to do this I have tried for hours
Upvotes: 0
Views: 113
Reputation: 2562
here is a working example: https://codesandbox.io/s/zen-sky-zh5tg?file=/src/App.js:0-531
In order to create a working example I have removed some of the logic that was posted in the original code
the code just utilizes flex box:
<li style={{ listStyleType: "none" }}>
<a onClick={() => console.log("clicked")} style={{ display: "flex", alignItems: "center" }}>
<span className="icon is-medium">
<div style={{ marginRight: 5 }}>avatar</div>
</span>
<div>{authUser ? <div>Dashboard</div> : <div>Sign in</div>}</div>
</a>
</li>
Upvotes: 1
Reputation: 8118
Don't change anything in your code. Just add these CSS flexbox properties on anchor tag.
li a{
display:flex;
align-items:center;
justify-content:center;
}
In fact this will align your icon
and sign in
text exactly to the center both horizontally and vertically.
Upvotes: 1
Reputation: 358
The <span>
tag is rendered inline, whereas the <div>
tag is not. You can either use <span>
or you can style your <div>
, like:
<div style={{display: 'inline'}}>
// your code goes here
</div>
Upvotes: 2