I am new to the world of webdesign and am not completely not entirely sure how to create a full background image.
I am playing around with the warship.ts example on typescriptlang.org, and I am trying to add in a background photo of a battleship. Below is the code of the CSS file:
html
{
width: 100%;
height: 100%;
-ms-content-zooming: none;
margin: 0px;
border: 0px;
padding: 0px;
background-image: url(pictures/cats.jpg); //My code
background-size: cover;
}
body {
font-family: Verdana;
width: 100%;
height: 100%;
/*background-color: #b5caae;*/
background: url('img/bg2.jpg');
margin: 0px;
border: 0px;
padding: 0px;
min-height: 480px;
min-width: 640px;
}
#header {
width: 100%;
height: 25%;
}
#boards {
width: 100%;
height: 75%;
}
.quadrant
{
display: inline-block;
box-sizing: border-box;
-moz-box-sizing: border-box;
width: 40%;
margin: 2%;
vertical-align: top;
}
#banner {
font-size: 40pt;
font-weight: 800;
font-style: italic;
color: white;
text-shadow: -1px 0 black, 0 2px black, 1px 0 black, 0 -1px black;
height: 100px;
}
#status
{
width: 80%;
border: 1px dotted gray;
padding: 1%;
background-color: #CCCCCC;
height: 80%;
}
.board {
background-color: #111111;
border: 2px groove black;
height: 80%;
padding: 0%;
position: relative;
}
.cell {
box-sizing: border-box;
-moz-box-sizing: border-box;
float: left;
height: 10%;
width: 10%;
border: 1px dotted #A0A0FF;
margin: 0px;
padding: 0px;
position: relative;
}
.notBombed {
opacity: 0.2;
background: url('img/bg.jpg') repeat;
/*background-color: black;*/
z-index: 0;
}
.cellHit {
opacity: 0.5;
background-color: #C00000;
z-index: 2;
}
.cellMiss{
opacity: 0.5;
background-color: #008000;
z-index: 2;
}
.ship {
position: absolute;
box-sizing: border-box;
-moz-box-sizing: border-box;
margin: 0%;
padding: 0%;
width: 10%;
height: 10%;
border-radius: 20%;
/*background-color: #FFFF80;*/
background: #666666;
border: 2px solid black;
z-index: 1;
-ms-touch-action: none;
}
.dropTarget {
background-color: white;
}
As an IDE, I am using Visual Studio 2015. From the examples I have seen online, I place the url image in the solution explorer, then I reference it in the html method, and then set the image as a color. However, whenever I try to run it, nothing changes. Is there something that I am missing from the code, or am I updating this in the wrong spot? Do I need to change the HTML/ts code?
If you are trying to html background image in every resolution, try with this code
background: url(pictures/cats.jpg) no-repeat fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
do this for only body{} sector. remove background images code from other sectors.
Related
I have created a div container and within the container, there is a div box. Inside the box, I have a button that is supposed to be centered at the bottom of the box.
I have searched around and before anyone does the "duplicate post" I have tried everything that they've said. Such as, adding a "display: block;" into my code etc and still it's not centering the button into the middle. I have been messing around with whatever I can think of to try and centering the button but nothing is working.
.container {
max-width: 80%;
margin: auto;
overflow: hidden;
background-color: #fff000;
}
.box-1 {
background-image: url();
background-position: center;
background-size: cover;
background-repeat: no-repeat;
border: solid #000 1px;
margin: 10px;
padding: 10px;
width: 30%;
height: 260px;
transition: transform .5s;
overflow: hidden;
position: relative;
}
#mainButton {
position: absolute;
bottom: 0;
padding: 7px 5px;
margin: 0 auto;
width: 40%;
margin-bottom: 15px !important;
display: block;
overflow: hidden;
color: #fff;
background-color: #000;
border: 2px solid #fff;
font-family: inherit;
opacity: 0;
transition: .5s;
}
.box-1:hover #mainButton {
opacity: 1;
color: #fff;
background-color: #000;
border: 2px solid #fff;
font-family: inherit;
cursor: pointer;
}
<div class="container">
<div class="box-1">
<button type="button" id="mainButton"> Go To Website </button>
</div>
</div>
These three values set properly on your mainButton CSS should solve your issue:
width: 40%;
left:50%;
margin-left:-20%;
Its key to note what the calculation is here. The left property is centering the item at 50% of the page, and the negative margin-left is offsetting the items position in accordance with its width. Since its width is 40% the negative margin has to be half of this, ie 20%. With this in mind you can adjust the width and the offset if your design changes, better yet using css variables and calc() mean that you could set the width only and the margin would calculate itself.
As an example:
left:50%;
--buttonWidth: 40%;
width: var(--buttonWidth);
margin-left:calc( var(--buttonWidth) / -2);
.container{
max-width: 80%;
margin: auto;
overflow: hidden;
background-color: #fff000;
}
.box-1{
background-image: url();
background-position: center;
background-size: cover;
background-repeat: no-repeat;
border: solid #000 1px;
margin: 10px;
padding: 10px;
width: 30%;
height: 260px;
transition: transform .5s;
overflow: hidden;
position: relative;
}
#mainButton{
position: absolute;
bottom: 0;
padding: 7px 5px;
width: 40%;
left:50%;
margin-left:-20%;
margin-bottom: 15px !important;
display: block;
overflow: hidden;
color: #fff;
background-color: #000;
border: 2px solid #fff;
font-family: inherit;
opacity: 0;
transition: .5s;
}
.box-1:hover #mainButton{
opacity: 1;
color: #fff;
background-color: #000;
border: 2px solid #fff;
font-family: inherit;
cursor: pointer;
}
<div class="container">
<div class="box-1">
<a href="http://www.google.co.uk">
<button type="button" id="mainButton"> Go To Website</button>
</a>
</div>
</div>
Try with this code, i think this will help u in fixing the issue.
.container {
max-width: 80%;
margin: auto;
overflow: hidden;
background-color: #fff000;
}
.box-1 {
background-image: url();
background-position: center;
background-size: cover;
background-repeat: no-repeat;
border: solid #000 1px;
margin: 10px;
padding: 10px;
width: 30%;
height: 260px;
transition: transform .5s;
overflow: hidden;
position: relative;
}
#mainButton {
position: absolute;
padding: 5px;
width: 60%;
margin-bottom: 15px !important;
display: block;
overflow: hidden;
color: #fff;
background-color: #000;
border: 2px solid #fff;
font-family: inherit;
opacity: 0;
transition: .5s;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
.box-1:hover #mainButton {
opacity: 1;
color: #fff;
background-color: #000;
border: 2px solid #fff;
font-family: inherit;
cursor: pointer;
}
Just add "left: 0; right: 0;" in #mainButton
.container {
max-width: 80%;
margin: auto;
overflow: hidden;
background-color: #fff000;
}
.box-1 {
background-image: url();
background-position: center;
background-size: cover;
background-repeat: no-repeat;
border: solid #000 1px;
margin: 10px;
padding: 10px;
width: 30%;
height: 260px;
transition: transform .5s;
overflow: hidden;
position: relative;
}
#mainButton {
position: absolute;
bottom: 0;
padding: 7px 5px;
margin: 0 auto;
width: 40%;
margin-bottom: 15px !important;
display: block;
overflow: hidden;
color: #fff;
background-color: #000;
border: 2px solid #fff;
font-family: inherit;
opacity: 0;
transition: .5s;
left:0px;
right:0px;
}
.box-1:hover #mainButton {
opacity: 1;
color: #fff;
background-color: #000;
border: 2px solid #fff;
font-family: inherit;
cursor: pointer;
}
<div class="container">
<div class="box-1">
<button type="button" id="mainButton"> Go To Website </button>
</div>
</div>
It's because your button's parent is a link tag. Your button is not a direct child of the flexbox
So I have a simple little project I'm making, which has a gradient background. However, upon loading up the website, it looks like this:
image
And, as you can see, it doesn't extend to the bottom of the screen. What is the cause of this? Here is my stylesheet:
* {
box-sizing: border-box;
}
.bg-image {
background-image: url('../bg/bg.png');
background-size: cover;
-webkit-background-size: cover;
display: block;
filter: blur(5px);
-webkit-filter: blur(5px);
height: 800px;
left: 0;
position: fixed;
right: 0;
z-index: -1;
}
.container p {
margin: 1%;
font-weight: bold;
color: #000000;
opacity: 1;
}
.container {
background: rgba(255, 255, 255, 0.35);
border-radius: 3px;
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.25);
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
top: 175px;
left: 0;
position: fixed;
margin-left: 200px;
margin-right: 200px;
right: 0;
padding: 0 10px;
text-align: center;
}
.container ul {
margin: 5%;
font-weight: bold;
color: #000000;
opacity: 1;
}
.container img {
max-width: 600x;
max-height: 400px;
}
.logo img {
margin: 0 auto;
display: block;
max-width: 500px;
max-height: 150px;
}
Thanks for any help.
This question already has answers here:
How wide is the default `<body>` margin?
(4 answers)
Closed 5 years ago.
I am making a common header and footer which will be used throughout in all the HTML pages. My page has a white header and white footer and the body is grey colored. Now, my work demands to achieve as below:
What I achieved so far is as below:
I don't know why I am getting these white strips in the sides of the body tag. Please suggest, my code is as below.
main {
background-color: lightgrey;
padding: 50px;
}
header {
background-color: white;
width: 100%;
height: 50px;
}
.content-section {
background-color: lightgrey;
width: 100%;
}
.logo {
height: 20px;
margin: 15px 5px;
width: 116px;
}
.open-card-BG {
font-weight: 300;
margin: 0 auto;
width: 65%;
padding: 20px 40px;
object-fit: contain;
max-width: 325px;
min-height: 200px;
border-radius: 5px;
display: table;
background-color: white;
position: relative;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.2);
}
.open-card-BG::after {
content: '';
position: absolute;
top: 30px;
left: 100%;
width: 30px;
height: 30px;
background: url(../secure.svg) center no-repeat;
background-size: contain;
}
<header>
<img class="logo" src="logo.gif" />
</header>
<main>
<div class="open-card-BG">main content</div>
</main>
<footer>
I am footer
</footer>
That is because of the default (user agent stylesheet) margin applied by the browser on the body tag - see how the white stripes vanish when I set margin: 0 for body.
Demo below:
body {
margin: 0;
}
main {
background-color: lightgrey;
padding: 50px;
}
header {
background-color: white;
width: 100%;
height: 50px;
}
.content-section {
background-color: lightgrey;
width: 100%;
}
.logo {
height: 20px;
margin: 15px 5px;
width: 116px;
}
.open-card-BG {
font-weight: 300;
margin: 0 auto;
width: 65%;
padding: 20px 40px;
object-fit: contain;
max-width: 325px;
min-height: 200px;
border-radius: 5px;
display: table;
background-color: white;
position: relative;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.2);
}
.open-card-BG::after {
content: '';
position: absolute;
top: 30px;
left: 100%;
width: 30px;
height: 30px;
background: url(../secure.svg) center no-repeat;
background-size: contain;
}
<header>
<img class="logo" src="logo.gif"/>
</header>
<main>
<div class="open-card-BG">main content</div>
</main>
<footer>
I am footer
</footer>
add body{margin:0} in your stylesheet.
By default body tag have margin of 8px in most major browsers.
body{
margin:0
}
main {
background-color: lightgrey;
padding: 50px;
}
header {
background-color: white;
width: 100%;
height: 50px;
}
.content-section {
background-color: lightgrey;
width: 100%;
}
.logo {
height: 20px;
margin: 15px 5px;
width: 116px;
}
.open-card-BG {
font-weight: 300;
margin: 0 auto;
width: 65%;
padding: 20px 40px;
object-fit: contain;
max-width: 325px;
min-height: 200px;
border-radius: 5px;
display: table;
background-color: white;
position: relative;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.2);
}
.open-card-BG::after {
content: '';
position: absolute;
top: 30px;
left: 100%;
width: 30px;
height: 30px;
background: url(../secure.svg) center no-repeat;
background-size: contain;
}
<header>
<img class="logo" src="logo.gif"/>
</header>
<main>
<div class="open-card-BG">main content</div>
</main>
<footer>
I am footer
</footer>
you can try giving the main tag a margin: 0 -10px, may solve your problem.
See the fiddle
you can add this code in your css:
body {
display: initial;
}
Try the following:
html, body {margin: 0;}
I'm trying to create a small Notepad application online using just CSS and HTML. For some reason, my application creates a weird glitch where you scroll down in the text area far enough and scroll back up to find the header is missing.
https://jsfiddle.net/2v7ptadh/
How can I fix this issue?
This is the CSS code that is creating the error. If you want to view the full code, click on the JS Fiddle link above.
html,
body {
display: block;
box-sizing: border-box;
padding: 0;
margin: 0;
background-color: #888;
height: 100%;
width: 100%;
overflow-y: hidden;
}
div#header {
display: block;
width: 100%;
height: 40px;
border-left: 2px solid rgb(100, 125, 130);
border-top: 2px solid rgb(150, 175, 140);
border-bottom: 2px solid rgb(60, 48, 75);
border-right: 2px solid rgb(80, 84, 90);
background: #bbb;
box-sizing: border-box;
line-height: 40px;
text-align: center;
margin: 0;
padding: 0;
font-family: 'Open Sans', sans-serif;
font-weight: 900;
z-index: 4
}
div#app {
z-index: 2;
display: block;
width: 100%;
height: 100%;
box-sizing: border-box;
padding: 0;
margin: 0;
}
textarea#app-input {
display: block;
box-sizing: border-box;
padding: 4px;
margin: 0;
border: none;
outline: none;
width: 100%;
height: 100%;
line-height: 23px;
font-size: 20px;
resize: none;
}
textarea::selection {
background: #000;
color: #fff;
}
Video of issue: http://recordit.co/2AxYmb9XxV
If you're going to set html/body to height: 100%; overflow-y: hidden; then #app shouldn't be height: 100% - change that to height: calc(100% - 40px) where 40px is the header height. That will keep everything in the viewport.
#import url('https://fonts.googleapis.com/css?family=Open+Sans');
html,
body {
display: block;
box-sizing: border-box;
padding: 0;
margin: 0;
background-color: #888;
height: 100%;
width: 100%;
overflow-y: hidden;
}
div#header {
display: block;
width: 100%;
height: 40px;
border-left: 2px solid rgb(100, 125, 130);
border-top: 2px solid rgb(150, 175, 140);
border-bottom: 2px solid rgb(60, 48, 75);
border-right: 2px solid rgb(80, 84, 90);
background: #bbb;
box-sizing: border-box;
line-height: 40px;
text-align: center;
margin: 0;
padding: 0;
font-family: 'Open Sans', sans-serif;
font-weight: 900;
z-index: 4
}
div#app {
z-index: 2;
display: block;
width: 100%;
height: calc(100% - 40px);
box-sizing: border-box;
padding: 0;
margin: 0;
}
textarea#app-input {
display: block;
box-sizing: border-box;
padding: 4px;
margin: 0;
border: none;
outline: none;
width: 100%;
height: 100%;
line-height: 23px;
font-size: 20px;
resize: none;
}
textarea::selection {
background: #000;
color: #fff;
}
<div id="header">ONLINE NOTEPAD</div>
<div id="app">
<textarea id="app-input"></textarea>
</div>
try removing overflow-y:hidden from html and body
html,
body {
display: block;
box-sizing: border-box;
padding: 0;
margin: 0;
background-color: #888;
height: 100%;
width: 100%;
}
The below code works as intended (full width background image, with horizontally and vertically aligned text overlapping it), but I want to make a couple of changes. Instead of having a background image for #banner, I want to switch it to a color, and add a div before .teaser that is width: 1366px, height: 100% of parent, and includes a background image set to cover. I still need .teaser vertically aligned though. I've been struggling with this for awhile, so any help would be very much appreciated. http://jsfiddle.net/exczzyje/
HTML
<div id="banner">
<div id="valign">
<div class="teaser">
<h1>Title</h1>
<p>Tagline</p>
</div>
</div>
</div>
CSS
html, body {
width: 100%;
height: 100%;
}
#banner {
width: 100%;
height: 67%;
height: calc(67% - 123px);
background: #000 url('images/banner.jpg') 50% 0 no-repeat;
background-size: cover;
margin: 0 auto;
overflow: hidden;
padding: 0;
position: relative;
}
#banner[id] {
display: table;
position: static;
}
#banner #valign {
width: 100%;
position: absolute;
text-align: center;
top: 50%;
}
#banner #valign[id] {
display: table-cell;
position: static;
vertical-align: middle;
}
#banner .teaser {
width: 960px;
margin: -12px auto 0 auto;
padding: 21px 0;
position: relative;
top: -50%;
}
#banner .teaser h1 {
color: #fff;
font-size: 45px;
}
#banner .teaser h1:after {
content: "";
display: block;
width: 42px;
margin: 18px auto;
border-bottom: 3px solid #bfbfbf;
}
#banner .teaser p {
color: #808080;
font-size: 24px;
margin: 0;
text-align: center;
}
Are you looking for something like this:
See JSFiddle
CSS:
* {
margin: 0; padding: 0;
}
html, body {
width: 100%;
height: 100%;
}
#banner {
width: 100%;
height: 100%;
background-color: black;
padding: 0;
}
#banner #valign {
width: 100%;
height: 100%;
}
#newDiv {
height: 100%;
width: 1366px;
display: table;
margin: 0 auto;
background: #000 url('http://www.psdgraphics.com/file/colorful-triangles-background.jpg') 50% 0 no-repeat;
background-size: cover;
}
#banner .teaser {
display: table-cell;
width: 960px;
margin: 0 auto;
padding: 21px 0;
text-align: center;
vertical-align: middle;
}
#banner .teaser h1 {
color: #fff;
font-size: 45px;
}
#banner .teaser h1:after {
content: "";
display: block;
width: 42px;
margin: 18px auto;
border-bottom: 3px solid #bfbfbf;
}
#banner .teaser p {
color: #808080;
font-size: 24px;
margin: 0;
}
Just add a container around the outside instead.
Updated HTML
<div id="container">
<div id="banner">
<div id="valign">
<div class="teaser">
<h1>Title</h1>
<p>Tagline</p>
</div>
</div>
</div>
</div>
Updated CSS
#container {
width: 100%;
height: 67%;
height: calc(67% - 123px);
background: #000;
margin: 0 auto;
}
#banner {
width: 1366px;
height: 100%;
background: #000 url('images/banner.jpg') 50% 0 no-repeat;
background-size: cover;
margin: 0 auto;
overflow: hidden;
padding: 0;
position: relative;
}