Kinda new to HTML, want to edit my navigation bar so that it has an image behind it and the nav bar sits at the bottom of the image. How do I do this?
After looking at a few forum posts, this is what I tried:
#cover {
background-image: url("Images\FB Cover.png");
}
<div id="cover">
<div>
<nav>
<li>Home</li>
<li>About DRC</li>
<li>Our Products</li>
<li>Contact</li>
</nav>
</div>
</div>
#cover {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: url(http://lorempixel.com/800/600) no-repeat 50% 50% / cover;
}
menu {
position: absolute;
left: 20px;
bottom: 20px;
}
a {
color: #fff;
}
<div id="cover">
<menu>
<li>Home</li>
<li>About DRC</li>
<li>Our Products</li>
<li>Contact</li>
</menu>
<div>
simple example
to place image as background of DOM element you can use, background-image css property.
For example
background-image: url('https://static.pexels.com/photos/87646/horsehead-nebula-dark-nebula-constellation-orion-87646.jpeg');
W3School has great documentation about css properties.
here is the link
Related
I'm very, very new to HTML and CSS, so sorry for my ignorance! I'm trying to add an image to my header, to go to the left and above the navigation. Any help anyone can give would be amazing!!
I have tried two ways of adding the image, the first using , but it did not show (I could see the image 'content' highlighted in blue on the page when i was in the console, but i couldn't see the image. The second way I used a , then the css below:
body {
background-color:#4A4849;
margin: 0 auto;
font-family:Arial, helvetica, sans-serif;
}
.Logo {
display: inline;
float:left;
width: 100%;
height: 100%;
background-image: url('../Images/Logo.png');
}
header {
text-align: center;
width: 100%;
height: 15%;
background-color: white;
margin: 0;
}
My full CSS includes the below...i feel like the problem is to do with the , as in the console the dimensions show as 1304x0 (but I am able to see the navigation) I therefore tried adjusting the header, which is why it duplicates with the .topnav.(see below) :)
.topnav {
font-weight: bold;
background-color: white;
overflow: hidden;
position: fixed;
top: 0;
left 0;
width:100%;
height:15%;
}
.topnav ul {
list-style-type:none;
overflow: hidden;
margin:0;
padding: 0;
}
.topnav li {
display:inline;
padding: 0px;
margin: 0px;
}
.topnav a {
float: right;
color: #4A4849;
text-align: center;
padding: 20px 10px;
text-decoration:none;
width:10%;
}
It would be great if anyone could help, as I've tried different things based on resources i've found online!
*HTML, in case you need it:
<body>
<header>
<div class="Logo"></div>
<nav>
<div class="topnav">
<ul>
<li>CONTACT US</li>
<li>ABOUT US</li>
<li>GRAPHIC DESIGN</li>
<li>MARKET</li>
<li>HOME</li>
</ul>
</div>
</nav>
</header>
There are a few things that can be changed with how you are setting things up:
I would recommend not making your logo the background-image on a div, when an <img> tag will work better in your case (<img src="path/to/your/logo.png">).
If you do use it as a background-image on a div, you have to remember that background images do not affect the height of an element.
Setting a % height on the .Logo div will also not work, since a percentage height needs to be relative to a containing element and you also set it to an inline element (height will not apply). Since, its parent (header) has as height of 15%, but that element also has no reference to 15% - e.g. 15% of what? The body tag would need to have a height set to 100%.
Only for your logo, I would simply do this:
<header>
<img src="your logo link">
<nav>
<div class="topnav">
<ul>
<li>CONTACT US</li>
<li>ABOUT US</li>
<li>GRAPHIC DESIGN</li>
<li>MARKET</li>
<li>HOME</li>
</ul>
</div>
</nav>
</header>
If you absolutely want to make it a background-image:
.Logo {
height: whatever your logo height is;
display: block;
background-image: url( ../Images/logo.png );
background-repeat: no-repeat;
}
<header>
<div class="Logo"></div>
<nav>
<div class="topnav">
<ul>
<li>CONTACT US</li>
<li>ABOUT US</li>
<li>GRAPHIC DESIGN</li>
<li>MARKET</li>
<li>HOME</li>
</ul>
</div>
</nav>
</header>
<style>
header {
text-align: center;
background-image: url('http://i.imgur.com/7L79iny.jpg');
background-size: 100% 100%;
background-repeat: no-repeat;
}
This is the code I'm using to add a background image to my header. How to I make the image semi-transparent without making the rest of the header transparent.
<header>
<center><img src="http://i.imgur.com/EPd7PBU.jpg" height=350 title="source: imgur.com" /></center>
<h1>Taylor's Blog</h1>
<ul>
<li>About Me</li>
<li>Blogs</li>
<li>Contact Me</li>
</ul>
</header>
You cannot change the opacity of a background image with css, only the opacity of an element. However, there is a very easy work-around, that only requires css:
header {
text-align: center;
position:relative;
}
header:after{
content:'';
position:absolute;
z-index:-1;
top:0;
bottom:0;
left:0;
right:0;
background-image: url('http://i.imgur.com/7L79iny.jpg');
background-size: 100% 100%;
background-repeat: no-repeat;
opacity:0.5;
}
<header>
<img src="http://i.imgur.com/EPd7PBU.jpg" height=350 title="source: imgur.com" />
<h1>Taylor's Blog</h1>
<ul>
<li>About Me</li>
<li>Blogs</li>
<li>Contact Me</li>
</ul>
</header>
On another note, <center> is depreciated, and should not be used. In fact, in the case of the html you have, the link and image are already centered with text-align:center;, making the center tag useless.
The best way would be to create an absolutely positioned div that is transparent and is layered under the content.
<style>
header {
position: relative;
}
header .background {
position: absolute;
width: 100%;
height:100;
opacity: .5;
background-image: url('http://i.imgur.com/7L79iny.jpg');
background-size: 100% 100%;
background-repeat: no-repeat;
}
</style>
sadsad
<header>
<div class="background"></div>
<center><img src="http://i.imgur.com/EPd7PBU.jpg" height=350 title="source: imgur.com" /></center>
<h1>Taylor's Blog</h1>
<ul>
<li>About Me</li>
<li>Blogs</li>
<li>Contact Me</li>
</ul>
</header>
This question already has answers here:
Set div width equal to window size
(6 answers)
Closed 8 years ago.
I have a menu I want to be the entire width of the site even when I zoom out but can't manage to make it work, this is my code.
HTML:
<div id="menu">
<ul>
<li>home</li>
<li>contact</li>
<li>about</li>
<ul>
</div>
CSS I Have tried:
#menu {
width: max;
background-color: #f4f4f4;
height: 75px;
}
And
#menu {
width: 1920px;
background-color: #f4f4f4;
height: 75px;
}
Make the width 100% -- change it in your CSS to width: 100%;
HTML :
<div id="menu">
<ul>
<li>home</li>
<li>contact</li>
<li>about</li>
</ul>
</div>
CSS:
#menu {
width: 100%;
background-color: #f4f4f4;
height: 75px;
}
I want to put a navigation under my banner, but when I try to do that it just goes behind my banner (it pretends it isn't there. This is solved by removing position: absolute; but when I do that my banner wont be on top left anymore.
<img class="banner" src="images/banner.png">
<nav class="navigation">
<ul>
<li>Home</li>
<li>Prijzen</li>
<li>Examen</li>
<li>Leerlingen</li>
</ul>
</nav>
css:
.banner
{
width: 100%;
top: 0;
left: 0;
position: absolute;
}
.navigation
{
}
I suggest to use a container for your banner and for your menu like this:
html
<div class="navCont">
<div class="banner">BANNER</div>
<nav class="navigation">
<ul>
<li>Home</li>
<li>Prijzen</li>
<li>Examen</li>
<li>Leerlingen</li>
</ul>
</nav>
</div>
css
.banner
{
width: 100%;
height: 50px;
position: relative;
background: yellow;
float: left;
}
.navigation{
float:left;
}
Also i suggest to use position:relative and float instead of position:absolute.
Take a look to this example:
fiddle
You need to add position: relative to .navigation
Demo
.navigation {
position: relative;
}
I'm struggling with this problem for over an hour and can't get it right, I know these are basics but none solution from google helped, I don't understand what's the problem. I got that navigation bar and I want to vertically center logo and list elements inside it:
<nav id="mainMenu">
<img class="logo" src="images/logo.png" alt="logo" />
<ul id="menu">
<li>Home</li>
<li>About me</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
</nav>
css:
http://klaunfizia.pl/damian/style.css
Here's the demo: http://klaunfizia.pl/damian/
#edit:
When I put margin-top:50% for #menu why it refers to entire body instead of nav element?
Notice - the class name are different. From your existing style, remove: #mainmenu, #menu, and #menu li. Here is an example the code -> DEMO
Here is your new html:
<ul class="nav"> <img class="logo" src="images/logo.png" alt="logo" />
<li>Home
</li>
<li>About me
</li>
<li>Portfolio
</li>
<li>Contact
</li>
Here is your new CSS:
.nav {
border:1px solid #ccc;
border-width:1px 0;
list-style:none;
margin:0;
padding:0;
text-align:center;
background-color:red;
}
.nav li {
display:inline;
}
.nav a {
display:inline-block;
padding:10px;
text-decoration: none;
color: #000000;
}
Since your "nav" element is fixed try wrapping your "ul" element in a div and setting the css of the margin to the distance you desire.
<div style="margin-top:20px">
<ul id="menu">
<li>Home</li>
<li>About me</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
</div>
The vertical spacing of block elements can be a bit tricky as they were never intened to behave that way. So some tricks are always required.
You can center them to the middle by making the list and the logo's position relative, than giving them a 50% top and a negative margin with the half of their height. So just add these properties to the existing ones:
.logo {
position: relative;
top: 50%;
margin-top: -25px;
}
#menu {
position: relative;
top: 50%;
margin-top: -10px;
}
use this:
#mainMenu {
height: 80px;
width: 100%;
background-color: #F00;
position: fixed;
line-height: 80px; /* added */
}
#menu {
float: right;
margin-right: 16%;
display: inline-block; /* added */
}