Extend element beyond container, but keep children within container - html

I've recently had a problem, where I want to keep all my content within a parent container, but I want the navigation background to be 100% of the width of the page. The methods I've tried have worked in terms of getting the navigation to be 100% width of the page, but now the ul inside isn't affected by the container, which is what I originally wanted.
I got it to work by using another container div inside the navigation, but I feel like this is a very makeshift method.
Any suggestions on how to get the parent container to affect the ul inside the nav?
HTML:
<div class="container">
<nav class="menu">
<div class="container">
<ul>
<li>HOME</li>
<li>ABOUT ME</li>
<li>SERVICES</li>
<li>CURRENT PROJECT</li>
<li>PORTFOLIO</li>
<li>CONTACT ME</li>
</ul>
</div>
</nav>
</div>
CSS:
.container {
margin: 0 auto;
width: 1200px;
}
.menu {
left: 0;
right: 0;
height: 80px;
position: fixed;
background-color: rgb(33, 33, 33);
}
.menu ul {
padding: 0;
margin: 0;
color: #fff;
list-style: none;
font-weight: bold;
height: 80px;
float: right;
}
.menu ul li {
display: inline-block;
padding-right: 50px;
}

You can use :before or :after pseudo selector for creating background effect that looks like having width equal to the width of the page.
body {
overflow: hidden;
width: 100%;
margin: 0;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
.menu {
height: 80px;
position: relative;
}
.menu:before {
background-color: rgb(33, 33, 33);
position: absolute;
right: -9999px;
left: -9999px;
content: '';
z-index: -1;
bottom: 0;
top: 0;
}
.menu ul {
padding: 0;
margin: 0;
color: #fff;
list-style: none;
font-weight: bold;
float: right;
}
.menu ul li {
display: inline-block;
padding-right: 50px;
}
.menu ul li a {
color: #fff;
}
<div class="container">
<nav class="menu">
<ul>
<li>HOME</li>
<li>ABOUT ME</li>
<li>SERVICES</li>
<li>CURRENT PROJECT</li>
<li>PORTFOLIO</li>
<li>CONTACT ME</li>
</ul>
</nav>
</div>

Related

CSS mix-blend-mode not working if the background image is placed in another tag

I have this simple page layout with a header and a banner.
I want to make the header transparent and sit on top of the banner image (which I might convert into a slider later, here for simplicity I have used single image).
The menu which is inside header is not clearly visible because of the background image, so I decided to use mix-blend-mode: difference, as I should.
But the text is not changing color.
As you can see in the below code snippet, I have applied mix-blend-mode to the <a>. This only works if I give li a background color.
I think the problem is that the image element is in a different tag that the mix-blend-mode element. I cannot figure out where the problem is. Any help would be appreciated.
.header {
position: absolute;
width: 100%;
top: 50px;
left: 0;
z-index: 9;
}
.header .header__bottom ul {
list-style: none;
margin: 0;
padding: 0;
text-align: right;
position: relative;
}
.header .header__bottom ul li {
display: inline-block;
}
.header .header__bottom ul li a {
text-decoration: none;
display: block;
padding: 0 20px;
color: #fff;
mix-blend-mode: difference;
}
.banner img {
width: 100%;
}
<section class="header">
<div class="header__bottom">
<div class="logo">
<img src="https://www.imltravel.com/wp-content/uploads/2017/03/IML-LOGO-VECTOR-WEBSITE-SMALL-e1489572911433.png">
</div>
<div class="header__menu">
<ul>
<li>Home</li>
<li>Tour Packages</li>
<li>Visa</li>
<li>Blog</li>
<li>Team</li>
<li>Contact</li>
</ul>
</div>
</div>
</section>
<section class="banner">
<img src="https://images.unsplash.com/photo-1503220317375-aaad61436b1b?ixlib=rb-1.2.1&ixid=MXwxMjA3fDB8MHxleHBsb3JlLWZlZWR8OHx8fGVufDB8fHw%3D&w=1000&q=80">
</section>
.header is creating a stacking context since it has z-index defined
Either remove z-index:
.header {
position: absolute;
width: 100%;
top: 50px;
left: 0;
}
.header .header__bottom ul {
list-style: none;
margin: 0;
padding: 0;
text-align: right;
position: relative;
}
.header .header__bottom ul li {
display: inline-block;
}
.header .header__bottom ul li a {
text-decoration: none;
display: block;
padding: 0 20px;
color: #fff;
mix-blend-mode: difference;
}
.banner img {
width: 100%;
}
body {
margin:0
}
<section class="header">
<div class="logo">
<img src="https://www.imltravel.com/wp-content/uploads/2017/03/IML-LOGO-VECTOR-WEBSITE-SMALL-e1489572911433.png">
</div>
<div class="header__bottom">
<div class="header__menu">
<ul>
<li>Home</li>
<li>Tour Packages</li>
<li>Visa</li>
<li>Blog</li>
<li>Team</li>
<li>Contact</li>
</ul>
</div>
</div>
</section>
<section class="banner">
<img src="https://images.unsplash.com/photo-1503220317375-aaad61436b1b?ixlib=rb-1.2.1&ixid=MXwxMjA3fDB8MHxleHBsb3JlLWZlZWR8OHx8fGVufDB8fHw%3D&w=1000&q=80">
</section>
Or move the mix-blend-mode to header (but this will affect the logo too):
.header {
position: absolute;
width: 100%;
top: 50px;
left: 0;
z-index:9;
mix-blend-mode: difference;
}
.header .header__bottom ul {
list-style: none;
margin: 0;
padding: 0;
text-align: right;
position: relative;
}
.header .header__bottom ul li {
display: inline-block;
}
.header .header__bottom ul li a {
text-decoration: none;
display: block;
padding: 0 20px;
color: #fff;
}
.banner img {
width: 100%;
}
<section class="header">
<div class="logo">
<img src="https://www.imltravel.com/wp-content/uploads/2017/03/IML-LOGO-VECTOR-WEBSITE-SMALL-e1489572911433.png">
</div>
<div class="header__bottom">
<div class="header__menu">
<ul>
<li>Home</li>
<li>Tour Packages</li>
<li>Visa</li>
<li>Blog</li>
<li>Team</li>
<li>Contact</li>
</ul>
</div>
</div>
</section>
<section class="banner">
<img src="https://images.unsplash.com/photo-1503220317375-aaad61436b1b?ixlib=rb-1.2.1&ixid=MXwxMjA3fDB8MHxleHBsb3JlLWZlZWR8OHx8fGVufDB8fHw%3D&w=1000&q=80">
</section>
An element that has blending applied, must blend with all the underlying content of the stacking context that that element belongs to. ref

How can I add spacebar on Header Nav Bar

So I made a navigation bar and a section lists and I successfully done it but the only problem is that the lists are not spaced. How do I fix this?
How the Page looks like
header {
width: 100%;
height: 80px;
position: fixed;
top: 0;
left: 0;
background: white;
box-shadow: 0 32px 55px rgba(0, 0, 0, 0.5);
z-index: 999;
}
header nav {
float: none;
margin: 30px;
}
header nav ul li {
display: inline-block;
}
header nav ul li a {
font-size: 16px;
}
<header>
<nav id="nav-main">
<ul>
<li>Home</li>
<li>Elektro One</li>
<li>Über uns</li>
<li>Kontakt</li>
<li>Impressum</li>
</ul>
</nav>
</header>
If you want to display evenly across the navbar and be responsive with screen then try using:
<ul id="even-space">
<li>..</li>
..
</ul>
and css
#even-space {
display: flex;
justify-content: space-between;
}
just add margin for li tags like following:
header {
width: 100%;
height: 80px;
position: fixed;
top: 0;
left: 0;
background: white;
box-shadow: 0 32px 55px rgba(0, 0, 0, 0.5);
z-index: 999;
}
header nav {
float: none;
margin: 30px;
}
header nav ul li {
display: inline-block;
margin: 0 16px;
}
header nav ul li a {
font-size: 16px;
}
<header>
<nav id="nav-main">
<ul>
<li>Home</li>
<li>Elektro One</li>
<li>Über uns</li>
<li>Kontakt</li>
<li>Impressum</li>
</ul>
</nav>
</header>
Add "padding-left" and "padding-right" to the anchor tag CSS under "#nav-main" id. Please update below anchor CSS :
header nav ul li a {
font-size:16px;
padding-left: 30px;
padding-right:30px; }

Space navigation evenly across window (responsive)

I am trying to space my navigation evenly across the top of my page while eliminated any empty space on the left, right, and between each link. I know I could probably just use the Calc function but it is not supported enough with older versions of browsers so I am looking for an alternative method.
My current code:
.nav {
z-index: 1;
position: fixed;
top: 0;
left: 0;
right: 0;
background-color: #252839;
}
.nav ul {
list-style-type: none;
width: 100%;
}
.nav ul li{
color: #b5b5b7;
padding: 15px 0;
font-size: 1.2em;
display: inline-block;
}
.nav ul li:hover {
background-color: #677077;
color: #89C4F4;
}
<div class="nav">
<ul>
<li>Home</li>
<li>Profile</li>
<li>Experience</li>
<li>Abilities</li>
<li>Projects</li>
<li>Contact</li>
</ul>
</div>
Thanks for your help!
Use display:flex and flex-grow: 1 to expand the li elements, then change the a tags within to display: block and center the text.
.nav {
z-index: 1;
position: fixed;
top: 0;
left: 0;
right: 0;
background-color: #252839;
}
.nav ul {
list-style-type: none;
width: 100%;
padding: 0;
display: flex;
}
.nav ul li{
flex-grow: 1;
}
.nav ul li a {
display: block;
text-align: center;
color: #b5b5b7;
font-size: 1.2em;
padding: 15px 0;
}
.nav ul li a:hover {
background-color: #677077;
color: #89C4F4;
}
<div class="nav">
<ul>
<li>Home</li>
<li>Profile</li>
<li>Experience</li>
<li>Abilities</li>
<li>Projects</li>
<li>Contact</li>
</ul>
</div>

Trying to make a fixed menu with a background

Hey there I wanted to create a white background for my menu on the right and title on left just like on this website http://weblendit.co.uk/, that also stays at the top when you scroll down (doesn't necessarily have to change its size like this one)
My header also consists of a big picture after the nav and h1, when I set a background color it will only be behind the text, but I want it to be fullsize.
I also tried setting a width and height for .fixed but then the nav floats to the left and the h1 disappears?
.fixed{
position: fixed;
top: 0;
background-color: white;
}
h1{
padding: 1% 0 0 4%;
text-transform: uppercase;
float: left;
left: 0;
}
nav{
float: right;
padding-right: 12%;
padding-top: 3%;
width: auto;
right: 0;
}
#menu ul{
display: flex;
list-style: none;
padding: 0;
margin: 0;
}
#menu li{
margin: 0 5%;
float: left;
}
#menu li a {
text-decoration: none;
color: #666666;
font-size: 25px;
font-weight: bold;
display: block;
float: left;
}
<header class="header">
<h1 class="fixed">My page</h1>
<nav class="fixed" id="menu">
<ul>
<li>Home</li>
<li>Portfolio</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</nav>
....
It is better to fix the container surrounding the header elements, rather that every element in it. Then you don't need the fixed class anymore.
<header class="header">
<h1>My page</h1>
<nav id="menu">
<ul>
<li>Home</li>
<li>Portfolio</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</nav>
</header>
CSS
.header {
position: fixed;
background-color: red;
top: 0px;
left: 0px;
width: 100%;
}

Chrome and opera leaves empty space on top because of li padding

I'm working on a homepage with fullpage slider.
At firefox everything went right!
At Chrome and Opera, I have an empty space on the top of the page.
I noticed that all the space is from the menu padding (li), when I turn it to 0 the space is getting shorter but is not leaving.
Here is my html
<ul id="connect">
<li>
logo
</li>
</ul>
<ul id="menu">
<li>menu1</li>
<li>menu2</li>
<li>menu3</li>
<li>menu4</li>
</ul>
And my css is
#connect {
z-index: 10;
position: fixed;
width: 100%;
list-style: none;
margin: 0;
margin-left: 90px;
padding: 20px;
}
#menu {
z-index: 10;
float: right;
margin: 0;
font-size:12px;
list-style: none;
position:relative;
top:30px;
right:20px;
font-family: 'Open Sans', sans-serif;
}
li {
display:block;
float: left;
padding: 10px;
}
Could someone help?
I'd re-write your code like this so it's more simple and semantic: http://jsfiddle.net/kc4umn1c/
Whenever you use "position: fixed" you should also specify your X/Y coordinates ("left/right" in this case). I've added the styles below.
Also, look into using a reset.css file to make all of your styles fit nicely between browsers. (google html5 boiler plate, they have a good one.)
Good luck!
HTML
<header class="header">
<h1 class="logo">logo</h1>
<nav class="menu">
<ul>
<li>menu1</li>
<li>menu2</li>
<li>menu3</li>
<li>menu4</li>
</ul>
</nav>
</header>
CSS
* { margin: 0; padding: 0; box-sizing: border-box; }
.header {
position: fixed;
left: 0;
top: 0;
right: 0;
background: black;
z-index: 1;
padding: 20px;
color: white;
}
.logo {
float: left;
display: inline-block;
}
.menu {
float: right;
display: inline-block;
color: white;
}
.menu ul {
list-style: none;
}
.menu ul li {
float: left;
padding: 10px;
}