For my header I'm using the ul and li tags for my nav menu (Portfolio/Contact/About) I'm trying to place the images text (Portfolio/Contact/About) and the slashes in the CSS file instead of my div "navigationMain" in the HTML file but every attempt I tried has failed. Is there a certain way dealing with ul, li tags and placing images within the tags using CSS? Because I've placed my logo and header background in the header within the css file. Also I'm creating this website in notepadd++
http://jsfiddle.net/J4h9Q/7/embedded/result/ http://jsfiddle.net/J4h9Q/8/
HTML:
<div class="header">
<div class="container">
<div class="headerMain"> </div>
<div class="navigationMain">
<ul class="nav">
<li><img src="images/portfolio2.png" alt="portfolio" id="portfoliobutton"></li>
<li><img src="images/slash.png" alt="slash"></li>
<li><img src="images/about.png" alt="about" id="aboutbutton"></li>
<li><img src="images/slash.png" alt="slash"></li>
<li id="contactbutton" class="contact"><img src="images/contact.png" alt="contact"></li>
</ul>
</div>
</div>
CSS:
body,div,ul,li,p{
margin:0;
padding:0;
}
html,body {
margin:0;
padding:0;
}
body{
margin:0;
padding:0;
height:100%;
background: url(../images/background11.png) repeat scroll 0 0;
}
.header {
background: black;
height: 165px;
min-width: 1075px;
}
.container {
height: 165px;
margin-left: auto;
margin-right: auto;
width: 1075px;
}
.headerMain{
height: 165px;
position: relative;
width: 195px;
float: left;
left: 20px;
top: 4px;
background:url(../images/ARlogo8.png) no-repeat center center;
}
.navigationMain{
height: 154px;
margin-left: auto;
margin-top: -4px;
position: relative;
width: 665px;
right: 30px;
}
li{
display: inline;
}
.nav li{
display: inline;
color:white;
position: relative;
top: 70px;
font-family: "Century Gothic", CenturyGothic, AppleGothic, sans-serif;
left: 160px;
font-size:44px;
}
How tied are you to putting the images in CSS? I recommend putting the slashes, if anything, in the CSS. That would immediately reduce the number of list items down to 3 - so it's more "semantic". You should not have a list item just to denote a slash.
Demo: http://jsfiddle.net/YBzA9/1/
Feel free to tweak the dimensions in .nav a when you use your real images.
After you reduce the number of list items, consider one of the following:
(easy solution) putting the images inside of anchor tags in the markup and calling it a day
(a more "correct" solution) styling your anchor like such:
HTML
<ul>
<li>Portfolio</li>
<li>About</li>
<li>Contact</li>
</ul
CSS
.nav li {
background: url('http://dummyimage.com/26x34/000000/fff&text=//');
padding-left: 26px;
}
.nav li:first-child {
background: none;
}
.nav a {
display: block;
text-indent: -999px;
height: 35px;
width: 120px;
}
#portfolio-link {
background: url('http://dummyimage.com/146x35/000000/fff&text=Portfolio');
}
#about-link {
background: url('http://dummyimage.com/146x35/000000/fff&text=About');
}
#contact-link {
background: url('http://dummyimage.com/146x35/000000/fff&text=Contact');
}
This allows text to still be read (search engines, screen readers) but still maintain visual appeal.
You could set that images as background without repeating it. You also need to set a min height and width to be sure that you can see the image later. You can also store the image in the css file if you store it base64 encoded.
In general I would just fix the links to your images. Try using absolute urls beginning with a single slash.
Related
I have a problem where the links are not shown in a row but instead some of them are stacked underneath eachother. Are there any step by step tips out here on how I can solve it and also an explanation to why my links in the navbar shows up messed up?? I only wanna use CSS and HTML, no JS.
Please take note: I have a picture of how i want the header to look and also a print screeen of how it looks in GChrome right now. However i am not familiar with posting questions here on StackOverflow so i dont know how to post 2 images in the same question. So please dont be too hardjudging since I am a beginner.
header {
border-bottom: 4px solid #000;
}
.logo img{
position: absolute;
margin-top: 15px;
margin-left: 10px;
}
.header ul {
padding: 0;
margin: 0 0 0 150px;
list-style: none;
float: right;
}
.header li {
float:left;
font-family: 'Brother 1816';
font-weight: bold;
font-size: 2rem;
color: #000;
}
nav {
width: 100%;
background: #FFFFFF;
overflow: auto;
}
nav a{
width: 400px;
display: block;
text-decoration: none;
color: #a71b1a;
}
<header class="header">
<div class="logo"> <img src="logo/logo_250x150.png" alt="Freyas logotype.">
</div>
<nav class="navigation">
<ul>
<li>HOME</li>
<li>ABOUT ME</li>
<li>PORTFOLIO</li>
<li>SERVICES</li>
<li>CONTACT ME</li>
</ul>
</nav>
</header>
How it should look
How it looks
The width property associated with your links is causing them to take up 400px each which then wraps down the page
nav a{
width: 400px;
}
remove the width property and the links should sit on the same line.
Alternatively use flexbox https://www.w3schools.com/css/css3_flexbox.asp to space the links across the page as you desire.
Width and display: block in your a tag are causing the issue. Also add display: inline to your <li> properties to make elements render in the same row.
Looking to resize a big image down to a thumbnail within a list item:
HTML code
<div class="header">
<ul class="nav">
<li><img src="imgs/logo.jpg"></li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
CSS code
.header {
width: 100%;
}
.nav {
max-width: 92.5%;
margin: 0 auto;
padding: 1% 0% 0.75% 1%;
}
.nav li {
display: inline;
font-family: 'Raleway', sans-serif;
font-size: 1em;
font-weight: 600;
margin-right: 2%;
}
No matter what I try, the image breaks out of the li "box" ... I can obviously resize it to fit inside, but I want it to take up the entire li box based on how big the other li are... any suggestions?
add image as background:
background-image: url('https://www.w3schools.com/css/img_fjords.jpg');
check this
https://jsfiddle.net/nqo79yxm/4/
Provide the height to the img tag.
Like below:
img{
height :20px;
}
Now the image will have a fixed height, otherwise the image will take height: auto.
I am new to HTML5 & CSS and New since HTML when it first came to life
Anyhow I am working on learning how to code in HTML5 & CSS3 at the moment.. but have ran into a road block...
I want to get my Copy right information on the left of the footer background and my browser icons to the right of my footer background.... I have been playing with the problem for 9 hours I don't give up easily even tried some suggestions I found here which did not work...
If you would like to see actual page you can goto
http://cowboy0629.ddns.net/test
.mainFooter {
width: 97%;
float: left;
height: 40px;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
background-color: #141476;
margin: 2% 1.5% 2% 1.5%;
}
.footerIcons img.chrome {
width: auto;
height: 20px;
}
.footerIcons img.firefox {
width: auto;
height: 23px;
}
.footerIcons img.safari {
width: auto;
height: 23px;
}
.footerIcons {
float: right;
height: 9px;
}
.footerIcons ul {
float: right;
padding: 0;
margin: 0 auto;
}
.footerIcons li {
float: right;
list-style:none;
margin-left:5px;
}
.footerIcons span p {
height: 20px;
float: left;
color: #3399FF;
width: 97%;
margin: 9px;
}
<footer class="mainFooter">
<div class="footerIcons">
<span>
<p>Copyright © 2017 cowboyDesigns.com</p>
</span>
<ul>
<li>
<img class="chrome" src="images/icons/black-chrome-icon.png" alt="">
</li>
<li>
<img class="firefox" src="images/icons/black-firefox-icon.png" alt="">
</li>
<li>
<img class="safari" src="images/icons/black-safari-icon2.png" alt="">
</li>
</ul>
</div>
</footer>
You could use relative positioning on the <ul> element.
.footerIcons ul {
position: relative;
top: -47px;
}
This might be a sloppy solve than doing something like setting the container size to 30% and getting div alignment.
The solutions above will fix the issue but they seem more likely to be hacks,
p and ul are block elements and they won't be in the same line by default.
you need to replace the existing CSS rules with the set the CSS as below
.mainFooter p {
color: #3399FF;
display: inline-block;
margin: 9px;
}
.mainFooter ul {
display: inline-block;
float: right;
list-style: none;
margin: 0 auto;
}
.mainFooter img {
width: 30px;
height: 30px;
margin: 5px;
}
there is no need for separate rules for each browser icon and use icons of same width and height.
Just change the float setting to left in .floatericons in the css file for the copyright part.
.footerIcons {
float: left;
height: 9px; }
Add this part:
.footerIcons ul {
position: relative;
top: -47px;
left:600px;
float:right;}
There's multiple ways I can think of to accomplish this.
This works:
<footer class="mainFooter">
<ul>
<li style="float:left">Copyright © 2017 cowboyDesigns.com</li>
<li style="float:right"><img class="chrome" src="images/icons/black-chrome-icon.png" alt=""></li>
<li style="float:right"><img class="firefox" src="images/icons/black-firefox-icon.png" alt=""></li>
<li style="float:right"><img class="safari" src="images/icons/black-safari-icon2.png" alt=""></li>
</ul>
</footer>
It could use a little love with regards to vertical alignment, but it works.
I wouldn't set links in navigation bars to display:inline because it makes them harder to click (since they don't fill up the block around them)...I also use utility CSS float classes, not inline styles.
Floats and positioning are one of the hardest things to learn in CSS but there's an easy and fast way to get it sorted out.
Check out this video on using Chrome DevTools as an IDE
Not only can you see the changes in real time, you can even map them back to your source files so changes you make are saved.
Or you could just use a framework that has solutions for things like this baked right in. I'm a big fan on Foundation and the grid and alignment classes would be well-suited to this problem.
It seems you're doing this for school so maybe you can't use a framework but you can look at how they solved the problem and what code they used.
Just building on top what you have created you will have something similar to this:
footer {
width: 97%;
height: 40px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
background-color: #141476;
margin: 2% 1.5%;
}
footer p,
.footerIcons{
line-height: 20px;
margin: 9px;
}
footer p{
float: left;
color: #3399FF;
}
.footerIcons {
float: right;
}
.footerIcons img.firefox,
.footerIcons img.safari,
.footerIcons img.chrome{
width: auto;
height: 23px;
}
<footer>
<p>Copyright © 2017 cowboyDesigns.com</p>
<div class="footerIcons">
<img class="chrome" src="images/icons/black-chrome-icon.png" alt="">
<img class="firefox" src="images/icons/black-firefox-icon.png" alt="">
<img class="safari" src="images/icons/black-safari-icon2.png" alt="">
</div>
</footer>
Images I place are blocking me from clicking links, and I think it is because the image is possibly larger than I thought (though I think I cropped it and I am not sure if it is something else.
Here is a picture (I moved he image as far over as I could in order to avoid this issue, but I would like to move the image closer if this problem can be fixed and I feel it will be helpful to know in the future):
Note: If I move it right it does not push the content or anything, it just makes the links in the nav bar unclickable (if that was not clear).
Here is the HTML:
<nav>
<ul>
<li class="current">Home</li>
<li>Jehovah's Witness</li>
<li>Wood Block Print</li>
<li>Jazz</li>
<li>Being Ethical and Socially Responsible </li>
</ul>
</nav>
<div class="container">
<header>
<h1>
<img src="images/banner.png" alt="banner">
Designer Websites
</h1>
</header>
and my CSS:
nav ul
{
list-style-type: none;
text-align: center;
}
nav ul li
{
padding: 5px;
display: inline-block;
border: solid 1px black;
color: black;
background-color: tan;
}
.current
{
background-color: yellow;
}
body
{
background-color: tan;
font-family: Arial, "Times New Roman", "Sans Serif", Georgia;
}
.container
{
width: 80%;
max-width: 960px;
margin:0px auto;
}
h1 img
{
height: 40%;
position:absolute;
left:-15px;
top: -30px;
}
New picture with the absolute position removed:
I think your "absolute" positioned banner image was floating over navbar. That's the reason it was not clickable.
Remove this code (You may keep the "height" to set fixed height for your image)
h1 img {
height: 40%;
position: absolute;
left: -15px;
top: -30px;
}
Now image and heading will be left aligned. You can simply align them by adding text-align:center in .container. Or you can add this code:
header {
text-align: center;
}
Try adding this in order to put anchor "above" the img
h1 img {
z-index: 1;
}
h1 a {
position: relative;
z-index: 2;
}
im wondering if anyone could please help me with a css / html issue.
I have a complex background image. The menu div is positioned at the correct location to overlay the background where it is ment to position. The entire LI has a hover rollover image with a display type of block. The result is that when the mouse is over the list href the entire block rollover works..
The problem happens however when i attempt to add padding to create a buffer between the list item text and its border.. Things start to go funny... I'll add a screen shot.. Padding is required to move it from the border.
The second problem exists that i cant valign the text to the middle without applying a line height.. The solution works great until items wrap.. I need to be able to wrap menu item text..
The below example shows the state with the current CSS/HTML. The menu bar and rollover are in place as expected. Amend i cant place the image to to restrictions on posting as a new person here.. The example can however be found at 213.40.100.100 / example1.jpg
The below example shows the state when padding OR margin is added. The LI seems to completly shift, not moving the interal text..
213.40.100.100 / example2.jpg
<div id="wrapper">
<div
id="header">Header</div> <div
id="menu">
<ul>
<li><a>Contact Us</a></li>
<li><a>Recommends</a></li>
<li><a>Deals</a></li>
<li><a>Home</a></li>
</ul> </div> <div id="content">Content</div>
<div id="footer">Footer</div>
</div>
#charset "utf-8"; /* CSS Document */
* { margin: 0; padding: 0; }
body {
padding-top: 10px;
background: url(background.jpg) no-repeat center top; height:100%;
}
div#wrapper {
margin: auto;
height: 100%;
width: 978px;
min-width: 978px;
}
div#header {
height: 196px;
}
div#menu {
height: 69px;
position:
relative;
}
div#menu ul {
height: 69px;
list-style-type: none;
}
div#menu ul li {
display: block;
height: 69px;
width: 140px;
float: right;
padding: 5px;
}
div#menu ul li a:hover {
display:block;
background:url(menu_red_bg.jpg) repeat-x; height: 69px; color:#FF0;
font-family: Arial, Helvetica, sans-serif;
font-size: large;
}
div#menu ul li a {
text-decoration: none;
color:#000;
font-family: Arial, Helvetica, sans-serif;
font-size: large;
}
div#content { margin-top: 80px; }
I think you are adding the padding to the wrong element.
or you add a "margin" to the <li> or you add a padding to div#menu
I should do this:
A div#menu with the yellow gradient background, with the 5px padding and a margin: 80px 0 0 0;
Inside this div, the <ul><li>...</li></ul>
You don't need to add any padding or margin to the li, just be sure the height of each li is less than the div#menu heigh + padding.