I created a little test website with UIKit. Now that I messed around with that I wanted to try and create the design without using a pre-made framework. I am having issues with my navbar though.
This is the Original navbar that was created on the UIKit, see how the text is aligned vertically with the middle of the logo.
This is the second image, which is the Navbar i am trying to create, as you can see the text is on the same row as the image, but it is aligned with the top of the image (logo)
I am Trying to make the second image like the first image, the text aligned with the centre of the logo. I have tried "vertical-align: middle;" in my css but it doesn't seem to work... Any ideas?
Here's my code:
html {
font-family: monospace;
font-size: 12pt;
}
body {
margin: 0;
}
header {
background-color: honeydew;
}
nav .ul {
list-style-type: none;
display: table;
margin: 0;
padding: 0;
overflow: hidden;
float: left;
vertical-align: middle;
}
li {
display: table-cell;
vertical-align: middle;
}
<header>
<div class="row">
<nav>
<ul class="column small-hidden large-12">
<li class="column small-hidden large-3"> </li>
<li class="column small-hidden large-1">Yep</li>
<li class="column small-hidden large-1">Yep</li>
<li style="float: center;" class="column small-hidden large-1 logo"><img alt="Website Logo" src="img/image.png"></li>
<li class="column small-hidden large-1">Yep</li>
<li class="column small-hidden large-1">Yep</li>
<li class="column small-hidden large-3"> </li>
</ul>
</nav>
</div>
</header>
Thanks in advance!
You can try this:
nav li.img{ vertical-align: middle;}
Related
I am trying to add icons to my menu items. I have read many different tutorials on it, but the css that all tutorials recommend will not work for me, and I'm not sure what to do.
Here is my html and css:
<div class="hike-menu">
<ul>
<li class="icon">Menu Item 1</li>
<li class="icon">Menu Item 2</li>
<li class="icon">Menu Item 3</li>
<li class="icon">Menu Item 4</li>
</ul>
</div>
ul li {
list-style-type: none;
display: inline-block;
}
.icon {
background-image: url("https://i.postimg.cc/ZWW7qTmm/calendar-yellow-copy.png");
background-repeat: no-repeat;
background-position: top;
}
And I have also uploaded in onto a jfiddle if you would like to take a look. You can see the exact problem I am having with the icon not showing. https://jsfiddle.net/katherinekonn/g1e4cok3/5/
I should also note that it is absolutely necessary I use background-image for this, I am unable to place an img link directly into the html. Does anyone know how I can fix it? I would like the icon to be above the list items text.
Here is an image of what I am trying to create:
The main issue is related to the size of the icon you used. The actual size is much bigger than you required. So either you resize the image or apply background image size in css. Then apply some padding-top for the <LI> to avoid overlapping of text and icon.
I tried modifying your css in fiddle and it worked perfect for me. please see it below
ul li {
list-style-type: none;
display: inline-block;
}
.icon {
background-image: url("https://i.postimg.cc/ZWW7qTmm/calendar-yellow-copy.png");
background-size: 20px;
background-repeat: no-repeat;
background-position: top;
padding-top: 30px;
}
Please try this. It will work.
HTML
<div class="hike-menu">
<ul>
<li class="element">
<div class="icon">
</div>
<div class="text">
Menu Item 1
</div>
</li>
<li class="element">
<div class="icon">
</div>
<div class="text">
Menu Item 2
</div>
</li>
<li class="element">
<div class="icon">
</div>
<div class="text">
Menu Item 2
</div>
</li>
<li class="element">
<div class="icon">
</div>
<div class="text">
Menu Item 2
</div>
</li>
</ul>
</div>
CSS
ul li {
list-style-type: none;
display: inline-block;
}
.icon {
background-image: url("https://i.postimg.cc/ZWW7qTmm/calendar-yellow-copy.png");
background-repeat: no-repeat;
background-position: top;
background-size: cover;
display: block;
width: 24px;
height: 24px;
margin: 0 auto;
}
.text {
display: block;
}
I am using bootstrap grid system.
I have 3 grids which aligned center:
<div id="jumbotron">
<div class="container">
<div class="row row-centered">
<div class="col-md-4 col-centered">
<p>
Logo
</p>
</div>
<div class="col-md-4 col-centered">
<h3>
Some text
<h3>
</div>
<div class="col-md-4 col-centered">
<ul class="list">
<li>
<img src="img_url"/>
<a class="phones" href="+1-380-555-5555">+13805555555</a>
</li>
<li>
<img src="img_url"/>
<a class="phones" href="+1-380-555-5555">+13805555555</a>
</li>
<li>
<img src="img_url"/>
<a class="phones" href="+1-380-555-5555">+13805555555</a>
</li>
</ul>
</div>
</div>
</div>
</div>
and CSS looks like:
.row-centered {
text-align: center;
}
.list {
text-decoration: none;
color: #f1f0e9;
font-size: 20px;
font-family: 'Trirong', serif;
list-style-type: none;
text-align-last: right;
}
In third grid I have which I want to be aligned right.
text-align: right helps, but when I switch to mobile mode bootstrap makes grids in a column and third grid become right aligned(two others centered).
So I need that third grid will come right aligned but inside parent grid which has center align. Is it possible?
Try add a pull-right class to those you want right
Remove text-align-last: right; property because it's not affect to the a tag inside li. Use .list:last-child a will select the last li tag and affect to its a tag.
.row-centered {
text-align: center;
}
.list {
text-decoration: none;
color: #f1f0e9;
font-size: 20px;
font-family: 'Trirong', serif;
list-style-type: none;
/*text-align-last: right;*/
}
.list li:last-child a{
text-align: right;
}
Answer:
I have separated columns on two <ul class = "list"> objects and add
display: inline-block;
*display: inline;
properties to list class.
I want to create a navbar with a logo in the center, and two navbar items (links) on either side, width equal spacing. I also need the logo to be lined up center with the navbar items.
Here's the code i have thus far. I'm using bootstrap.
HTML:
<div class="nav">
<div class="container">
<ul>
<li> Navbaritem1 </li>
<li> Navbaritem2 </li>
</ul>
<div class="logo">
<img src="Img/logo.png" class="img-responsive">
</div>
<ul>
<li> Navbaritem3 </li>
<li> Navbaritem4 </li>
</ul>
</div>
</div>
CSS:
.nav li {
display: inline;
margin-left:5%;
margin-right:5%;
}
.logo {
width: 100px;
display: inline-block;
height: auto;
}
.logo img {
float: none;
padding-top:10%;
}
ul {
display: inline;
text-align:center;
width:30%;
}
Did you try centering a div inside the container?
<div class="container">
<div class="center">
Centered content here
</div>
</div>
And the css:
.center {
display: table;
margin: 0 auto;
}
Also this post might've helped you with a quick search.
I have some HTML, and I am trying to figure out a way to make my logo, nav menu and social media icons one a single line.
<div class="header">
<div class="logo"><h1>Logo</h1></div>
<ul class="nav">
<li class="menuitem">Home</li>
<li class="menuitem">Blog</li>
<li class="menuitem">Test</li>
<li class="menuitem">Contact</li>
</ul>
<div class="social-media">
<img src="facebook.jpg">
<img src="twitter.jpg">
<img src="pinterest">
</div>
</div>
I want to logo to the left, nav menu in the middle, and the social media icon to the right.
I just realized that I forgot to post my CSS:
div .h1 {
float: left;
}
li {
display: inline-block;
}
ul {
float: left;
}
.nav {
float: left;
}
The easiest way to achieve this is text-align: justify:
Take a look at this Fiddle
Another good Tutorial for this effect is found on Codrops.
I have been trying to figure this little bugger out for a little while, and now I seek some expertise. What am I trying to do? I want to create a 100% width menubar, but keep the logo, and the content centered so it can fit in with the rest of the content. The container is on 1000px. Right now I have placed my menu outside of the container tag, and used "width: 100%" to get it to cover the screen. However with that the content moves to the left. I don't really know how to fix this, I have been working on it for a while.
Here is my HTML code:
<body>
<!-- navigation / header -->
<div class="grid_12" id="menu">
<div class="grid_3" id="logo">
<img src="img/logo.png" alt="logo" />
</div>
<div class="grid_9 omega">
<ul class="nav">
<li>
<label>
Features
<br />Check our features
</label>
</li>
<li>
<label>
Pricing
<br />Starts at $X/month
</label>
</li>
<li>
<label>
30-day free trial
<br />Start using us right away
</label>
</li>
<li class="sign-btn">
Log in
</li>
</ul>
</div>
</div>
<div class="container clearfix">
and here is my css file:
#menu {
width:100%;
margin: 0 0 0 0;
padding: 0;
background: #1d3853;
color: white;
font-size: 13px;
}
.nav li {
padding-top: 15px;
list-style:none;
float: left;
text-align: center;
margin-right: 20px;
}
.nav li a {
color: #a7c5e3;
font-family: helvetica;
font-weight: bold;
letter-spacing: 1px;
}
.sign-btn a {
color: #FFF;
display: block;
background: #105296;
padding: 10px 15px;
text-align: center;
border-radius: 5px;
border: 1px solid white;
}
So I ask again, dear StackOverflow... how do I get my links in the center with the rest of my content. Like this picture: http://www.cssnewbie.com/wp-content/uploads/2009/12/centered-navbar-sketch.png
write your navigation code inside another div with class=container.
That is
<body>
<div class="container">
<!-- your navigation code here-->
</div>
</body>
To center something with a set width, add the style margin:auto. To be more precise, you only need margin-left:auto and margin-right:auto to give equal padding to an element inside a container.