I'm having two problems with this CSS code, and I'm needing a second set of eyes to help me look at it.
1.I'm trying to move my text up a bit while not moving the image inside of my navbar. Everything should look centered in the navbar, but the text seems to be offset and I'm not sure how to fix it. My only understanding of fixing vertical alignment is through padding, but that would also impact the image.
I'm trying to make the hover-over effect dynamic and resize according to window height, but I seem to be having trouble accomplishing this.
Codepin: https://codepen.io/dansbyt/pen/ZEWvZwJ
CSS in question:
.navbar{
top: 0;
left: 0;
width: 100%;
height: 56px;
z-index: 10;
position: fixed;
background-color: #5B7042;
border-bottom: 4px solid #3F5328}
.navbar_links{
margin-left: 22%;
position: absolute;
width: 78%}
.navbar_links a{
padding: 2%;
display: block;
float: left;
font-family: 'Archivo', sans-serif;
font-size: x-large;
text-decoration: none;
color: white;}
.navbar_links a:hover {background-color: #3F5328}
How about this:
.navbar {
top: 0;
left: 0;
width: 100%;
height: 56px;
z-index: 10;
position: fixed;
background-color: #5B7042;
border-bottom: 4px solid #3F5328;
}
.navbar_links {
margin-left: 22%;
position: absolute;
width: 78%;
}
.navbar_links a {
line-height: 56px;
display: flex;
float: left;
font-family: 'Archivo', sans-serif;
font-size: x-large;
text-decoration: none;
color: white;
}
.navbar_links a:hover {
transform: scale(1.05);
}
p {
margin-block-start: 0;
margin-block-end: 0;
}
<div class="navbar">
<div id="computer" class="navbar_links">
<img src="http://mrdansby.com/projects/dash_icon.png"> Dash
</div>
</div>
add span to text and style to it and use rem instead % for navbar_links a padding
.navbar{
top: 0;
left: 0;
width: 100%;
height: 56px;
z-index: 10;
position: fixed;
background-color: #5B7042;
border-bottom: 4px solid #3F5328}
.navbar_links{
margin-left: 22%;
position: absolute;
width: 78%}
.navbar_links a{
padding: 1.2rem;
display: block;
float: left;
font-family: 'Archivo', sans-serif;
font-size: x-large;
text-decoration: none;
color: white;}
.navbar_links span{ position:relative; bottom:5px; }
.navbar_links a:hover {background-color: #3F5328}
<div class="navbar">
<div id="computer" class="navbar_links">
<img style="width:30%" src="http://mrdansby.com/projects/dash_icon.png"> <span>Dash</span>
Related
I'm wanting to add a small profile picture to my navbar, similar to how StackOverflow has on the top. However, when I resize the image for the navbar, it appears that the "container" is still present because when I hover over a part of the navbar that does not include the image, my page acts as if I hovered over the image. How do I fix this?
Image of error: https://imgur.com/a/jqzVeeK
Codepin of error: https://codepen.io/dansbyt/pen/ZEWvdwG
CSS:
.logo{
position: absolute;
left: 2%}
.money{
position: absolute;
top: 15%;
right: 6%;
font-family: 'Noto Sans JP', sans-serif;
font-size: x-large;
color: white}
.profile{
position: absolute;
top: 1%;
right: 0%}
.profile img{float:right}
.navbar{
top: 0;
left: 0;
width: 100%;
height: 56px;
z-index: 10;
position: fixed;
background-color: #5B7042;
border-bottom: 4px solid #3F5328}
.navbar_links{
margin-left: 21%;
position: absolute;
width: 78%}
.navbar_links a{
padding: 1% 1%;
display: block;
float: left;
font-family: 'Noto Sans JP', sans-serif;
font-size: x-large;
text-decoration: none;
color: white;}
.navbar_links a:hover {background-color: #3F5328}
.navbar_links span{position:relative; bottom:5px}
HTML:
<div class="navbar">
<div class="logo"><img src="http://mrdansby.com/Resources/logo.png" style="width:27%; height:auto"></div>
<div class="navbar_links">
<img style="width:30%" src="http://mrdansby.com/projects/icons/i_home.png"><span> Dash</span>
<div class="profile"><img src="http://mrdansby.com/Resources/ProfilePics/default.png" style="width:4%;border-radius:50%;object-fit: contain"></div>
<div class="money">$100</div>
</div>
</div>
Instead of .navbar_links a{ use .navbar_links > a{. You do not want all a to have a hover effect and so on which was affecting the avatar.
see working code below (width makes it appear smaller here)
.logo{
position: absolute;
left: 2%}
.money{
position: absolute;
top: 15%;
right: 6%;
font-family: 'Noto Sans JP', sans-serif;
font-size: x-large;
color: white}
.profile{
position: absolute;
top: 1%;
right: 0%}
.profile img{float:right}
.navbar{
top: 0;
left: 0;
width: 100%;
height: 56px;
z-index: 10;
position: fixed;
background-color: #5B7042;
border-bottom: 4px solid #3F5328}
.navbar_links{
margin-left: 30%;
position: absolute;
width: 78%}
.navbar_links > a{
padding: 1% 1%;
display: block;
float: left;
font-family: 'Noto Sans JP', sans-serif;
font-size: x-large;
text-decoration: none;
color: white;}
.navbar_links > a:hover {background-color: #3F5328}
.navbar_links span{position:relative; bottom:5px}
<div class="navbar">
<div class="logo"><img src="http://mrdansby.com/Resources/logo.png" style="width:27%; height:auto"></div>
<div class="navbar_links">
<img style="width:30%" src="http://mrdansby.com/projects/icons/i_home.png"><span> Dash</span>
<div class="profile">
<img src="http://mrdansby.com/Resources/ProfilePics/default.png" style="width:4%;border-radius:50%;object-fit: contain">
</div>
<div class="money">$100</div>
</div>
</div>
I found the answer to my problem. I should resize the div, not the image. See below.
.profile{
position: absolute;
width: 4%;
top: 1%;
right: 0%}
.profile img{float:right; max-width: 100%; max-height: 100%;display: block;}
this time I hope i'll be able to format the question better and I apologize if the latter is trivial, but I'm a beginner in html and css. I'd need help with a header, which needs to be as in the picture: made of a background image cut into two halves by a white bar where the navigation bar(right) and the title (left) stand. The title has another background image shaped as a half-moon.Since I couldn't find an acceptable way to make the half-moon appear as a background-image of the div where I put the title, I made another div with the half-moon as a background-image and I gave this div a relative position, working on top, right and left so to make it fit in the right place. However, I don't know how make the text show up in front of everything. Also if I make the browser window smaller the halfmoon moves around the page. Is there something I can do to make things better?
my try is below. Thanks in advance for any help.
html, body *{margin: 0; box-sizing: border-box}
h1, h2, h3, h4, h5 {
font-family: 'Play', sans-serif;
color: #c76161;
}
#header {
background: url("http://i65.tinypic.com/t8vzp2.jpg") 100% no-repeat;
background-position: center center;
position: fixed;
right: 0;
left: 0;
top:0;
display: block;
width: 100%;
height: 14.37em;
}
#testo-header{
background-color: white;
height: 70px;
width: 50%;
position: absolute;
top: 80px;
left: 0;
text-align: center;
line-height: 70px;
z-index: 2;
}
#mezzaluna{
background-image: url(http://i63.tinypic.com/w72ag6.png);
background-repeat: no-repeat;
height:90px;
position: relative;
bottom: 67px;
left: 180px;
z-index: 1;
}
ul#nav {
background-color: white;
height: 70px;
width: 50%;
position: absolute;
top: 80px;
right: 0;
font-family: sans-serif;
font-size: 1em;
font-weight: bold;
list-style-type: none;
line-height: 35px;
display: block;
}
ul#nav li {
float: left;
text-align: center;
vertical-align: text-top;
padding: 20px;
}
ul#nav li a {
text-decoration: none;
color: #3a7777;
}
ul#nav a:hover {
color: #f5af33
}
bodybody>
<div id="header">
<div class="wrap">
<div id="testo-header">
<h1>Rosso Pomodoro</h1>
<div id="mezzaluna"></div>
</div>
<ul id="nav">
<li>Home</li>
<li class="active">Ricette</li>
<li>Categorie</li>
<li>Blog</li>
<li>Contatti</li></li>
</ul>
</div>
Not sure what you are planning on doing with that but you could do this. It would be better if you tell us what you expect to get! But so far this is what you are trying to do!
html, body *{margin: 0; box-sizing: border-box}
h1, h2, h3, h4, h5 {
font-family: 'Play', sans-serif;
color: #c76161;
}
#header {
background: url("http://i65.tinypic.com/t8vzp2.jpg") 100% no-repeat;
background-position: center center;
position: fixed;
right: 0;
left: 0;
top:0;
display: block;
width: 100%;
height: 14.37em;
}
#testo-header{
background-color: white;
height: 70px;
width: 50%;
position: absolute;
top: 80px;
left: 0;
text-align: center;
line-height: 70px;
z-index: 2;
}
#testo-header h1:before{
content: '\0020';
background-image: url(http://i63.tinypic.com/w72ag6.png);
background-repeat: no-repeat;
background-color: #ff0000;
width: 75%;
height:100%;
display: block;
position: absolute;
top: 50%;
left: 12.5%;
border-bottom-left-radius: 50%;
border-bottom-right-radius: 50%;
z-index: -1;
}
ul#nav {
background-color: white;
height: 70px;
width: 50%;
position: absolute;
top: 80px;
right: 0;
font-family: sans-serif;
font-size: 1em;
font-weight: bold;
list-style-type: none;
line-height: 35px;
display: block;
z-index: 5;
}
ul#nav li {
float: left;
text-align: center;
vertical-align: text-top;
padding: 20px;
}
ul#nav li a {
text-decoration: none;
color: #3a7777;
}
ul#nav a:hover {
color: #f5af33
}
bodybody>
<div id="header">
<div class="wrap">
<div id="testo-header">
<h1>Rosso Pomodoro</h1>
</div>
<ul id="nav">
<li>Home</li>
<li class="active">Ricette</li>
<li>Categorie</li>
<li>Blog</li>
<li>Contatti</li></li>
</ul>
</div>
i'm trying to creat a side menue.
and im not sure what is the best way to do this.
my question is how to pin the menu to the upper part of the screen?
thank you :)
this is the HTML
<!--menu-->
<div class="menu">
<div class="option" align="center">
<ul>
<li>דף הבית</li>
<li>צור קשר</li>
<li>בלוג</li>
<li>מי את גברת?</li>
</ul>
</div>
</div>
<!--endmenue-->
the CSS
div.menu{
position: fixed;
width: 20%;
height: 100%;
background: black;
right: 0;
}
div.option{
padding-top: 50%;
padding-bottom: 50%;
}
div.option a{
text-decoration: none;
}
div.option ul{
list-style-type: none;
text-align: center;
font-family: alef;
font-weight: 700;
color: white;
line-height: 400%;
margin: 0;
padding: 0;
}
Try this:
div.menu{
position: fixed;
width: 20%;
height: 100%;
background: black;
right: 0;
top: 0; // added this
}
I added top:0 which attaches the element to the top of it's parent
In your CSS I would add
*{
margin: 0px;
padding: 0px;
}
This will help with pesky unwanted margin and padding
I guess you need this?
div.menu{
position: fixed;
width: 100%;
background: black;
right: 0;
}
div li{
display: inline-block;
margin-right: 10%;
}
div.option a{
text-decoration: none;
}
div.option ul{
list-style-type: none;
text-align: center;
font-family: alef;
color: white;
line-height: 200%;
margin: 0;
padding: 0;
}
See here JsFiddle
I have a wired problem, i have a regular nav with ul and li and i am trying to make after one of the li red box with number inside, but the problem is that the number from some reason going out of the box, what is the problem?
This is the code:
#mainHeader .rightNav {
float: right;
li {
position: relative;
}
img {
vertical-align: middle;
}
li:nth-child(4)::after {
content:attr(data-value);
color:#fff;
border-radius: 2px;
background-color: #d94a3e;
text-align: center;
width: 18px;
height: 18px;
position: absolute;
top:0;
right:0;
}
}
http://plnkr.co/edit/ys7Wy3EJPlA4VlXDt6hE?p=preview
There was wrong on your line height.
Should have : line-height: normal;
Add that to #mainHeader .rightNav li:nth-child(4)::after
Update your css to this:
#mainHeader .rightNav li:nth-child(4)::after {
content: attr(data-value);
color: #fff;
border-radius: 2px;
background-color: #d94a3e;
text-align: center;
width: 18px;
height: 18px;
position: absolute;
top: 0;
right: 0;
line-height: normal;
}
Sample link
Replace your styles with this:)
#mainHeader .rightNav li:nth-child(4)::after {
content: attr(data-value);
color: #fff;
border-radius: 2px;
background-color: #d94a3e;
text-align: center;
position: relative;
top: -10px;
right: 0;
padding: 1px 4px;
}
I have my code set up so I have the hero image at the bottom and the overlay on top with the text and button in overlay. I also have the navigation bar with a z-index but for some reason the button for my resume in overlay isn't working.
HTML
<div id="header">
<a href="index.html"><div id="leftHeader">
<img src="assets/logo2.jpg" alt="Logo" style="width:65px;height:65px">
<h1>Amanda Farrington</h1>
</div>
<div id="nav">
<ul>
<li>About</li>
<li>Work</li>
<li>Contact</li>
<li>Notes</li>
</ul>
</div>
</div>
<div id="hero">
<div id="heroImage">
<img src="assets/trees.jpg" alt="trees" style="width:100%;height:10%">
</div>
<div id="overlay">
<h2>Amanda Farrington</h2>
<h3>Graphic Artist | Web Designer</h3>
View Resume
</div>
</div>
CSS
#header {
color: #D7DADB;
font-family: 'Roboto', sans-serif;
font-weight: 300;
font-size : 15px;
text-align: left;
width: 100%;
padding-left: 3em;
position: relative;
height: 15%;
box-sizing: border-box;
padding-top: 1em;
}
#header img
{
float: left;
padding-left: 3em;
}
h1{
width: 9em;
float: left;
padding-left: 0.5em;
color: #45CCCC;
padding-bottom: 1px;
}
#nav {
width: 50%;
margin:0;
padding:0;
text-align: right;
color: red;
font-size:20px;
float: right;
padding-right: 2em;
z-index: 99;
}
#nav ul {
padding: 1px;
}
#nav li {
display: inline;
padding: 38px;
}
#nav li a {
color: #2C3E50;
text-decoration: none;
}
#nav li a:hover {
color: #45CCCC;
}
/*----------hero image styles-------------*/
#hero{
padding-top: 25em;
width: 100%;
height: 30em;
position: relative;
z-index: -1;
}
#heroImage
{
top: 9%;
width: 100%;
z-index: 1;
position: absolute;
}
#overlay{
width: 34em;
top: -15%;
margin-left: 30%;
z-index: 2;
position: relative;
clear: left;
}
h2{
width: 100%;
position: relative;
font-family: 'Roboto', sans-serif;
font-weight: 300;
font-size: 60px;
float: center;
color: white;
opacity: 1.0;
text-shadow: 2px 2px 3px #000000;
text-align: center;
}
h3{
width: 100%;
position: relative;
font-family: 'Roboto', sans-serif;
font-weight: 300;
font-size: 30px;
color: #e5e5e5;
opacity: 1.0;
text-shadow: 2px 3px 2px #000000;
text-align: center;
}
a.down{
z-index: 100;
font-family: 'Roboto', sans-serif;
font-weight: 400;
text-decoration: none;
color: #181b1e;
background: #45CCCC;
position: relative;
padding: 0.6em 0.2em;
font-size: 1.2em;
-webkit-border-radius: 6px;
width: 30%;
position: relative;
display: block;
margin-left: auto;
margin-right: auto;
text-align: center;
}
a.down:hover{
text-decoration: underline;
color: white;
}
Because z-index works only on elements which are NOT set asposition: static. Bear in mind that every element is set as default to position:static.
Try set to position:absolute; or relative your element.
Also all other types of positioning, like position:fixed, position:sticky.
So I've taken a look at your code and the reason your button doesn’t work is because the div with the ID of #hero (which contains the button) is below the body because it has a z-index of -1.
Set the z-index for #hero to 0 or higher and the button will work.
#hero {
padding-top: 25em;
width: 100%;
height: 30em;
position: relative;
z-index: 0;
}
Check out this JS Fiddle I've created for you:
https://jsfiddle.net/8fqwr6ca/
Edit: Oh, and I forgot to mention–since you want the image to be below, set the #hero 's z-index to 1, set #heroImage to 0, and overlay to 2. That should do the trick (if what I think you want is correct).