changing specific elements only under a specific class - html

New to CSS . I am experiencing a problem where i only want to change elements within a class only. I have looked online and tried many ways but i really dont know whats the problem.
Here is the html part:
<nav class = "choice">
<ul>
<li>Sign-in</li>
<li> | </li>
<li>Register</li>
<li> | </li>
<li>Request</li>
</ul>
</nav>
<footer class = "footer">
<h2>Site Map</h2>
<ul>
<li>Home</li>
<li>Register</li>
<li><a class = "active" href="about.html">How it All Works</a></li>
<section id = "copy">
<p>© 2018. All Rights Reserved.</p>
</section>
</ul>
</footer>
Here is the css:
.choice{
text-align : right;
}
ul {
list-style-type: none;
margin: 0;
padding: 1em;
width: 200px;
color:white;
}
li a {
display: block;
color: #00ff00;
padding: 8px 16px;
text-decoration: none;
}
li a.active {
background-color: #4CAF50;
color: white;
}
li a:hover:not(.active) {
background-color: #555;
color: white;
}
#copy{
position: absolute;
width: 100%;
color: #fff;
line-height: 40px;
font-size: 1em;
text-align: center;
bottom:0;
}
So long story short. I just want to change the elements "li" and "ul" under the class choice only but because i have same elements in the footer part, the selectors for the footer part will also change the elements in the class choice. What is the correct way to change g a specific part of a element only for that class ? Thank you

Try adding .choice to select elements under it:
.choice {
text-align : right;
}
.choice ul {
list-style-type: none;
margin: 0;
padding: 1em;
width: 200px;
color:white;
}
.choice li a {
display: block;
color: #00ff00;
padding: 8px 16px;
text-decoration: none;
}
.choice li a.active {
background-color: #4CAF50;
color: white;
}
.choice li a:hover:not(.active) {
background-color: #555;
color: white;
}
#copy{
position: absolute;
width: 100%;
color: #fff;
line-height: 40px;
font-size: 1em;
text-align: center;
bottom:0;
}

Add .choice to all ul and li in CSS which you want to change.
For example: .choice ul, .choice li > a, .choice li > a.active
Below is working code:
.choice {
text-align: right;
}
.choice ul {
list-style-type: none;
margin: 0;
padding: 1em;
width: 200px;
color: white;
}
.choice li > a {
display: block;
color: #00ff00;
padding: 8px 16px;
text-decoration: none;
}
.choice li > a.active {
background-color: #4CAF50;
color: white;
}
.choice li > a:hover:not(.active) {
background-color: #555;
color: white;
}
#copy {
position: absolute;
width: 100%;
color: #fff;
line-height: 40px;
font-size: 1em;
text-align: center;
bottom: 0;
}
<nav class="choice">
<ul>
<li>Sign-in</li>
<li> | </li>
<li>Register</li>
<li> | </li>
<li>Request</li>
</ul>
</nav>
<footer class="footer">
<h2>Site Map</h2>
<ul>
<li>Home</li>
<li>Register</li>
<li><a class="active" href="about.html">How it All Works</a></li>
<section id="copy">
<p>© 2018. All Rights Reserved.</p>
</section>
</ul>
</footer>

Related

Problem with making my menu horizentel (ul)

i have a problem with making the list horizontally, I tries putting in display: inline; and float: right; doesn't seem to work. Hope you can help, and sorry for the badly explained problem, I just started the education. Have a great day
ul {
display: inline;
list-style-type: none;
margin: 0px;
padding: 0px;
margin-left: -17px;
width: 200px;
line-height: 350%;
}
li a {
display: inline;
color: #FFFFFF;
padding: 15px;
text-decoration: none;
font-size: 35px;
font-weight: 400;
}
li a.active {
color: white;
}
li a:hover:not(.active) {
color: #F39D2A;
}
<body style="background-color:black;">
<div class="menu">
<ul>
<li>Home</li>
<li>Om os</li>
<li>Portfojle</li>
<li>Kontakt os</li>
</ul>
</div>
Try this code to set your menu horizontal and remove color white or give background color so you can visible text properly give float property to li only.
ul {
display: inline;
list-style-type: none;
margin: 0px;
padding: 0px;
width: 200px;
}
li {
float: right;
}
li a {
display: inline;
color: #000;
padding: 15px;
text-decoration: none;
font-size: 35px;
font-weight: 400;
}
li a.active {
color: white;
}
li a:hover:not(.active) {
color: #F39D2A;
}
<div class="menu">
<ul>
<li>Home</li>
<li>Om os</li>
<li>Portfojle</li>
<li>Kontakt os</li>
</ul>
</div>
You can use flexbox like display: flex in ul.
ul {
display: flex;
width: 100%
}
It will align ul items in horizontal.
HTML:
<body style="background-color:black;">
<div class="menu">
<ul>
<li>Home</li>
<li>Om os</li>
<li>Portfojle</li>
<li>Kontakt os</li>
</ul>
</div>
CSS:
ul {
display: flex;
width: 100%
}
li a {
display: inline;
color: #FFFFFF;
padding: 0 25px;
text-decoration: none;
font-size: 35px;
font-weight: 400;
}
li a.active {
color: white;
}
li a:hover:not(.active) {
color: #F39D2A;
}
I belive this will work. If you want adjust more, you can read about flex concept here (https://css-tricks.com/snippets/css/a-guide-to-flexbox/).

Unable to change the background color of my bottom navigation bar

I'm trying to create a clone of the google homepage as one of my first html/css projects. This is the first time I've ever coded and I'm having trouble with setting the background colour for one of the navigation bars at the bottom of the screen. I was able to set the background colour of the upper navigation bar (the one with the country name on it) but when I try to set the background colour for the lower navigation bar (the one with the Advertising and Business links) it doesn't show and the bar remains white.
This is my html code for the lower navigation bars
<footer class="bottom_nav">
<div class="country_nav">
<ul>
<li>Canada</li>
</ul>
</div>
<div class="bottom_nav_l">
<ul>
<li>Advertising</li>
<li>Business</li>
<li>How Search Works</li>
<ul>
</div>
<div class="bottom_nav_r">
<ul>
<li>Settings</li>
<li>Terms</li>
<li>Privacy</li>
</ul>
</div>
</footer>
This is my CSS
.country_nav {
background-color: #f2f2f2;
color: rgba(0,0,0,0.54);
border-top: 1px solid #e4e4e4;
padding-top: 10px;
padding-bottom: 10px;
padding-left: 25px;
}
.country_nav li {
font-size: 14px;
font-family: arial, sans-serif;
}
.bottom_nav_l li {
float: left;
margin: 10px;
font-size: 14px;
}
.bottom_nav_r li {
float: right;
margin: 10px;
font-size: 14px;
}
.bottom_nav_l li a {
display: block;
text-decoration: none;
color: rgba(0,0,0,0.54);
}
.bottom_nav_r li a {
display: block;
text-decoration: none;
color: rgba(0,0,0,0.54);
}
.bottom_nav_l li a:hover {
text-decoration: underline;
}
.bottom_nav_r li a:hover {
text-decoration: underline;
}
.bottom_nav_l {
padding-left: 15px;
background-color: #f2f2f2;
}
.bottom_nav_r {
padding-right: 15px;
background-color: #f2f2f2;
}
.bottom_nav {
padding-top: 170px;
}
And this is what the page looks like for reference. I want the lowest bar to be grey as well.
google homepage clone
Can anyone help me out?
You do not need to use ul li. You can wrap your bottom link in to div and use display: flex and justfify-content:space-between to have space between your link.
Also i have modified the a links to match exactly as google footer by adding padding and text-decoration:none
Exact copy of google footer in demo.
Working Demo: https://jsfiddle.net/kx291hqm/
Run snippet below.
.country_nav {
background-color: #f2f2f2;
color: rgba(0,0,0,0.54);
border: 1px solid #e4e4e4;
padding-top: 10px;
padding-bottom: 10px;
padding-left: 27px;
}
.bottom_nav_l li a {
display: block;
text-decoration: none;
}
.bottom_nav_r li a {
display: block;
text-decoration: none;
color: rgba(0,0,0,0.54);
}
.bottom_nav_l li a:hover {
text-decoration: underline;
}
.bottom_nav_r li a:hover {
text-decoration: underline;
}
.bottom_nav_r {
padding-right: 27px;
}
.bottom_nav {
padding-top: 170px;
}
.bottom_link {
display: flex;
justify-content: space-between;
line-height: 40px;
background: #f2f2f2;
}
a {
text-decoration: none;
white-space: nowrap;
color: #5f6368;
padding-left: 27px;
}
<footer class="bottom_nav">
<div class="country_nav">
Canada
</div>
<div class="bottom_link">
<div class="bottom_nav_l">
Advertising
Business
How Search Works
</div>
<div class="bottom_nav_r">
Settings
Terms
Privacy
</div>
</div>
</footer>
Try with adding following css:
.bottom_nav{
background-color:blue;
}
I hope this will help you..
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.country_nav {
background-color: #f2f2f2;
color: rgba(0,0,0,0.54);
border-top: 1px solid #ededed;
padding-top: -1px;
padding-bottom: 1px;
padding-left: 25px;
}
.country_nav li {
font-size: 14px;
font-family: arial, sans-serif;
margin-left: -10px;
}
section{
background-color: #ebebeb;
}
.bottom_nav_l li {
float: left;
margin: 10px;
font-size: 14px;
}
.bottom_nav_r li {
float: right;
margin: 10px;
font-size: 14px;
list-style-type: none;
}
.bottom_nav_l li a {
display: block;
margin-left: -10px;
text-decoration: none;
color: rgba(0,0,0,0.54);
}
ul {
list-style-type: none;
}
.bottom_nav_r li a {
display: block;
text-decoration: none;
color: rgba(0,0,0,0.54);
}
.bottom_nav_l li a:hover {
text-decoration: underline;
}
.bottom_nav_r li a:hover {
text-decoration: underline;
}
.bottom_nav_l {
padding-left: 15px;
background-color: #f2f2f2;
}
.bottom_nav_r {
padding-right: 15px;
background-color: #d7d7d7;
}
.bottom_nav {
padding-top: 0px;
position: relative;
top: 460px;
}
</style>
</head>
<body>
<footer class="bottom_nav">
<div class="country_nav">
<ul>
<li>Canada</li>
</ul>
</div>
<section>
<div class="bottom_nav_l">
<ul>
<li>Advertising</li>
<li>Business</li>
<li>How Search Works</li>
<ul>
</div>
<div class="bottom_nav_r">
<ul>
<li>Settings</li>
<li>Terms</li>
<li>Privacy</li>
</ul>
</div>
</section>
</footer>
</body>
</html>

How do I highlight a whole row in css?

I'm trying to get the orange part across the whole screen instead of just on the text? So when someone hovers over it, the orange color comes up on the selected menu item
Capture
Here is my code
* {
margin: 0;
padding: 0;
}
html {
background: #76787a;
font-family: Arial, sans-serif;
font-weight: bold;
}
.container {
text-align: center;
list-style-type: none;
}
a {
text-decoration: none;
background-color: #c67b3d;
}
a:hover {
background-color: green;
}
.menu li a {
color: yellow;
font-size: 160px;
}
<div class="container">
<nav class="menu">
<li>HOME</li>
<li>ABOUT</li>
<li>WORK</li>
<li>CONTACT</li>
</div>
Amend your css file:
Put:
background-color: #c67b3d; max-width: 100%;
in .container
Make .menu li a display: block.
Not sure if you want margin-bottom: 10px;
* {
margin: 0;
padding: 0;
}
html {
background: #76787a;
font-family: Arial, sans-serif;
font-weight: bold;
}
.container {
text-align: center;
list-style-type: none;
}
a {
text-decoration: none;
background-color: #c67b3d;
}
a:hover {
background-color: green;
}
.menu li a {
display: block;
margin-bottom: 10px;
color: yellow;
font-size: 160px;
}
<div class="container">
<nav class="menu">
<ul>
<li>HOME</li>
<li>ABOUT</li>
<li>WORK</li>
<li>CONTACT</li>
</ul>
</nav>
</div>
Simply add display: block to the a element. You can even get rid of <li> elements and the <nav> element.
* {
margin: 0;
}
.container {
text-align: center;
}
a {
text-decoration: none;
display: block;
background-color: orange;
}
a:hover {
background-color: green;
}
<div class="container">
HOME
ABOUT
WORK
CONTACT
</div>
https://jsfiddle.net/pfvf10g5/
* {
margin: 0;
padding: 0;
}
html {
background: #76787a;
font-family: Arial, sans-serif;
font-weight: bold;
}
.container {
text-align: center;
list-style-type: none;
background-color: #c67b3d;
max-width: 100%;
}
a {
text-decoration: none;
background-color: #c67b3d;
}
a:hover {
background-color: green;
}
.menu li a {
color: yellow;
font-size: 160px;
}
<div class="container">
<nav class="menu">
<li>HOME</li>
<li>ABOUT</li>
<li>WORK</li>
<li>CONTACT</li>
</div>
colour effect need to be apply on .menu li instead of .menu li a.
snippet of this code is
here.

Why is my text not in middle of the blocks on nav bar? What am I doing wrong?

I want the text in the center but they all seem to be sticking on top of the nav bar.
see my image attached. Please tell me what I am doing wrong.
edit:I am unable to attach image as I don't have 10 reputations.
body {
background-color: white;
}
ul {
list-style-type: none;
}
li {
float: left;
}
a:link,
a:visited {
display: block;
padding: 0;
width: 200px;
height: 30px;
background-color: blue;
text-decoration: none;
font-family: arial;
color: white;
font-weight: bold;
text-align: center;
}
a:hover,
a:active {
background-color: green;
}
<body>
<ul>
<li> Home
</li>
<li> Products
</li>
<li> Services
</li>
<li> Contact us
</li>
<li> About us
</li>
<li> Blog
</li>
</ul>
</body>
use line-height same has height to align text of 'a' vertically to center.
set the style on a or a:link, a:visited
a {
line-height: 30px;
}
jsfiddle demo
Take padding from top padding-top:12px of a:link, a:visited in your css
and it's done
Because of that you gave padding:0 the text is sticking to the top.
so i changed two thing and it works for me.
padding:5px 0px;
height:20px;//To make your `li height 30px`
Fiddle: Text at center
I think this is what you want...Just add a padding-top to the anchor tag.
body {
background-color: white;
}
ul {
list-style-type: none;
}
li {
float: left;
}
a:link,
a:visited {
display: block;
width: 200px;
height: 30px;
background-color: blue;
text-decoration: none;
font-family: arial;
color: white;
font-weight: bold;
text-align: center;
padding-top:12px;
}
a:hover,
a:active {
background-color: green;
}
<body>
<ul>
<li> Home
</li>
<li> Products
</li>
<li> Services
</li>
<li> Contact us
</li>
<li> About us
</li>
<li> Blog
</li>
</ul>
</body>
add line height to a tag
<style>
body {
background-color: white;
}
ul {
list-style-type: none;
}
li {
float: left;
}
a:link,
a:visited {
display: block;
padding: 0;
width: 200px;
height: 30px;
line-height: 30px;
background-color: blue;
text-decoration: none;
font-family: arial;
color: white;
font-weight: bold;
text-align: center;
}
a:hover,
a:active {
background-color: green;
}
</style>
Add padding-top:10px; in a:link, a:visited
Here is working fiddle :Demo

CSS and HTML Navigation Bar Error

I am trying to make a basic site with HTML & CSS, with a navigation bar, but I have a problem with it [below]:
body
{
background-color: #666;
}
.font_title
{
font-family: "Segoe UI";
font-weight: bold;
font-size: 60px;
text-align: center;
}
#title
{
width: 800px;
}
#container
{
position: relative;
margin: auto;
width: 800px;
height: 995px;
background-color: #CCCCCC;
}
#navigation_holder
{
position: relative;
margin: auto;
width: 800px;
}
.navigation_button
{
font-family: "Segoe UI";
text-align: center;
font-size: 26px;
width: 200px;
height: 40px;
background-color: #09C;
}
.navigation_button:hover
{
background-color: #09F;
}
<div id="container"> <!-- The main container -->
<div class="font_title", id="title"> Our Site</div>
<div id="navigation_holder">
<div id="navigation_button_1", class="navigation_button"> Home </div>
<div id="navigation_button_2", class="navigation_button"> About </div>
<div id="navigation_button_3", class="navigation_button"> Services </div>
<div id="navigation_button_4", class="navigation_button"> Contact </div>
</div>
<!-- More DIVs in the container -->
</div>
The problem is - all my navigation buttons are stacked up ontop of each other, not on a row. What am I doing wrong?
Instead of making them divs, use anchor tags inside lists. Here's the image and the complete working code for you:
<html>
<head>
<style>
body
{
background-color: #666;
}
.font_title
{
font-family: "Segoe UI";
font-weight: bold;
font-size: 60px;
text-align: center;
}
#title
{
width: 800px;
}
#container
{
position: relative;
margin: auto;
width: 800px;
height: 995px;
background-color: #CCCCCC;
}
#navigation_holder
{
position: relative;
margin: auto;
width: 800px;
}
.navigation_button
{
font-family: "Segoe UI";
text-align: center;
font-size: 26px;
width: 200px;
height: 40px;
background-color: #09C;
}
.navigation_button:hover
{
background-color: #09F;
}
ul
{
list-style-type:none;
margin:0;
padding:0;
overflow:hidden;
}
li
{
float:left;
}
a:link,a:visited
{
display:block;
width:200px;
font-family: "Segoe UI";
text-align: center;
font-size: 26px;
width: 200px;
height: 40px;
background-color: #09C;
}
a:hover,a:active
{
background-color: #09F;
}
</style>
</head>
<body>
<div id="container"> <!-- The main container -->
<div class="font_title", id="title"> Our Site</div>
<div id="navigation_holder">
<ul>
<li id="navigation_button_1" > Home </li>
<li id="navigation_button_2" > About </li>
<li id="navigation_button_3" > Services </li>
<li id="navigation_button_4" > Contact </li>
</ul>
</div>
<!-- More DIVs in the container -->
</div>
</body>
</html>
The problem is that divs are block elements, thus they naturally position themselves on top of each other. You can use several methods to get them to behave. Applying a display: inline-block to your .navigation_button class is what I would prefer in most cases. In this case, however, a float: left will work just as well.
The two methods have their benefits and drawbacks, but floats can become problematic because they essentially become unrecognizable to non-floated elements (in the same way position: absolute does).
As an aside, if I were you, I'd pull the height off your container, change #navigation_holder to a <nav>, and perhaps even pull the ids (and possibly even the classes!) off of your individual navigation elements. Heck, you could even take out the inner divs entirely, and replace them with a ul whose li were display: inline (it would be more semantic).
You could then reference them like this:
.navigation_holder ul li {
display: inline;
padding-left: 40px; /* or whatever */
}
And if you need to target only the first or last:
.navigation_holder ul li:first-of-type {
// styles
}
.navigation_holder ul li:last-of-type {
// styles
}
To pop the default styles off the ul:
.navigation_holder ul {
list-style-type: none;
}
A reply to your question, and a question to your question...
What are you looking for?
Here are 3 examples:
1 Providing you wanted a normal left hand horizontal inline-list you would do:
HTML
<div id="navigation_holder">
<ul>
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Contact</li>
</ul>
</div>
CSS
#navigation_left ul
{
margin: 0;
padding: 0;
list-style-type: none;
}
#navigation_left ul li { display: inline; }
#navigation_left ul li a
{
font-family:"Helvetica Neue","Helvetica",Helvetica,Arial,sans-serif;
text-decoration: none;
padding: .2em 1em;
color: #DDD;
background-color: #0099CF;
border-radius: 4px;
}
#navigation_left ul li a:hover
{
color: #FFF;
background-color: #00BEF9;
}
2 Providing you want to center your li elements.
HTML
<div id="navigation_center">
<ul>
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Contact</li>
</ul>
</div>
CSS
#navigation_center ul
{
margin: 0;
padding: 0;
list-style-type: none;
text-align: center;
}
#navigation_center ul li { display: inline; }
#navigation_center ul li a
{
font-family:"Helvetica Neue","Helvetica",Helvetica,Arial,sans-serif;
text-decoration: none;
padding: .2em 1em;
color: #DDD;
background-color: #0099CF;
border-radius: 4px;
}
#navigation_center ul li a:hover
{
color: #FFF;
background-color: #00BEF9;
}
3 Providing you want to center your li elements with a solid background.
HTML
<div id="navigation_center_full">
<ul class="full">
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Contact</li>
</ul>
</div>
CSS
#navigation_center_full ul
{
margin: 0;
padding: 0;
list-style-type: none;
text-align: center;
padding: .2em 1em;
color: #DDD;
background-color: #0099CF;
}
#navigation_center_full ul li { display: inline; }
#navigation_center_full ul li a
{
font-family:"Helvetica Neue","Helvetica",Helvetica,Arial,sans-serif;
text-decoration: none;
padding: .2em 1em;
color: #DDD;
background-color: #0099CF;
border-radius: 4px;
}
#navigation_center_full ul li a:hover
{
color: #FFF;
background-color: #00BEF9;
}
Pretty sure this should help you.
Why you dont use <ul> and <li> tags? I think is better. Then in CSS you must use:
display: inline
One example in: http://www.w3schools.com/css/tryit.asp?filename=trycss_float5