I have the following: http://jsfiddle.net/5mbK8/2/
The text Link is supposed to function as a link, but it doesn't work because .container .image has a z-index of -1. If I remove the z-index, it works, but then the image isn't behind the yellow shadow.
How can I make the text clickable while keeping the background image behind the yellow box shadow?
HTML:
<div class="container">
<div class="side"></div>
<div class="image" style="background: url('http://i.imgur.com/T0VWLqZ.png');">
<div class="menu">
<ul>
<li><a href="#">Link</li>
</ul>
</div>
</div>
</div>
CSS:
a {
color: black;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.container {
width: 900px;
height: 300px;
}
.container .image {
width: 598px;
height: 300px;
float: right;
position: relative;
z-index: -1;
}
.container .side {
float: left;
width: 302px;
height: 300px;
background: red;
box-shadow: 5px 0 5px -5px yellow;
}
.container .image .menu {
position: absolute;
bottom: 0;
left: -25px;
}
.container .image .menu ul {
list-style: none;
margin: 0;
}
.container .image .menu ul li {
display: inline-block;
text-align: center;
padding: 10px;
background: white;
}
Check out this fiddle: http://jsfiddle.net/5mbK8/5/
A solution would be to position the menu outside the .image div.
And of course you will have to adapt the left: 300px; depending on what width the .side will have.
EDIT (added code):
<div class="container">
<div class="side"></div>
<div class="image" style="background: url('http://i.imgur.com/T0VWLqZ.png');"> </div>
<div class="menu">
<ul>
<li>Link</li>
</ul>
</div>
</div>
CSS:
a {
color: black;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.container {
position: relative;
width: 900px;
height: 300px;
}
.container .image {
width: 598px;
height: 300px;
float: right;
position: relative;
z-index: -1;
}
.container .side {
float: left;
width: 302px;
height: 300px;
background: red;
box-shadow: 5px 0 5px -5px yellow;
}
.container .menu {
position: absolute;
bottom: 0;
left: 300px;
}
.container .menu ul {
list-style: none;
margin: 0;
}
.container .menu ul li {
display: inline-block;
text-align: center;
padding: 10px;
background: white;
}
Related
I'm building a top navigation bar. I'd like the logo & menu items on the right to be vertically centered. To achieve this, I'm looking to set the position of the container of both logo & menu items as relative, and then set the position of logo & menu items as absolute to achieve the effect.
This successfully worked for the logo. However, it's not working for menu items, in fact, all the menu items are gone once the code below is implemented. Not sure what's going on here.
<div class="boxA">
<div class="box1">
<div class="site">
<img src="img/logo.png">
</div>
</div>
<div class="box2">
<nav class="menu">
<ul>
<li>menu1</li>
<li>menu2</li>
<li>menu3</li>
<li>menu4</li>
</ul>
</nav>
</div>
</div>
.boxA:after {
content:"";
display: block;
clear: both;
}
.boxA {
height: 100px;
position: relative;
border-bottom: 1px solid #E0DCDC;
}
.boxA img {
position: absolute;
top: 50%;
left: 3%;
transform: translate(0, -50%);
}
.box2 li {
position: absolute;
top: 50%;
transform: translate(0, -50%);
}
.box1 {
float: left;
width: auto;
}
.box2 {
float: right;
width: auto;
}
.box2 ul {
margin: 0;
padding: 0;
list-style: none;
}
.box2 li a {
display: block;
padding: 0px;
color: inherit;
text-decoration: none;
font-size: 12px;
}
.box2 li a:hover {
text-decoration: underline;
}
.box2 ul:after {
content: "";
display: block;
clear: both;
}
.box2 li {
float: left;
width: auto;
}
.box1 img {
position: absolute;
height: 20px;
}
body{margin:0}
.boxA {
display: flex;
flex-direction: row;
background: #b6d6f3;
border-bottom: 2px solid #8ac8ff;
justify-content: space-between;
align-items: center;
padding: 20px 5px;
}
.site img {
width: 100px;
}
.menu ul {
margin: 0;
padding: 0;
list-style-type: none;
}
.menu ul li a {
text-decoration: none;
padding: 2px 5px;
display: inline-block;
}
<div class="boxA">
<div class="box1">
<div class="site">
<img src="https://www.smashingmagazine.com/images/smashing-cat/cat-with-slippers.svg">
</div>
</div>
<div class="box2">
<nav class="menu">
<ul>
<li>menu1</li>
<li>menu2</li>
<li>menu3</li>
<li>menu4</li>
</ul>
</nav>
</div>
</div>
Try not to use css float property instead use css grid or css flex box.
EDIT 1 :
If you want to see the same result in IE without using flex property then.
.boxA:after {
content:"";
display: block;
clear: both;
}
.boxA {
height: 100px;
position: relative;
border-bottom: 1px solid #E0DCDC;
}
.boxA img {
position: absolute;
top: 50%;
left: 3%;
transform: translate(0, -50%);
}
.box2 ul {
position: absolute;
top: 50%;
transform: translate(0, -50%);
/* -- NEW -- */
right: 10px;
}
.box1 {
float: left;
/* -- NEW -- */
width: 100PX;
background-color: #cddef7;
height: 100px;
}
.box2 {
float: right;
/* -- NEW -- */
width: 50%;
background-color: #85c3f9;
height: 100px;
}
.box2 ul {
margin: 0;
padding: 0;
list-style: none;
}
.box2 li a {
display: block;
padding: 0px;
color: inherit;
text-decoration: none;
font-size: 12px;
/* --NEW-- */
padding:2px 0;
}
.box2 li a:hover {
text-decoration: underline;
}
.box2 ul:after {
content: "";
display: block;
clear: both;
}
/* DOES NOT REQUIRED--
.box2 li {
float: left;
width: auto;
}
*/
.box1 img {
position: absolute;
/* --NEW-- */
width:80px;
}
<div class="boxA">
<div class="box1">
<div class="site">
<img src="https://www.smashingmagazine.com/images/smashing-cat/cat-with-slippers.svg">
</div>
</div>
<div class="box2">
<nav class="menu">
<ul>
<li>menu1</li>
<li>menu2</li>
<li>menu3</li>
<li>menu4</li>
</ul>
</nav>
</div>
</div>
I have the layout as below:
https://imgur.com/r1l0cCi
I have added a side section just below the nav bar. I want the side section to be placed in relation to the nav bar but it takes its position in relation to the header. Is there a way I can achieve this?
Here is my html code and css
body {
position: absolute;
top: 0px;
left: 0px;
right: 0px;
bottom: 0px;
}
.header {
border-radius: 25px;
height: 14%;
width: 100%;
}
img.nav-action-image {
width: 14px;
height: auto;
}
nav a {
display: inline;
text-decoration: none;
float: left;
color: #d1e231;
padding: 14px 16px;
border-right: 1px solid #bbb;
}
nav a:hover {
color: #bff000;
}
nav a.active {
display: inline;
background-color: #bab86c;
color: #37412a;
}
.navigation-bar {
position: absolute;
padding: 0;
width: 100%;
margin-top: 5px;
border-radius: 7px;
}
.action-block {
height: 80%;
width: 20%;
margin-top: 40px;
}
<body>
<header class=header>
</header>
<nav class=navigation-bar>
<img class="nav-action-image" src="menu_icon.png" />
<a class="active" href="#Summary">Summary</a>
Preferences
</nav>
<br>
<div class="action-block">
hello
</div>
</body>
you can see that in the css, the code for action-block class aligns from the header instead of the nav bar. I want it to align from the nav bar. Is there a way that I can do this?
remove position:absolute from body and nav.
The below css will clear the floating elements inside nav which will give it a height of its content.
nav:after {
content: '';
display: block;
clear: both
}
html,
body {
height: 100%
}
.header {
border-radius: 25px;
height: 14%;
width: 100%;
}
img.nav-action-image {
width: 14px;
height: auto;
}
nav:after {
content: '';
display: block;
clear: both
}
nav a {
display: inline;
text-decoration: none;
float: left;
color: #d1e231;
padding: 14px 16px;
border-right: 1px solid #bbb;
}
nav a:hover {
color: #bff000;
}
nav a.active {
display: inline;
background-color: #bab86c;
color: #37412a;
}
.navigation-bar {
padding: 0;
width: 100%;
margin-top: 5px;
border-radius: 7px;
background: yellow;
}
.action-block {
height: 80%;
width: 20%;
background: greenyellow;
}
<body>
<header class="header">
</header>
<nav class="navigation-bar">
<img class="nav-action-image" src="menu_icon.png" />
<a class="active" href="#Summary">Summary</a>
Preferences
</nav>
<div class="action-block">
hello
</div>
</body>
If using a absolute element relative to another element, then the parent must have position: relative. With this in mind replace your body css with:
html, body {
width: 100%;
height: 100%;
margin: 0;
position: relative;
}
If using floats in the nav (the anchor element), use a clear: both at the end likte this
.navigation-bar {
position: absolute;
display: block;
width: 100%;
margin-top: 5px;
padding: 0;
border-radius: 7px;
}
.navigation-bar::after {
display: block;
clear: both;
content: "";
}
nav a {
float: left;
padding: 14px 16px;
text-decoration: none;
color: #d1e231;
}
nav a:hover {
color: #bff000;
}
nav a.active {
background-color: #bab86c;
color: #37412a;
}
I am currently having an issue where my navigation bar and banner shrink when I set their position to fixed.I have many things like changing z-index,setting its top position to 0,adding auto margin etc, and none of it worked.I hope someone can point me to my mistake.This is my html code:
html,
body {
margin: 0;
background-color: #ffeecc;
font-family: 'Chivo', sans-serif;
}
.container {
margin: auto;
width: 75%;
}
.nav_left {
width: 100%;
background-color: #258e25;
height: 50px;
float: left;
text-align: left;
}
.banner {
width: 100%;
overflow: hidden;
background-color: white;
}
.banner img {
width: 70%;
height: 150px;
padding: 0 15%;
}
.top {
position: fixed;
}
nav {
text-align: center;
}
nav ul {
list-style-type: none;
padding: 0;
margin: 0;
display: inline-block;
width: 100%;
height: 100%;
}
nav ul li {
float: left;
text-align: center;
height: 100%;
width: 25%;
}
nav ul li a {
display: inline-block;
width: 100%;
font-weight: bold;
line-height: 50px;
text-decoration: none;
color: white;
}
nav ul li a:hover {
background-color: white;
color: black;
}
<div class="container">
<div class="top">
<div class="banner">
<img src="images/winwin-logo-cover.jpg" alt="winwin logo">
</div>
<nav>
<div class="nav_left">
<ul>
<li>PROIZVODI</li>
<li>O NAMA</li>
<li>KONTAKT</li>
</ul>
</div>
<div class="nav_right"></div>
</nav>
</div>
this is how it should look like
this is how it looks like when i put .top{position:fixed}
When you set an element to absolute or fixed position, it will be out of the the normal content flow and trigger the shrink to fit feature. You can apply the offsets and width/height to position and recreate the box size you wish to have.
.top {
position: fixed;
left: 0; /* ADDED */
top: 0; /* ADDED */
width: 100%; /* ADDED */
}
html,
body {
margin: 0;
background-color: #ffeecc;
font-family: 'Chivo', sans-serif;
}
.container {
margin: auto;
width: 75%;
}
.nav_left {
width: 100%;
background-color: #258e25;
height: 50px;
float: left;
text-align: left;
}
.banner {
width: 100%;
overflow: hidden;
background-color: white;
}
.banner img {
width: 70%;
height: 150px;
padding: 0 15%;
}
.top {
position: fixed;
left: 0;
top: 0;
width: 100%;
}
nav {
text-align: center;
}
nav ul {
list-style-type: none;
padding: 0;
margin: 0;
display: inline-block;
width: 100%;
height: 100%;
}
nav ul li {
float: left;
text-align: center;
height: 100%;
width: 25%;
}
nav ul li a {
display: inline-block;
width: 100%;
font-weight: bold;
line-height: 50px;
text-decoration: none;
color: white;
}
nav ul li a:hover {
background-color: white;
color: black;
}
<div class="container">
<div class="top">
<div class="banner">
<img src="images/winwin-logo-cover.jpg" alt="winwin logo">
</div>
<nav>
<div class="nav_left">
<ul>
<li>PROIZVODI</li>
<li>O NAMA</li>
<li>KONTAKT</li>
</ul>
</div>
<div class="nav_right"></div>
</nav>
</div>
Because .top has no width. However, when set to fixed it is using the viewport width to calculate the width. You might want to set it to 75%.
You also might want to set .container to position: relative so .top will relate to its borders.
body {
margin: 0;
background-color: #ffeecc;
font-family: 'Chivo', sans-serif;
}
.container {
margin: auto;
width: 75%;
position: relative;
}
.top {
position: fixed;
width: 75%;
}
.nav_left {
width: 100%;
background-color: #258e25;
height: 50px;
float: left;
text-align: left;
}
nav {
text-align: center;
}
nav ul {
list-style-type: none;
padding: 0;
margin: 0;
display: inline-block;
width: 100%;
height: 100%;
}
nav ul li {
float: left;
text-align: center;
height: 100%;
width: 25%;
}
nav ul li a {
display: inline-block;
width: 100%;
font-weight: bold;
line-height: 50px;
text-decoration: none;
color: white;
}
nav ul li a:hover {
background-color: white;
color: black;
}
<div class="container">
<div class="top">
<nav>
<div class="nav_left">
<ul>
<li>PROIZVODI</li>
<li>O NAMA</li>
<li>KONTAKT</li>
</ul>
</div>
<div class="nav_right"></div>
</nav>
</div>
I have the following HTML (Fiddle Example):
<header>
<div class="wrapper">
<em class="brand">
<img src="http://via.placeholder.com/200x40?text=LOGO"/>
</em>
<nav class="menu">
<ul class="menu">
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
</div>
<div class="slides">
<div class="slide">
<div class="frame">
<img src="http://via.placeholder.com/1200x400?text=Image to Crop" />
</div>
<div class="text">
<h2>Our Message</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
</div>
</div>
</header>
<main>
Main content
</main>
And correspondent CSS:
header {
text-align: center;
}
div.wrapper {
margin: 0 auto;
max-width: 640px;
text-align: left;
position: relative;
}
em.brand img {
display: block;
}
ul.menu {
list-style: none;
margin: 0;
padding: 0;
}
ul.menu li {
display: inline-block;
margin: 0;
padding: 8px;
}
ul.menu li a {
text-decoration: none;
font-size: 18px;
color: white;
}
em {
border: 1px solid red;
position: absolute;
z-index: 2000;
}
nav {
position: absolute;
z-index: 2000;
right: 0;
}
.slides {
width: 100%;
position: relative;
}
.slide .frame img {
width: 100%;
margin: 0 -100px;
}
.slide .text {
position: absolute;
text-align: center;
top: 80px;
width: 100%;
}
.slide .text h2 {
color: white;
font-size: 40px;
margin: 8px;
}
.slide .text p {
color: white;
font-size: 20px;
margin: 8px;
}
main {
border: 1px solid red;
font-size: 20px;
}
Using media queries I need, sometimes, to adjust the image by cropping it on Left/Right or on Bottom/Top:
.slide .frame img {
width: 100%;
margin: 0 -100px;
}
This does not change the image. It only changes it if I try Top/Bottom:
.slide .frame img {
width: 100%;
margin: -100px 0;
}
Any idea why?
You have to set up the negative margins to the image's container, and set the image width: 100%
.slides {
width: 100%;
position: relative;
overflow: hidden; // so the "negative" part is not visible
}
.slide .frame {
margin: 0 -100px;
}
.slide .frame img {
width: 100%;
}
But maybe you should the image as a background and use the property background-size: cover; and background-position: center;
I have an un-ordered list that is nested inside the purple div. I only want the portion in (or on top of) the div to be visible, and I want to be able to scroll to view the rest. I've already done this on an earlier project.
http://codepen.io/tyl-er/pen/ALAyjq (Enter a search to see an example)
I tried using "overflow:hidden;" but that is not working.
<!--<span class="glyphicons glyphicons-wifi-alt"></span>
live icon
<span class="glyphicons glyphicons-moon"></span>
not live icon-->
<body>
<div class="box">
<header>
<div class="nav">
<ul>
<li class="favs">Favs</li>
<li class="online">Online</li>
<li class="offline">Offline</li>
</ul>
</div>
</header>
<div class="list">
<ul>
<li>streamerhouse</li>
<li>freecodecamp</li>
<li>OgamingSC2</li>
<li>brunofin</li>
<li>cretetion</li>
<li>ESL_SC2</li>
<li>storbeck</li>
<li>comster404</li>
<li>habathcx</li>
<li>RobotCaleb</li>
<li>noobs2ninjas</li>
</ul>
</div>
<div class="output"></div>
</div>
<div class="divN"></div>
</body>
/*Colors
#6441A4 (navbar, footer, highlight)
#392E5C
#17141F(background)*/
* {
color: white
}
body {
height: 100%;
width: 100%;
background: #17141f;
}
.box {
height: 80%;
width: 360px;
background: #392E5C;
position: absolute;
margin-left: auto;
margin-right: auto;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
}
.nav ul {
width: 360px;
margin: 0;
padding: 0;
background: #6441A4;
}
.nav li {
font-family: 'Oswald', sans-serif;
font-size: 1.2em;
line-height: 40px;
height: 40px;
border-bottom: 1px solid #888;
text-align: center;
}
.nav a {
text-decoration: none;
color: #fff;
display: block;
transition: .5s background-color;
}
.nav a:hover {
background-color: #005f5f;
}
.nav a.active {
background-color: #fff;
color: #444;
cursor: default;
}
#media screen and (min-width: 600px) {
.nav li {
width: 120px;
border-bottom: none;
height: 50px;
line-height: 50px;
font-size: 1.4em;
}
/* Option 1 - Display Inline */
.nav li {
display: inline-block;
margin-right: -4px;
}
a {
color: white;
}
a:hover {
color: white;
}
.list ul {
padding: 8px;
overflow: hidden;
overflow-y: scroll;
position: relative;
background:
}
.list li {
width: 360px;
height: 50px;
}
Here's the project url
http://codepen.io/tyl-er/pen/NRPkaV?editors=1100
you should give fix height to your parent div named list. try this
.list{
height: 346px;
overflow-y: scroll;
overflow-x: hidden;
}
just change your code to this and you are done
.list {
overflow-y: auto;
height: calc(100% - 50px);
}
.list ul {
padding: 8px;
overflow: hidden;
position: relative;
background:
}