Running HTML without CSS in Visual Studio Code - html

So I installed Visual Studio Code to build my website, I wrote my code using HTML and CSS and when I try to run it It gives me "localhost refused to connect." knowing that I downloaded Live Server.
* {
margin: 0;
padding: 0;
font-family: sans-serif;
}
.hero {
width: 100%;
height: 100%;
background-image: url(images/background.png);
background-size: cover;
background-position: center;
position: relative;
overflow: hidden;
}
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="base.css" type="text/css">
<title>Document</title>
</head>
<body>
<h1>hi</h1>
<div class="hero">
</div>
</body>
</html>

Related

How can I apply background on my web page using css?

I am facing problem in adding a background image using CSS. I am applying following codes for my web page design, but it's not adding image to the page and showing blank page. My html codes are running properly.
<link rel="stylesheet" href="css/style.css">
<style>
/* css reset */
body{
margin: 0px;
padding: 0px;
background: url('img\dark-1839088_1920.jpg');
}
</style>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<link rel="stylesheet" href="css/style.css">
<style>
/* css reset */
body{
margin: 0px;
padding: 0px;
background: url('img\dark-1839088_1920.jpg');
}
</style>
<body>
<h1>This is heading</h1>
</body>
</html>
try like this:
body{
min-width: 100vw;
min-height: 100vh;
margin: 0px;
padding: 0px;
background-image: url('./img\dark-1839088_1920.jpg');
}

Background Image doesnt show

I have a div with a class called "wrapper'. When i try to add a background image to it in css it does not show, but the image shows up when i add it to the body.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width-device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Login Page</title>
<link rel="stylesheet" href="Custom.css">
<style>
.wrapper{
width: 100%;
height: 100%;
background-image: url(login-register.jpg);
}
</style>
</head>
<body>
<div class="wrapper"></div>
</body>
</html>
In given example .wrapper after rendering has 0px height so background image is just not visible.
Height in percentage is relative to its parent - so if parent has 0 height child will have 0 height too (as long as there are no elements with height inside child).
You can add min-height: 100vh or min-height: 300px to make it work.
This worked for me :)
.wrapper{
width: 100%;
height: 100vh;
background-image: url(login-register.jpg);
}

responsive image not working on safari mac and safari iPhone

im making a website, but the responsive image for safari mac/iphone is not working
here is my code
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Language" content="es">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta property="og:locale" content="es">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
<title>Reparación iPhone – iPad, iPod | iFixed</title>
<link href="style.css" rel="stylesheet" type="text/css" media="all" />
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300' rel='stylesheet' type='text/css'>
</head>
<body>
<nav><img src="LayerMain.png" style="max-width: 100% height: auto" /></nav>
and this is the css
img {
max-width: 100% !important;
height: auto !important;
}
For most 'resposive' images in layout, here's how I'd recomend setting that up. The parent should define the constraints.
https://jsfiddle.net/sheriffderek/9dnjvnc4/
<figure class='logo'>
<img src='http://placehold.it/800x700' alt='example image'>
</figure>
...
figure {
margin: 0;
padding: 0; /* reset */
border: 1px solid blue;
}
figure img {
display: block;
width: 100%;
height: auto;
max-width: 100%; /* just in case? not nessesary */
}
.logo { /* specific figure size */
max-width: 400px;
}
It sounds like you are trying to get a full-screen image - in which case you should use background-image on a div setup to be full-screen or the body etc. https://jsfiddle.net/sheriffderek/v65saLmd/
body {
background-color: black;
background-image: url('http://placehold.it/2400x4000');
background-size: cover;
background-position: center center;
border: 2px solid blue;
}

CSS works in Internet Explorer but not Chrome or Firefox

Why does the code below work in IE, but not Firefox or Chrome? Is it the CSS or HTML?
CSS
body {
background-image:url("\images\body_bg.png");
background-repeat: repeat-x;
background-color:#e0dfe4;
background-attachment: scroll;
background-size: auto;
}
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta content="width=device-width, initial-scale=1.0"/>
<title>Program Letters</title>
<link rel="stylesheet" type="text/css" href="../general.css"/>
</head>
<body>...</body>
</html>
It was a location issue in the CSS. The modified code below fixed it.
body
{
background-position: inherit;
background-image: url("images/body_bg.jpg");
background-repeat: repeat-x;
background-color: #e0dfe4;
}

When I try to get a background on my website with css/html it wont show the background

I'm trying to get a background on my website BJBGaming1.com, and i have this
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>BJBGaming1</title>
<link href="css/main.css" rel="stylesheet" type="text/css">
<link rel="stylesheet"
href="http://dhbhdrzi4tiry.cloudfront.net/cdn/sites/foundation.min.css">
</head>
<body>
and if you look i have the css/main.css part which has this for code
html {
min-height:100%;
min-width:100%;
overflow-x: hidden;
overflow-y: scroll;
width: 100%;
}
body {
background-image:url('../img/background.png');
background-repeat:no-repeat;
background-size:cover;
}
and i have an image that matches the name background.png that is 1 folder back and into the img folder so i have the ../img/background.png but the background still wont show, somebody please help.
You can try to use !important to the background-image because foundation.css is already override your background image to #fefefe
html {
min-height:100%;
min-width:100%;
overflow-x: hidden;
overflow-y: scroll;
width: 100%;
}
body {
background-image:url('../img/background.png') !important;
background-repeat:no-repeat;
background-size:cover;
}
OR
You can also load your main.css file after foundation.css
<link rel="stylesheet" href="http://dhbhdrzi4tiry.cloudfront.net/cdn/sites/foundation.min.css">
<link href="css/main.css" rel="stylesheet" type="text/css">
Using Chrome developer tools, I can get your image to display using
body { background-image: url('../img/background.png') !important; }
and
body { background-size: 100% !important;} will work
or body { background-size: cover !important; } worked as well.