Hi I'm trying to middle vertical align my site's logo with my navigation link list. I've tried adding "vertical-align: middle" to my div columns, but nothing happens. Right now my logo and my navigations look kinda weird and is just floating around. Any help on this would be great.
HTML:
<div class="sixteen columns clearfix">
<div class="five columns">
<a href="{{ shop.url }}" title="{{ shop.name }}">
{% if settings.use_logo %}
<img src="{{ 'logo.png' | asset_url }}" alt="{{ shop.name }}" />
{% else %}
{{ shop.name }}
{% endif %}
</a>
</div>
<div class="eleven columns">
<div id="mobile_nav"></div>
<div id="nav">
<ul id="menu">
{% for link in linklists[settings.main_linklist].links %}
{% if linklists[link.handle] == empty %}
<li><a href="{{ link.url }}" title="{{ link.title }}" {% if link.active %}class="active"{% endif %}>{{ link.title }}</a></li>
{% else %}
<li><a href="{{ link.url }}" title="{{ link.title }}" {% if link.active %}class="active"{% endif %} {% for link in linklists[link.handle].links %}{% if link.active %}class="active"{% endif %}{% endfor %}>{{ link.title }}
<span class="arrow">∨</span></a>
<ul>
{% for link in linklists[link.handle].links %}
{% if linklists[link.handle] == empty %}
<li><a href="{{ link.url }}" title="{{ link.title }}">{{ link.title }}</a></li>
{% else %}
<li><a href="{{ link.url }}" title="{{ link.title }}">{{ link.title }} <span class="arrow"> ></span></a>
<ul>
{% for link in linklists[link.handle].links %}
<li><a href="{{ link.url }}" title="{{ link.title }}">{{ link.title }}</a></li>
{% endfor %}
</ul>
</li>
{% endif %}
{% endfor %}
</ul>
</li>
{% endif %}
{% endfor %}
</ul>
</div>
</div>
</div>
Column CSS:
.column, .columns {
float: left;
display: inline;
margin-left: 10px;
margin-right: 10px;
vertical-align: middle;
}
Here's how it currently looks like:
Need to move it to the middle:
- Specify the parent container as
position: relative
orposition: absolute
.- Specify a fixed height on the child container.
- Set
position: absolute
andtop: 50%
on the child container to move the top down to the middle of the parent.- Set
margin-top: -yy
whereyy
is half the height of the child container to offset the item up.
( http://phrogz.net/CSS/vertical-align/ )
.columns
( position: relative
) or absolutely position it ( position: absolute
) .column
a height
value .column
( position: absolute
) , and give it top: 50%
.column
a top margin of the negative of half its height
value ( margin-top: -yy
where yy is half of the height of .column
) As you have already used vertical-align: middle
in class; so by just adding display: table-cell
property your problem must solved.
Note: There are many ways to align content or div vertically.. using line-height
(condition is only apply for first line), padding-top
, table-cell
and giving absolute
position.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.