Hello once again Stackoverflow,
I have a flex-container with one large image (960x660) with 6 li elements similar to tabs on the side of it that line up with the images height(pic here- https://imgur.com/zSqFNmx). I would like the entire container to scale the same way that the image does. I have the image on the left set to a width of 100%. However I have the li elements width explicitly set by px(wrong of course). Which gives me this when I resize my window (pic- https://imgur.com/3RrVpZs).
My question is what is the best route to go so that I get all of the LI elements and text within to resize alongside the image to the left. Basically I want the entire container to be able to scale down completely. All while still lining up with the image at its full height.
Ive included a code pen example however the images do not work the same way im guessing due to the code pen frame around all of it?
HTML
<!-- HEADER START -->
<div id="flexContainer">
<div id="bigImage">
<img src="http://getdrawings.com/colorings/marvel-deadpool-coloring-pages-10.jpg">
</div>
<ul class="flexUL">
<li class="vm_clickable" id="organic" data-src="http://getdrawings.com/colorings/marvel-deadpool-coloring-pages-10.jpg" data-url="/organic"> Organic </li>
<li class="vm_clickable" id="glutenFree" data-src="https://www.bemea.com/wp-content/uploads/2018/11/Hero_SPE-V3_960x660.jpg" data-url="/gluten-free-shopping"> Gluten-Free </li>
<li class="vm_clickable" id="sugarFree" data-src="https://cdn.wallpapersafari.com/25/1/0yt8rf.jpg" data-url="/productsearch.aspx?rid=1041.05"> Sugar-Free</li>
<li class="vm_clickable" id="vegan" data-src="https://1iu5gpsjoqnqr.wpcdn.shift8cdn.com/wp-content/uploads/2019/09/960x660-SoWalWIne-1.jpg" data-url="/vegan"> Vegan </li>
<li class="vm_clickable" id="keto" data-src="https://cdn.wallpapersafari.com/66/32/4YHl2n.jpg" data-url="/keto-diet-essentials"> Keto </li>
<li class="vm_clickable" id="paleo" data-src="https://static.zerochan.net/Frozen.(Disney).full.1819021.jpg" data-url="/paleo"> Paleo </li>
</ul>
</div>
</div> <!-- deal wrapper end -->
CSS
#flexContainer {
display: flex;
width:100%;
height:auto;
flex-wrap:nowrap;
}
#bigImage > img{
width: 100%;
}
.flexUL{
display: flex;
flex-direction: column;
flex-wrap:nowrap;
}
.flexUL > li {
height: 100px;
width:320px;
}
.flexUL > li > a{
color: white;
font-size: xx-large;
margin-left: 20px;
}
.flexUL > li:hover > a:after{
content: '\203A';
font: 300 36px/18px "Roboto Slab";
margin-left: .2em;
height: 24px;
vertical-align: middle;
display: inline-block;
color: white;
}
#organic{
background-color: #ccb3d1;
}
#organic:hover{
background-color: #B7A1BC;
}
#glutenFree{
background-color: #e7b020;
}
#glutenFree:hover{
background-color: #CF9D1C;
}
#sugarFree{
background-color: #f07f53;
}
#sugarFree:hover{
background-color: #D8724A;
}
#vegan{
background-color: #889a2c;
}
#vegan:hover{
background-color: #7A8A27;
}
#keto{
background-color: #f49382;
}
#keto:hover{
background-color: #DB8475;
}
#paleo{
background-color: #9e5860;
}
#paleo:hover{
background-color: #8E4F56;
}
/* MEDIA QUERIES */
https://codepen.io/gchis66/pen/gOPqoeX
Any help is appreciated. Something tells me im missing very obvious solutions
Related
I'm trying to keep my logo "Reservia" and my LI "S'inscrire" on the same line and wrap my 2 other LI "Hebergement" and "Activités" on a line under this first one but it doesn't work.
Here is my Header
<header>
<div id="containerHeader">
<img src="images/logo/Reservia.svg" class="test" alt="Logo reservia">
<nav class="Navmenu">
<ul class="liMenu">
<li class="liMenu--list liMenu--list_nocolor">
Hebergement
</li>
<li class="liMenu--list liMenu--list_nocolor">
Activités
</li>
<li class="liMenu--list liMenu--list_blue">
S'inscrire
</li>
</ul>
</nav>
</div>
</header>
And here is my CSS
#containerHeader{
flex-wrap: wrap;
}
.navMenu,
.liMenu {
justify-content: center;
padding-right: 80px;
}
.liMenu--list {
list-style: none;
}
.test{
order: -1;
}
.link--navbar {
border-bottom: 4px solid lightgrey;
border-top: none;
padding-bottom: 15px;
}
.link--navbar:hover {
border-top: none;
}
And I put my 2 screenshots ( what it looks like and what I want ) :)
Thanks a lot
img, li {
width: 50%
}
Try adding 50% width to the img and li elements. This will ensure that a single element takes up half the width, which will result in two elements per row.
You may need to use media queries if you want a different look for different devices.
This question already has an answer here:
Why does clip-path (and other properties) affect the stacking order (z-index) of elements later in DOM?
(1 answer)
Closed 2 years ago.
I made my navigation bar and positioned it (fixed), and it works fine. I was able to scroll down and all. As soon has I added filter (brightness) to it the image on my page, the navigation bar disappeared. I have tried using pseudo-elements and setting the position (absolute/relative), I set the filter property to the container of the child element of the image, it still didn't work. Can someone help me on how to have my navigation bar display on fixed position and still have the image filtered. Thanks in Advance.
nav {
position: fixed;
background-color: #fff;
}
nav ul {
margin: 0;
padding: 0;
}
.navbar-brand {
padding-right: 20px;
}
nav li {
display: inline-block;
padding: 10px;
}
nav a {
color: #000;
text-decoration: none;
}
nav a:hover {
color: #ff6600;
text-decoration: none;
}
.title-image img {
width: 100%;
height: 300px;
filter: brightness(60%);
}
<nav>
<ul>
<li>
<a class="navbar-brand" href="#">Navbar Brand</a>
</li>
<li>
Home
</li>
<li>
About
</li>
<li>
services
</li>
</ul>
</nav>
<div class="title-image">
<img src="https://images.unsplash.com/photo-1599546824091-f49550ce8cbc?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60">
</div>
JSfiddle Demo
Just add z-index to your nav element as follow
nav{
position: fixed;
background-color: #fff;
z-index:999;
}
nav ul{
margin: 0;
padding: 0;
}
.navbar-brand{
padding-right: 20px;
}
nav li{
display: inline-block;
padding: 10px;
}
nav a{
color: #000;
text-decoration: none;
}
nav a:hover{
color: #ff6600;
text-decoration: none;
}
.title-image img{
width: 100%;
height: 300px;
filter: brightness(60%);
}
<nav>
<ul>
<li>
<a class="navbar-brand" href="#">Navbar Brand</a>
</li>
<li>
Home
</li>
<li>
About
</li>
<li>
services
</li>
</ul>
</nav>
<div class="title-image">
<img src="https://images.unsplash.com/photo-1599546824091-f49550ce8cbc?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60">
</div>
The navbar didn't disappear, it is just beneath the image. To have it in front, you should use z-index: 10; (or any value greater than 0).
See more at : https://developer.mozilla.org/en-US/docs/Web/CSS/z-index
In addition, keep in mind that your image - or any element after your navbar - will be positioned on top of your page. May be you'll want to let the equivalent of the navbar height as space before any content.
I have a navigation bar with image in the middle. Looks similar to this:
<nav class="navigation">
<ul class="navigation-list-1">
<li class="navigation-list-item">Home</li>
<li class="navigation-list-item">Features</li>
<li class="navigation-list-item">Add info</li>
<li class="navigation-list-item"><img class="logo" src="https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.svg?v=6f4af2d2d158"></li>
<li class="navigation-list-item">Form</li>
<li class="navigation-list-item">Team</li>
<li class="navigation-list-item">Contact</li>
</ul>
And style:
> .navigation-list-item {
list-style: none;
font-size: 15px;
font-weight: bold;
}
.logo {
position:absolute;
width: 10vw;
left:calc(50% - (10vw/2) - (10px/2));
background: cornflowerblue;
border: 5px solid cornflowerblue;
}
ul{
display:flex;
margin-left:-40px;
}
li{
flex:1;
background:yellow;
border:1px solid green;
height:70px;
line-height:70px;
text-align:center;
}
li>a{
text-decoration:none;
}
Now, if text in navigation item is longer than particular length, the text is spliting into next line and going outside the bar so it doesn't look good. How to make text in container always to be in one line?
Good option for start is to add css style for text: white-space: nowrap;
Another good way is to set the font-size in vw units. Font will be responsive depending on screen size.
Here is the fiddle:
https://jsfiddle.net/5jnnutg8/
My question is how can I align the "something #" list items as center and inline. One can see the "Hi" title is aligned in the center using text-align: center in css, but this doesn't seem to work for the list items.
Is there a pure css way of doing this without messing around with the <div>, <ul>, and <li> structure, as I am using a plugin for wordpress and it would be a pain to change this.
I want it to be that the "something #" list items are centered aligned, and if the browser is resized the "something 3" drops down but is still centered -- hope that makes sense.
Thanks!
Do not use float: left, simply use display: inline-block;
li {
display: inline-block;
}
Working demo
.list-holder {
background: black;
height: 100px;
color: white;
text-align:center;
}
.div-list-item {
background: red;
color: black;
margin-left: 10px;
}
.ul-class {
list-style: none;
padding: 0;
}
li {
display: inline-block;
}
a {
display: black;
}
<div class="list-holder">
Hi
<ul class="ul-class">
<li class="li-class">
<div class="div-list-item">
Something 1
</div>
</li>
<li class="li-class">
<div class="div-list-item">
Something 2
</div>
</li>
<li class="li-class">
<div class="div-list-item">
Something 3
</div>
</li>
</ul>
</div>
I have a list of 4 menu items sitting side by side using display:inline-block;. Each item is 120px, therefore I should be able to set the parent container to be 480px wide, however this sends the last item into the next row, why is this ??
Here is a jsfiddle :http://jsfiddle.net/htdgdhxn/
My html:
<section id="nav">
<div id="nav-wrapper">
<ul id="nav-list">
<li id="nav-home">Home
</li>
<li id="nav-clothes"><a class="category All">Clothes</a>
</li>
<li id="nav-about">About Us
</li>
<li id="nav-contact">Contact Us
</li>
</ul>
</div>
</section>
CSS:
* { margin: 0px; padding: 0px; }
#nav { background-color: #fff; }
#nav-wrapper { text-align: center; height: 74px; }
#nav-list { height: 100%; width: 480px; }
#nav-list li { display: inline-block; vertical-align: top; width: 120px; height: 100%; }
#nav-list li a { text-decoration: none; color: #000; font-size: 1.6em; display: block; height: 100%; line-height: 74px; }
#nav-list li a:hover { background-color: #F0ECE1; cursor: pointer; }
I have tested and this happens in Chrome, IE and Firefox.
Remove the whitespace between each <li>
<li></li> <...space here...> <li></li>
Inline block elements create a gap between li elements.
<ul id="nav-list">
<li id="nav-home">Home
</li><li id="nav-clothes"><a class="category All">Clothes</a>
</li><li id="nav-about">About Us
</li><li id="nav-contact">Contact Us
</li>
</ul>
See fiddle
The inline-block value is incredibly useful when wanting to control margin and padding on
"inline" elements without the need to block and float them.One problem that arrises
when you use inline-block is that whitespace in HTML becomes visual space on screen.
Gross.There are a few ways to remove that space; some of them are just as gross, one is
reasonably nicer.
Solution 0: No Space Between Elements:
The only 100% solution to this issue is to not put whitespace between those elements in the HTML source code:
<ul><li>Item content</li><li>Item content</li><li>Item content</li></ul>
Solution 1: font-size: 0 on Parent
The best white-space solution is to set a font-size of 0 on the parent to the inline block
elements.
.inline-block-list { /* ul or ol with this class */
font-size: 0;
}
.inline-block-list li {
font-size: 14px; /* put the font-size back */
}
Solution 2: HTML Comments
This solution is a bit gangsta but also works. Using HTML comments as spacers between the elements works just as placing no space between elements would:
<ul>
<li>Item content</li><!--
--><li>Item content</li><!--
--><li>Item content</li>
</ul>
It might help you.
Just increase the width of your container to 500px
#nav-list { height: 100%; width: 500px; }
or remove the white spaces between consecutive li tags
or
apply display:initial in #nav-list { height: 100%; width: 480px;}
i.e #nav-list { height: 100%; width: 480px; display: initial;}
Reason:-
1. The font size of the text in the li element might be causing the problem.
You can modify it by reducing the font-size.
#nav-list li a { text-decoration: none; color: #000; font-size: 1.2em; display: block; height: 100%;line-height: 74px; }
Instead of using this
#nav-list li { display: inline-block; }
You can do like this:-
#nav-list li { display: inline; font-weight:bold;}
Please let me know if this helps.