UL/LI CSS menu not aligning properly - html

I am having issues getting my menu to align properly. The images are all spaced far away from each other even when they should be closer. I am new to using Ul and Li and am not sure how to fix this. Ideally I would have the images across the whole screen with no space on the right or left and just a thin space between each image, but instead, there is a large space. I am unsure if this is something in the Ul Li tags or if there is something I can do with margin.
Could someone please advise me. I am including a jsfiddle to show what it currently looks like. https://jsfiddle.net/f1bctqzn/ is what I am currently getting. How do I these lines to touch their respective sides of the screen and still have a small space between the rest.
<li class="header"><img src="https://i.imgur.com/T4ZAaK3.png" class ="kale-grain-bowls"></li>
<li class="header"><img src="https://i.imgur.com/T4ZAaK3.png" class ="kids-real-meals"></li>

Add padding: 0 to your ul and margin: 1px (or something) to li
Also, add width: 100% to img

See this fiddle
To add space betwwen the li items, don't add the margin property to the ul, but add a margin to the li items (I used the 2px you had set for the ul). To add a margin only between the li items, I used
li.header{
margin-left:2px;
}
li.header:first-child{
margin-left: 0;
}

Adjusted the margins and used a flexbox to adjust the images across the whole screen.
Check it out and let me know your feedback. Thanks!
body {
margin: 0;
padding: 0;
}
ul.toplist {
list-style: none;
padding: 0;
width: 100%;
display: flex;
flex-direction: row;
justify-content: space-between;
}
li.header {
display: inline-block;
height: 100%;
margin-right: 1px;
}
img.kale-grain-bowls,
img.salads,
img.burgers-sandwiches,
img.sides,
img.smoothies-milkshakes,
img.kids-real-meals {
max-width: 100%;
max-height: 100px;
}
<ul class="toplist">
<li class="header">
<a href="/menu/kale-grain-bowls">
<img src="https://i.imgur.com/T4ZAaK3.png" class="kale-grain-bowls">
</a>
</li>
<li class="header">
<a href="/menu/salads">
<img src="https://i.imgur.com/T4ZAaK3.png" class="salads">
</a>
</li>
<li class="header">
<a href="/menu/burgers-sandwiches">
<img src="https://i.imgur.com/T4ZAaK3.png" class="burgers-sandwiches">
</a>
</li>
<li class="header">
<a href="/menu/sides">
<img src="https://i.imgur.com/T4ZAaK3.png" class="sides">
</a>
</li>
<li class="header">
<a href="/menu/smoothies-shakes">
<img src="https://i.imgur.com/T4ZAaK3.png" class="smoothies-milkshakes">
</a>
</li>
<li class="header">
<a href="/menu/kids-real-meals">
<img src="https://i.imgur.com/T4ZAaK3.png" class="kids-real-meals">
</a>
</li>
</ul>

Related

Displaying rows of images on 100% width

I need to display images in my grid with the following idea: every li elements of each ultag should stay in the same row and be 100% width of the container.
As you can see in the jsfiddle, for the demo, I created 3 ul. So I would like 3 rows of images.
The jsfiddle: is here
The final result should be like below:
I don't know how to proceed so that every row takes 100% width.
So every row (ul) may contains 1, 2, 3, 4 or 5 images.
every li elements of each ultag should stay in the same row and be 100% width of the container
You needs to use Flexbox
Result
ul {
display: flex;
justify-content: space-between;
list-style: none;
margin: 0;
padding: 0;
margin-bottom: 3px;
}
li {
flex-grow: 1;
}
li+li {
margin-left: 3px;
}
img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
}
<ul>
<li>
<img src="https://via.placeholder.com/250x200?text=A1">
</li>
<li>
<img src="https://via.placeholder.com/150x200?text=A2">
</li>
<li>
<img src="https://via.placeholder.com/350x200?text=A3">
</li>
</ul>
<ul>
<li>
<img src="https://via.placeholder.com/200x200?text=B1">
</li>
<li>
<img src="https://via.placeholder.com/300x200?text=B2">
</li>
<li>
<img src="https://via.placeholder.com/150x200?text=B3">
</li>
</ul>
<ul class="fivePerRow">
<li>
<img src="https://via.placeholder.com/250x200?text=C1">
</li>
<li>
<img src="https://via.placeholder.com/150x200?text=C2">
</li>
<li>
<img src="https://via.placeholder.com/350x200?text=C3">
</li>
<li>
<img src="https://via.placeholder.com/200x200?text=C4">
</li>
<li>
<img src="https://via.placeholder.com/300x200?text=C5">
</li>
</ul>
And same code on JSFiddle
I think using Flexbox will do the job.
ul {
width: 100%;
list-style: none;
display: flex;
justify-content: space-between;
}
li {
display: inline-block;
vertical-align: top;
}
Codepen Demo

How to split my list into two sections on navigation bar?

I'm trying to split my navigation bar into two (with one part going left and the other right). When trying to get the items I want on the left side, I'm left with a small gap between the items and the wall. Where as, the right side hits the wall of the green and meshes.
**Kinda new to this posting thing so if you need more information on the code please be sure to respond*
Here is the JSFiddle: https://jsfiddle.net/2dkhrjg8/2/
Here is the HTML:
<div id="navbar">
<div class="table">
<ul>
<a class="" href=""><li class="main-nav">Home</li></a>
<li class="main-nav">about</li>
<a target="_blank" href=""><li class="main-nav">where</li></a>
<li class="main-nav">team</li>
<li class="main-nav">Help</li>
<li id="right-side" class="sign-in">Sign In</li>
<li id="right-side" class="sign-up">Sign Up!</li>
</ul>
</div>
</div>
Here is the CSS:
#navbar{
position: relative;
table-layout: fixed;
width: 100%;
border-collapse: separate;
background-color: green;
}
.table{
display: table;
margin: 0 auto;
width: 60%;
overflow: auto;
height: 20px;
background-color: red;
}
#navbar li{
display: inline
}
.main-nav{
float:left;
}
#right-side{
float: right;
vertical-align: middle;
}
Okay. The thing is that your HTML it's not semantically correct.
I would suggest using flexbox since it is super easy to do it.
Check the modified HTML and if I understood, this is what you want to achieve.
Wish you happy styling and if need any more help just right
.navbar {
display: flex;
justify-content: space-between;
}
.main-nav:hover{
background-color: #eff0f1;
}
<div id="navbar">
<ul class='navbar'>
<li class="left-side">
<a class="" href="#">Home</a>
About
<a target="_blank" href="#">Where</a>
Team
Help
<input id="nav-search-bar" type="text" placeholder="Search..." />
</li>
<li class="right-side">
Sign In
Sign Up!
</li>
</ul>
</div>

HTML lists and z-index on content of li

I am trying to solve an issue. I have a regular list. Within the li's I have a overlapping div, witch appears on a hover. The problem is, that the hover is always overlapped by the next li. How can i make it happen, that the content of the next li stays below the hovered div. Html and css seems to stack li's? Is this a know problem?
I already tried z-index, but that will not work on child elements.
Its impossible to add the complete code, but this basically shows it. Why is the next li-element always overlapping the last and how can I get around this?
li {
position: relative;
width: 100px;
}
img {
width: 120%;
height: auto;
position: absolute;
top: 0;
border: 1px solid red;
}
<ul>
<li style="z-index:1;"><!-- list-element 1 -->
<div style="z-index:4;"><img src="http://img.brothersoft.com/screenshots/softimage/f/free_cat_wallpaper-407575-1285474870.jpeg" style="width:100%;" /></div>
</li>
<li style="z-index:1;"><!-- list-element 2 -->
<div style="z-index:4;"><img src="http://img.brothersoft.com/screenshots/softimage/f/free_cat_wallpaper-407575-1285474870.jpeg" style="width:100%;" /></div>
</li>
<li style="z-index:1;"><!-- list-element 3 -->
<div style="z-index:4;"><img src="http://img.brothersoft.com/screenshots/softimage/f/free_cat_wallpaper-407575-1285474870.jpeg" style="width:100%;" /></div>
</li>
</ul>
Thanks
/* EDIT: My Mistake - I misunderstood your question. */
Do the positioning on the .img-wrapper. (code snippet updated below too)
See this fiddle: https://jsfiddle.net/tqtveoau/4/
/* END EDIT */
I'm guessing this isn't your production code but always try and use classes for your styles.
.list-item {
position: relative;
width: 100px;
}
.img-wrapper {
display: none;
position: absolute;
top: 0;
z-index: 1;
}
.img-wrapper img {
width: 120%;
border: 1px solid red;
}
.list-item:hover .img-wrapper {
display: block;
}
<ul>
<li class="list-item">
List Item
<div class="img-wrapper">
<img src="http://img.brothersoft.com/screenshots/softimage/f/free_cat_wallpaper-407575-1285474870.jpeg" style="width:100%;" />
</div>
</li>
<li class="list-item">
List Item
<div class="img-wrapper">
<img src="http://img.brothersoft.com/screenshots/softimage/f/free_cat_wallpaper-407575-1285474870.jpeg" style="width:100%;" />
</div>
</li>
<li class="list-item">
List Item
<div class="img-wrapper">
<img src="http://img.brothersoft.com/screenshots/softimage/f/free_cat_wallpaper-407575-1285474870.jpeg" style="width:100%;" />
</div>
</li>
</ul>
See the fiddle here:
https://jsfiddle.net/tqtveoau/3/
Move the styles from your img to the parent div and give it a class. Also set the background of the div that's absolute to white

How can I make my header completely inline using float?

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.

Center inline block images

I need some help centering some images
HTML:
<div id="thumbs" class="navigation">
<ul class="thumbs noscript">
<li>
<a class="thumb" href="#">
<img src="http://farm4.static.flickr.com/3261/2538183196_8baf9a8015_s.jpg" />
</a>
</li>
<li>
<a class="thumb" href="#">
<img src="http://farm4.static.flickr.com/3261/2538183196_8baf9a8015_s.jpg" />
</a>
</li>
<li>
<a class="thumb" href="#">
<img src="http://farm4.static.flickr.com/3261/2538183196_8baf9a8015_s.jpg" />
</a>
</li>
<br>
<li>
<a class="thumb" href="#">
<img src="http://farm4.static.flickr.com/3261/2538183196_8baf9a8015_s.jpg" />
</a>
</li>
<li>
<a class="thumb" href="#">
<img src="http://farm4.static.flickr.com/3261/2538183196_8baf9a8015_s.jpg" />
</a>
</li>
CSS:
ul.thumbs {
clear: both;
padding-left: 0px;
}
ul.thumbs li {
display: inline-block;
/*float: left;*/
padding: 0;
margin: 5px 10px 5px 0;
list-style: none;
}
a.thumb {
padding: 2px;
display: block;
border: 1px solid #ccc;
}
ul.thumbs li.selected a.thumb {
background: #DAA12F;
}
a.thumb:focus {
outline: none;
}
ul.thumbs img {
border: none;
display: block;
height: 120px;
width: 120px;
margin: 0px auto;
}
I need the images be centered together so that they remained lined up. Ive tried using:
ul.thumbs {
text-align:center;
}
but since there are a different number of images on each row, they move out of alignment
Thanks for the help, this is driving me crazy
EDIT: I thought I found a solution using this as a guide: http://www.tightcss.com/centering/center_variable_width.htm but if the images go over more than row, they no longer center. Originally I put a br tag to break up the rows and that fixes the problem, but a JS library Im using doesnt play nice with br tags between list items. Any suggestions (you can see the issue here http://jsfiddle.net/HvZva/26/)
There is two solutions to this, one is if you want your images to be centered and the another is if your images should be aligned left, but centered on the page.
Center block, left align images
To do this you need to add the following to your css (or see: http://jsfiddle.net/HvZva/20/)
ul.thumbs{
margin:0 auto;
width:416px;
}
what I do is basicly to tell the browser that this un ordered list should have an equal margin to both sides. But since this object has an width of 100% as standard, we need to specifiy that aswell, and in this case it is 416px.
Center align images
If this is static content, one easy way to do this is to add a div with the class of center that wraps each line, and then adding "text-align:center;" to those divs, that will do the trick.
note: there is one new way to center the block, but aligning the images to the left. but that involves the box flex model and css 3, and it has not yet been implemented by browsers yet
Applying text-align: center; to .thumbs.noscript ul fixes it in the jsfiddle
You can give the parent element a width and apply margin-left: auto; margin-right: auto;
http://jsfiddle.net/HvZva/13/
ul.thumbs {
display:inline-block;
text-align:center;
}
Something like this? http://jsfiddle.net/HvZva/11/
I may have mis interpreded your issue but is it something like this you want?
http://jsfiddle.net/HvZva/12/