background-color stays white - html

I'm building a website but for some reason my background-color is not working. Nothing happens, the background-color just stays white.
The code that is not working is below :
.sub-header {
background-color: black !important;
}
My complete code on jsfiddle: https://jsfiddle.net/j7mdqaop/ and the interesting lines are 158, 159, 160.

if i understand it correctly you are trying to do :
HTML
<header class="sub-header">
<div class="dropdown">
Chezzles
<i class="fa fa-bars fa-fw bars" style="font-size:24px"></i>
</div>
</header>
CSS
.sub-header {
background-color: black !important;
}
.sub-header .dropdown {
background-color: black !important;
width: 100%;
height: 25px;
padding: 5px;
}
.sub-header .dropdown * {
color: white;
}
.sub-header .dropdown i {
top: 15px;
}
.main-navbar-heading-2 {
top: 5px;
left: 5px;
text-decoration: none;
color: black;
font-family: Raleway;
font-size: 1.3em;
}
like this fiddle https://jsfiddle.net/Tanbi/j7mdqaop/4/

It's because all elements in your .sub-header are not in the flow (because of absolute position)
See this fiddle
.sub-header {
background-color: black !important;
display: block;
}
.main-navbar-heading-2 {
top: 5px;
left: 5px;
text-decoration: none;
color: black;
font-family: Raleway;
font-size: 1.3em;
}
Note : I add display: block; to make the background-color property occupy all the line instead of just the title "Chezzles" but you can keep inline if you wants.

Related

CSS Transition unwantedly Moves my text. How do I prevent this from happening

So I've been learning front-end development recently, and this problem really bugs me. I wanted to make an on-hover animation for my links.
Here's the code
body{
background: linear-gradient(0deg, rgba(2,0,36,1) 0%, rgba(37,37,82,1)
35%, rgba(38,54,82,1) 100%);
color: white;
font-family: Arial, Helvetica, sans-serif;
font-size: 1.2em;
padding:0;
margin:0;
}
#Title{
Font-size: 3em;
text-align: center;
}
/*Global*/
.container{
width: 80%;
margin: auto;
overflow: hidden;
}
header {
background: rgb(0, 0, 0, 0.5);
min-height: 50px;
border-bottom: #ef3331 3px solid;
}
#branding {
float: left;
display: inline;
}
#branding h1 {
margin: 0;
padding: 0px;
}
header nav {
float: right;
margin: 10px;
display: inline;
}
header li {
display: inline-block;
float: left;
background-color: transparent;
}
header a {
overflow: hidden;
border-width: thick;
box-sizing: border-box;
border-radius: 5px;
color: #fff;
text-decoration: none;
text-transform: uppercase;
font-size: 15px;
background-color: transparent;
transition: 0.3s;
padding: 16px 22px;
text-align: center;
}
header a:hover {
background-color: black;
}
ul {
margin: 0;
padding: 0;
}
<header>
<div class="container" style="padding: 20px 0px;">
<div id="branding">
<h1>Anđelo Motika Design</h1>
</div>
<nav>
<ul>
<li>
<span>HOME</span>
</li>
<li> ABOUT ME </li>
<li> GALLERY </li>
</ul>
</nav>
</div>
</header>
The links keep moving during the page's loading phase. It is not what I want. I just wanna change the background of the a tag, not their position too.
Here's some screencaps to demonstrate my problem.
Just remove the below line from header a decorator in css file.
transition: 0.3s;
Also if you want to add text color while hovering , you can add this on the header a : hover
header a:hover {
background-color: black;
color: yellow;
}

My dropdown content won't show but it did before I moved my header

I had a simple website and everything worked perfectly but I wanted to make it more modern but I don't know what I changed that made my dropdown menu stop working.
I am new to coding btw and I use Visual Studio Code.
I haven't tried anything because I don't want to screw up my website.
My HTML and CSS code (see also jsfiddle):
<div class="header" id="header">
<span id="header-title">Nellfin Solutions</span>
<div class="dropdown">
<span id="menu">&#9776 Menu</span>
<div class="dropdown-content">
Home
Services
Products
About Us
Contact Us
</div>
</div>
</div>
#import url(http://fonts.googleapis.com/css?family=Monstserrat:400,700);
body {
background-image: url("backround.jpg");
background-repeat:no-repeat;
background-size:cover;
color: #555;
margin: 0;
font-family: 'Montserrat', sans-serif;
background-color: rgba(255, 255, 255, 0.979);
}
.header {
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
#header {
background-color: white;
height: 50px;
line-height: 50px;
position: fixed;
margin-top: 20px;
width: 80%;
transform: translate(12%, 0%)
}
#header-title {
float: right;
margin-right: 50px;
font-size: 20px;
color: orange;
}
.dropdown {
position: relative;
display: inline-block;
background-color: white;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #555;
min-width: 100px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
text-align: left;
overflow: auto;
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown-content a {
color: white;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {
color: orange;
background-color: #6F6F6F;
}
#menu {
text-transform: uppercase;
letter-spacing: 0.1em;
margin: 10px;
margin-top: 0px;
color: orange;
font-weight: bold;
position: relative;
}
.body h1 {
position: relative;
padding-top: 100px;
padding-left: 200px;
text-transform: uppercase;
color: orange;
}
Because of the relative position in .body h1, it changes the z-index position. You can decrease the position of your .body h1 to below 0.
.body h1 {
z-index: -1;
}
Or you can remove the position for h1.
.body h1 {
position: relative(no need to use this css line)
}
Hover for dropdown doesn't work because you put body in front of it (you can use inspector to see that). so bring header to front by:
.header {
z-index: 1000;
}
Fiddle: fiddle

Hover link text and icon

I got some text after two contact icons. What I want is both the icon AND the text to be a link, so that when the icon OR the text is hovered they both light up.
At this point I am only able to achive this effect on the envelope example, but as you can tell the text conflicts with the icon itself.
.fa {
text-align: center;
vertical-align: middle;
text-decoration: none;
margin: 15px 3px;
border-radius: 50%;
width: 30px;
height: 30px;
font-size: 15px;
line-height: 30px !important;
}
.fa {
background: #F0F0F0;
color: #282828;
}
.fa:hover { color: #F0F0F0; }
.fa-envelope-o:hover,
.fa-phone:hover {
background: #282828;
color: white;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
example#gmail.com
<br>
1234567
To achieve expected result , use below changes in HTML with CSS hover effect for both span and anchor element
.fa {
text-align: center;
vertical-align: middle;
text-decoration: none;
margin: 15px 3px;
border-radius: 50%;
width: 30px;
height: 30px;
font-size: 15px;
line-height: 30px !important;
}
.fa {
background: #F0F0F0;
color: #282828;
}
.fa:hover { color: #F0F0F0; }
.fa-envelope-o:hover,
.fa-phone:hover {
background: #282828;
color: white;
}
span:hover a{
background: #282828;
color: white;
}
span:hover{
color: white;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<span>example#gmail.com</span>
<br>
<span>1234567</span>
I came up with something...
.fa {
text-align: center;
vertical-align: middle;
text-decoration: none;
margin: 15px 3px;
border-radius: 50%;
width: 30px;
height: 30px;
font-size: 15px;
line-height: 30px !important;
}
span {
margin-left:15px;
}
.fa {
background: #F0F0F0;
color: #282828;
}
.fa:hover { color: #F0F0F0; }
.fa-envelope-o:hover,
.fa-phone:hover {
background: #282828;
color: white;
}
.fa-envelope-o::before {
content: "\f003";
margin-left: 7px;
}
.fa-phone::before {
content: "\f095";
margin-left: 8px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<span>example#gmail.com</span>
<br>
<span>1234567</span>
You could try making both the icon and the link <spans>, and give the link <span> a class (I've given it the classlink for the example):
<span class="fa fa-envelope-o"></span>
<span class="link">example#gmail.com</span>
And wrap them both in an <a> tag, also with a class, (I've used outer):
<a href="mailto:example#gmail.com" class="outer">
<span class="fa fa-envelope-o"></span>
<span class="link">example#gmail.com</span>
</a>
And apply the hover styles from that.
.outer { text-decoration: none; font-size: 15px; color: #282828; }
.outer:hover .link { color: #F0F0F0; }
.outer:hover .fa { background: #282828; color: white; }
This allows the rest of your CSS to be simplified to the following:
.fa {
text-align: center;
vertical-align: middle;
margin: 15px 3px;
border-radius: 50%;
width: 30px;
height: 30px;
line-height: 30px !important;
background: #F0F0F0;
}
.outer {text-decoration: none; font-size: 15px; color: #282828;}
.outer:hover .link { color: #F0F0F0; }
.outer:hover .fa { background: #282828; color: white; }
.fa {
text-align: center;
vertical-align: middle;
margin: 15px 3px;
border-radius: 50%;
width: 30px;
height: 30px;
line-height: 30px !important;
background: #F0F0F0;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<a href="mailto:example#gmail.com" class="outer">
<span class="fa fa-envelope-o"></span>
<span class="link">example#gmail.com</span>
</a>
You could wrap them in 'span' tags. Also the 'fa fa-font' should start with 'i class'
<span class='mud'><i class="fa fa-phone"></i>1234567</span>
Then add to your CSS the following.
span.mud:hover {
background: #282828;
color: white;
}
Hope this helps you. Have a great day.
Try this
1234567
As seen above, you need to put the number within the 'a' tag.

<il> is pushed down when border appears

It is hard to learn "float" "overflow" "clear" and some other properties so please help me find good online websites to learn these properties ..
I opened some websites to make designs like them I found http://wix.com I admired its nav bar so i tried to make like it but i had a problem when mouse is over the il it is pushed down to show the top border how can I fix that
thanks and I am sorry for my weak English
body {
background-color: lightblue;
}
ul {
position: fixed;
list-style-type: none;
overflow: hidden;
top: 0px;
right: 0px;
width: 100%;
margin: 0px;
padding: 0px;
padding-top: 8px;
padding-bottom: 8px;
display: block;
background-color: #666666;
transition:background-color, 1s;
}
ul:hover {
background-color: #333;
}
il {
transition:border-top,1s;
float: left;
padding-right: 10px;
border-right: 1px solid white;
}
il:hover {
border-top:5px solid lightblue;
}
#navl {
font-family: Trebuchet MS’, Helvetica, sans-serif;
letter-spacing: 3px;
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
pre{
font-family: Courier New,Courier,Lucida Sans Typewriter,Lucida Typewriter,monospace;
letter-spacing: 2px;
font-size: 30px;
text-align: center;
color: white;
margin-top: 150px;
}
#plans:link, #plans:visited {
background-color: white;
color: black;
padding: 14px 25px;
text-align: center;
text-decoration: none;
display: block;
border: 1px solid white;
border-radius: 30px;
margin: auto;
width: 110px;
padding-top: 20px;
padding-bottom: 20px;
font-size:20px;
font-family: Courier New,Courier,Lucida Sans Typewriter,Lucida Typewriter,monospace;
}
<!DOCTYPE html>
<html>
<head>
<title>test</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<ul>
<il><a id="navl" href="index.html">Home</a></il>
<il><a id="navl" href="Plans.html">Plans</a></il>
<il><a id="navl" href="About.html">About</a></il>
<il><a id="navl" href="Contact.html">Contact Us</a></il>
</ul>
<pre>test</pre>
<a id="plans" href="plans.html">Plans</a>
</body>
</html>
The reason this happens is because the border adds height to the element. To correct it, you can either remove height from the main element or shift it up:
li:hover {
margin-top: -5px; //shifts the element up 5px
}
or you can have an invisible border as Teuta mentions that gets "covered up" by the new border.
At first, replace those il with li, and add this style to your li:
li {
border-top: 5px solid transparent;
}
And in ul, instead of padding-top:8px add padding-top:3px.
Here is the link with a little work around I did. I removed the padding top in ul. Changed the il to li. Because actually it is 'li' not 'il'. And I added a border top in li.
Here is the css code I changed.
ul:hover {
background-color: #666666;
}
li {
transition:border-top,1s;
float: left;
padding-right: 10px;
border-right: 1px solid white;
border-top:5px solid #666666;
}
li:hover {
border-top:5px solid lightblue;
}
https://jsfiddle.net/7x7dy3jt/

How can I get text within a button to change while the button is highlighted?

I want to be able to have the text within the button change when the button is hovered over. The text only changes color when it is hovered over instead of the whole button. The button background should be #FFFFFF and the text color should be #3A75B0
HTML:
<div class="getStartedButton">
<a href ="/signup">
<button class="getStarted">
Get Started
</button>
</a>
</div>
CSS:
.getStarted {
display: table;
margin: 0 auto !important;
height: 170px;
width: 300px;
background: transparent;
text-decoration: none;
border-style: solid;
border-color: #FFFFFF;
font-family: Helvetica;
text-align: center;
color: #FFFFFF;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
font-size: 60px;
padding: 20px 10px 50px 10px;
margin-bottom: 50px;
}
.getStarted a {
text-decoration: none;
font-family: Helvetica;
text-align: center;
color: #FFFFFF;
font-size: 60px;
margin-bottom: 50px;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
.getStartedButton:hover {
color: #3A75B0;
background-color: #FFFFFF;
}
.getStartedButton {
width: 300px;
margin-left: auto;
margin-right: auto;
border-radius: 10px;
}
.getStartedButton a:hover {
color: #3A75B0;
}
.getStarted:hover {
color: #3A75B0;
}
.getStartedButton.getStarted:hover {
color: #3A75B0;
}
This is not possible in pure CSS. Try this JS approach:
function changeText(button){
button.innerHTML = "Text Changed!";
}
<div class="getStartedButton">
<a href ="/signup">
<button onmouseover="changeText(this)" class="getStarted">
Get Started
</button>
</a>
</div>
Hope that works for you!