I want to use multiple CSS files - html

I have 2 css files:
<link href="css/main.css" rel="stylesheet" type="text/css">
<link href="css/day/style.css" rel="stylesheet" type="text/css">
main.css
#MainHeader
{
position:absolute; top:0; left:0; right:0;
width:100%;
height:300px;
}
#ContentContainor
{
width: 80%;
position:absolute;
top: 350px;
left: 10%;
}
style.css
#MainHeader
{
background:green;
}
#ContentContainor
{
background: yellow;
}
I want one to position the site: main.css and the other is a user chosen style style.css.
The main.css works correctly but the style.css dosn't seem to be working.
I'll be honest I don't know if this is even possible; I'm experimenting.
If some one has a solution please comment.

What you're stating is absolutely possible.
Let's say you have two stylesheets, as you mentioned:
<link href="css/main.css" rel="stylesheet" type="text/css">
<link href="css/day/style.css" rel="stylesheet" type="text/css">
The main.css will hold your structural (position, dimensions, etc) CSS, and the day/style.css will hold your design (color, animations, etc) CSS.
If your css/main.css has the following CSS:
#main_header {
position:absolute;
top:0;
left:0;
right:0;
width:100%;
height:300px;
}
#content_container{
width: 80%;
position:absolute;
top: 350px;
left: 10%;
}
you can append styles (in css/day/style.css) as follows:
#main_header {
background-color: #00F;
}
#content_container{
color: #F00;
background-color: #0F0;
}
you can also override and 'lock' styles (in css/day/style.css) as follows:
#main_header {
height: 200px; /* override */
}
#content_container{
position: relative !important; /* override and 'lock' */
}
As a last note, you want to make sure your CSS files are being loaded and that your HTML is correctly formatted. Use your browsers Developer Tool / Firebug to make sure that the CSS is being loaded. For example, in Chrome, clicking on the Developer Tool (F12) tab called Network and reloading the page will tell you whether files are being loaded ok (200/304) or whether there are issues (ie, 404, 403, 500, etc)

Related

Why won't my image transfer from my files into my stylesheet for a DIV?

I'm trying to replicate a webpage template solely for the purpose of becoming more familiar with the works of HTML/CSS. I want to use an image in my documents as a background for a DIV, but for some odd reason, it will not import. Keep in mind, I'm still pretty new to coding.
I pulled a random stock photo address off of Google as a test, and that would work. So, I'm thinking either I have the photo located in the wrong folder (It's in the same exact folder as the document I'm calling it from), or there's something else in my code that is conflicting with the called image/file. I'm still not sure, though.
HTML file:
<html>
<head>
<title>conquer</title>
<link rel="stylesheet" type="text/css" href="conquer.css" />
</head>
<body>
<div class="navbar">
Homepage
About Us
Services
Contact
External
</div>
<div class="topbanner"></div>
</body>
</html>
CSS file:
body {
background-color: #fff;
margin: 0;
}
/** Navigation Bar **/
.navbar {
background-color: #383E4C;
height: 100px;
width: 100%;
position: fixed;
text-align: center;
margin-top: 0px;
}
.navbar a {
color: #F6F6F7;
text-decoration: none;
font-size: 22px;
font-family: "Helvetica", sans-serif;
border: 1px solid #646D7C;
padding: 15px;
margin-top: 20px;
margin-right: 20px;
display:inline-block;
}
.navbar a:hover {
background-color: #49505F;
}
/** Top Banner **/
.topbanner {
height: 500px;
width: 300px;
background-image: url('/city.jpg');
background-repeat: no-repeat;
}
I want the image to display in the DIV, but when I open the console elements, it's just a huge invisible block.
In paths, the leading slash /, tells the browser to goto the ROOT folder.
So you will want to change this:
background-image: url('/city.jpg');
to
background-image: url('city.jpg');

CSS div block makes text disappear

I've got the following css file :
.h_bg{
padding:22.4% 0;
background-size:100% auto;
background-position:center top;
background-repeat:no-repeat;
position:relative;
height: 2em;
}
.h_bg h1{
width: 100%;
position:absolute;
line-height:1;
top: 23%;
color:#fff;
font-size:500%;
text-align: center;
padding-bottom: 15%;
background-size:89px 183px;
}
#media screen and (min-width:1001px)
{
.h_bg{
background-image:url(/images/bg1-desktop.png);
}
}
#media screen and (min-width:1001px) and (max-width:1300px)
{
.h_bg h1{
background-size:7% auto;
padding-bottom: 16%;
}
}
And the following html page :
<!doctype html>
<html>
<head>
<title>Beauty app</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>
<div class="h_bg">
<h1>text</h1>
</div>
</body>
</html>
css link extactly to the place, where css file is. Unfortunately, text string is invisible and this code shows blank page. What can be a problem? Any help would be appreciated.
the problem is here:
color:#fff;
The #fff is forcing your H1 text in h_bg class to be white color, therefore it is invisible
Just incase you hit similar issues in future. This is how you can debug it.
Open your browser (i was using chrome) then right click on the element, for your instance its kind of difficult because you can't see it then click on inspect element.
On the bottom right corner you should see your CSS properties, try play around with it till you found your problem.

How to remove unnecessary margin on top?

I am making a website for some work and I have successfully made the background for the headers and all. But the problem is, I want to join it to the top of my webpage but it refuses to do that. How do I prevent it? (Not a duplicate of where the answer was adding !Important to the code)
Here is my code:
HTML:
<!DOCTYPE html>
<html class="html">
<head>
<link rel="stylesheet" type="text/css" href="css/index.css">
<title>LMUN - Home</title>
<div class="header"></div>
</head>
</html>
CSS:
.html
{
background-color: #FFFFFF;
}
.header
{
background-color: #70A5DA;
height: 4.5%;
width: 90%;
box-sizing: content-box;
position:absolute;
margin-left:5%;
margin-right:5%;
margin-top:0 !important;
padding:0 !important;
}
Note: I want to keep position absolute as it allows me to set everything in percentage values which is very essential for me.
Try this
HTML
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/index.css">
<title>LMUN - Home</title>
</head>
<body>
<div class="header"></div>
</body>
</html>
CSS
body {
margin:0;
}
.html
{
background-color: #FFFFFF;
}
.header
{
background-color: #70A5DA;
height: 4.5%;
width: 90%;
box-sizing: content-box;
position:absolute;
margin-left:5%;
margin-right:5%;
margin-top:0 !important;
padding:0 !important;
}
Yes for this you need to set the margin for body and also you can add same for html as 0.Then it will reduce unnecessary spaces. Like for example.
html{margin:0;}
body{margin:0}

Folder Path for url in css to access sprite img

So I have this image that 300px by 100px and its 3 icons in one I want to use it using html and css but I cannot access the folder the image is on my desktop and the path of my file html is C:\Users\User\Desktop\index1.html. Here is the html and css any help I am new to this so I am kinda lost.
HTML FILE
<!DOCTYPE html>
<html>
<head>
<head>
<link rel= "stylesheet" href="primary2.css">
</head>
<body>
<ul class="button">
<li class="yellow"></li>
<li class="purple"></li>
<li class= "red"></li>
</ul>
</body>
</html>
primary.css file
.button{
list-style: none;
margin:0;
padding:0;
}
.button li {
width:100px;
height:100px;
display:inline-block;
background-color: #000;
margin-right:10px;
}
.button li.info{
background : url(../sprite.JPEG) no repeat;
}
The relative path ../ refers to the parent folder, i.e. C:\Users\User\ when called from C:\Users\User\Desktop\
To refer to files in the same directory as your file, you can use the relative path ./, or in most cases, the preceding slash isn't necessary... just specifying the file name should suffice for files located within the same folder.
../sprite.JPEG from C:\Users\User\Desktop\ refers to C:\Users\User\sprite.JPEG whereas ./sprite.JPEG or sprite.JPEG would refer to C:\Users\User\Desktop\sprite.JPEG.
Notice also how you've specified the .css file in your html link tag...
My comment obfuscated the code a bit, so I'll put the revision to the CSS here:
.button{
list-style: none;
margin:0;
padding:0;
}
.button li {
width:100px;
height:100px;
display:inline-block;
background-color: #000;
margin-right:10px;
}
.button li.yellow {
background : url(sprite.JPEG) no-repeat;
}
the only changes were to the last style definition.

HTML/CSS banner not working

I am trying to place a solid color banner that stretches across the top of the screen like on this website, facebook, and others. For some reason I am encountering difficulties doing this
I created a div tag in my HTML file for the banner and tried to apply CSS to the div tag but nothing is working.
<!DOCTYPE html>
<html>
<head>
<style>
#banner {
background-color: #333FF;
font-family: Arial;
position: absolute;
left: 0;
right: 0;
padding:15px;
height:800px;
background-size:100%;
}
</style>
<title>Random Password Generator</title>
</head>
<body>
<div id="banner"><h1>fdsfdsfdsfds</h1></div>
</body>
</html>
I also tried linking to an external CSS file but that isn't working either.
How can I make a simple, solid color banner at the top of the page, on every page?
#333FF is an incorrect color. It should be like this: #333FFF. See the W3C Specification for more info on the length of hex codes (hint: they need to be six characters long).
Working example : http://jsfiddle.net/ntim/SKnxP/
position:absolute; also doesn't seem necessary in your case.
You don't actually need to use position absolute unless you want it to be over the top of anything. Instead, you can just use the following:
<style>
#banner {
background-color: #333FFF;
font-family: Arial;
padding:15px;
height:800px;
background-size:100% 100%;
}
</style>
here is something based on a template I use:
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<link rel="stylesheet" type="text/css" href="CSS-STYLE-SHEET.css">
<style type="text/css">
body
{
background-color: #E7E7E7;
text-align: center;
font-family: Arial, Helvetica;
font-size: 15px;
color: #000000;
border-spacing: 0;
border-collapse:collapse;
padding: 0;
margin: 0;
}
#Banner {
background-color: #333FFF;
top: 0; /* Probably not necessary... */
height: 40px;
width: 100%; /* Also probably not necessary */
}
#ContentMain
{
background-color: #FFFFFF;
height: 100%;
}
</style>
</head>
<body>
<div id="ContentMain">
<div id="Banner">Banner goes here</div>
Content goes here
</div>
</body>
</html>
should work.. the grey bit at the back is because the html and body tags dont fill the entire screen - something like this should fix it (I would use min-height), but I have not included it here as then if you want a page taller than the browser window and works in Internet Explorer things get annoying...
Jsfiddle here