Related
This has been eating away at my for the past day. What i want to achieve is when the users monitor is viewed at 1100px or less, it only shows a solid background color. When it exceeds that width, a left and right gradient aligned always at the left and right furthest appear, but are not ever shown if the screen size does not exceed 1100px.
Here is an example of what i am trying to do:
I tried setting up 3 divs, but that doesnt seem to work as show in the JSFiddle below. Any tips or suggestions?
JSFiddle
<div></div>
Try adding a gradient to the .left and .right divs and hide them when the screen width is below 1100px.
As an example:
Gradient from dark -> light
.left {
min-width: 300px;
height: 100%;
background: #000000;
float: left;
background: #000000;
/* Old browsers */
background: -moz-linear-gradient(left, #000000 0%, #ffffff 100%);
/* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%, #000000), color-stop(100%, #ffffff));
/* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, #000000 0%, #ffffff 100%);
/* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, #000000 0%, #ffffff 100%);
/* Opera 11.10+ */
background: -ms-linear-gradient(left, #000000 0%, #ffffff 100%);
/* IE10+ */
background: linear-gradient(to right, #000000 0%, #ffffff 100%);
/* W3C */
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#000000', endColorstr='#ffffff', GradientType=1);
/* IE6-9 */
}
Grandient from light -> dark
.right {
width: 300px;
height: 100%;
background: #ffffff;
/* Old browsers */
background: -moz-linear-gradient(left, #ffffff 0%, #000000 100%);
/* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%, #ffffff), color-stop(100%, #000000));
/* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, #ffffff 0%, #000000 100%);
/* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, #ffffff 0%, #000000 100%);
/* Opera 11.10+ */
background: -ms-linear-gradient(left, #ffffff 0%, #000000 100%);
/* IE10+ */
background: linear-gradient(to right, #ffffff 0%, #000000 100%);
/* W3C */
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#000000', GradientType=1);
/* IE6-9 */
background-color: #000;
float: right;
}
(The above gradients are generated from http://www.colorzilla.com/gradient-editor/)
Then an #media query to hide them below 1100px
#media (max-width: 1100px) {
.left, .right {
display: none;
}
}
DEMO
Hope this helps!
There are so many methods to achieve what you're trying to do. I'll post the most obvious and leave the intense answers for those who understand your question better.
Your first bet is it to center a div layer using:
.myDiv {
margin: 0 auto;
background-image: url(assets/mybg.jpg);
background-position: top center;
}
Basically, you'll take your background image (with that gradient) and center it, and then center your div layer.
Your background should be made in Photoshop/GIMP/Paint.net/Whateverprogram and the solid color should be 1100px wide. Then the gradient should span the remaining area outside the solid.
My next option for you is to actually do this in jquery. We'll design it so that the div has the gradient until the viewport 1100px or less and it'll transition that background image to a different background image:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script src="jquery-2.1.1.js"></script>
<script>
$(document).ready(function(){
function widthCalculator(wrapper, changeWidth){
var wrapperWidth = $(wrapper).width();
if (wrapperWidth <= changeWidth) {
$(wrapper).css("background-image", "url(Assets/mybackground2.jpg)");
} else {
$(wrapper).css("background-image", "url(Assets/mybackground1.jpg)");
}
}
widthCalculator('#wrapper', 1100);
$(window).resize(function(){ widthCalculator('#wrapper', 1100); });
});
</script>
<style>
body {
background-color:red;
margin: 0 auto;
width: 100%;
height: 5000px;
}
#wrapper {
background-color:white;
width: 100%;
height: 100vh;
margin: 0 auto;
}
</style>
</head>
<body>
<div id="wrapper">
</div>
</body>
</html>
The jquery method isn't the best solution, because upon resize, it loads a new background. If you're desperate, and looking for a quick fix, this will work for you.
Alright, so I have some issues with an HTML page that I'm coding. The page (so far) only has a table on it that's 700px wide and 50px tall. I want to use a gradient for the background that rises from the bottom of the page to the center of the page (50%).
On my stylesheet, I have the following set under the body tag:
body {
background-image: url('./bg.png');
background-position: bottom;
background-repeat: repeat-x;
background-color: white;
background-size: auto 50%;
}
Unfortunately, background-size counts for how much space is taken up by HTML elements, so the size would be 50% of the height from the top of the page to the bottom of my 50px tall table. So, the background ends up being about 30px tall.
Also, the background does not position itself at the bottom of window. Instead, it positions itself at the end of the page content (at the bottom of my table).
I've been rattling my brain around this for the past few hours. I'm redesigning a website I did a few years ago in hopes of bringing it back (the old design was decent, but the code was pretty messy).
All help would be appreciated. Thanks!
I'm using Chrome v31.0.1650.57 m.
Have you considered using a gradient generator as opposed to an image? It might make your life a little bit easier :) You wont have to worry about repeat/background size, etc
http://www.colorzilla.com/gradient-editor/
Your body inherits the size of its only parent element, html, so you have to set the size of both in order to get what you're looking for:
html {
width: 100%; # of the browser window
height: 100%; # of the browser window
}
body {
width: 100%; # of html
height: 100%; # of html
}
Then, as Digiguin said, just use a CSS3 gradient background to get what you want, perhaps like this:
body {
width: 100%;
height: 100%;
background: #ffffff; /* Old browsers */
background: -moz-linear-gradient(top, #ffffff 0%, #ffffff 50%, #2989d8 50%, #1e5799 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffffff), color-stop(50%,#ffffff), color-stop(50%,#2989d8), color-stop(100%,#1e5799)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #ffffff 0%,#ffffff 50%,#2989d8 50%,#1e5799 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #ffffff 0%,#ffffff 50%,#2989d8 50%,#1e5799 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #ffffff 0%,#ffffff 50%,#2989d8 50%,#1e5799 100%); /* IE10+ */
background: linear-gradient(to bottom, #ffffff 0%,#ffffff 50%,#2989d8 50%,#1e5799 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#1e5799',GradientType=0 ); /* IE6-9 */
}
Alternatively, you could set the above styles on html instead of body.
What it looks like:
Change it to the <html> background and add height: 100%:
html {
background-image: url('./bg.png');
background-position: bottom;
background-repeat: repeat-x;
background-color: blue;
background-size: auto 50%;
height: 100%;
}
So I'm in the process of making a drag and drop browser 'dress up' type game. However, for some reason, I can't seem to position my images - either the draggable image or the doll base. I am able to drag and drop the draggable image, but I can't change their initial positions.
I've changed their position types, tried using top/bottom/left/right, margin, and even padding to move the images to where I want them, but they absolutely will not move!
Here's the HTML/CSS I'm using:
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<style>
<!--Page Styling-->
html, body{
background-color:#5C5C5C;
height: 100%;
width: 100%;
overflow: hidden;
}
#banner{
background: rgb(143,250,138); /* Old browsers */
background: -moz-linear-gradient(top, rgba(143,250,138,1) 0%, rgba(127,239,127,1) 10%, rgba(109,223,115,1) 25%, rgba(107,229,115,1) 37%, rgba(106,236,114,1) 50%, rgba(74,226,82,1) 51%, rgba(136,242,122,1) 83%, rgba(175,252,142,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(143,250,138,1)), color-stop(10%,rgba(127,239,127,1)), color-stop(25%,rgba(109,223,115,1)), color-stop(37%,rgba(107,229,115,1)), color-stop(50%,rgba(106,236,114,1)), color-stop(51%,rgba(74,226,82,1)), color-stop(83%,rgba(136,242,122,1)), color-stop(100%,rgba(175,252,142,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(143,250,138,1) 0%,rgba(127,239,127,1) 10%,rgba(109,223,115,1) 25%,rgba(107,229,115,1) 37%,rgba(106,236,114,1) 50%,rgba(74,226,82,1) 51%,rgba(136,242,122,1) 83%,rgba(175,252,142,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(143,250,138,1) 0%,rgba(127,239,127,1) 10%,rgba(109,223,115,1) 25%,rgba(107,229,115,1) 37%,rgba(106,236,114,1) 50%,rgba(74,226,82,1) 51%,rgba(136,242,122,1) 83%,rgba(175,252,142,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(143,250,138,1) 0%,rgba(127,239,127,1) 10%,rgba(109,223,115,1) 25%,rgba(107,229,115,1) 37%,rgba(106,236,114,1) 50%,rgba(74,226,82,1) 51%,rgba(136,242,122,1) 83%,rgba(175,252,142,1) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(143,250,138,1) 0%,rgba(127,239,127,1) 10%,rgba(109,223,115,1) 25%,rgba(107,229,115,1) 37%,rgba(106,236,114,1) 50%,rgba(74,226,82,1) 51%,rgba(136,242,122,1) 83%,rgba(175,252,142,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#8ffa8a', endColorstr='#affc8e',GradientType=0 ); /* IE6-9 */
font-size: 20px;
font-family: 'Arial Black', sans-serif;
width: 100%;
margin-left: -10px;
text-align: center;
z-index: 99999;
position: fixed;
}
#holder{
position: absolute;
height: 800px;
width: 900px;
background-color: #838B8B;
margin-left: -10px;
margin-top: -300px;
z-index: -1;
}
<!--Bodies-->
#body1 {
position: absolute;
right: 0;
height: auto;
width: 200px;
z-index: 1;
}
<!--Parts-->
#breath{
position: relative;
left: 10px;
}
</style>
<!--Draggable Scripts-->
<script>
$(function() {
$( "#breath" ).draggable();
});
</script>
<!--End Draggable Scripts-->
</head>
<body>
<div id="banner">Homestuck Character Editor</div>
<div id="body1"><img src="http://i.imgur.com/aO3GWBO.png"draggable="false"/></div>
<div id="holder"></div>
<div id="breath">
<img src="http://i.imgur.com/iAmOFlH.png"/>
</div>
</body>
</html>
You positioned the div on the right, but the image is still on the left. Since div elements are blocks, they fill 100% of their parent. In this case, the parent is 100%. You can get the image on the right side of the screen by selecting it, and shifting the image itself. I used the following:
#body1 img {
position:absolute;
right:0;
}
The fiddle.
I have a background image for a hero element on a website that I'm working on. I want to make the background image in the .hero div be on a gradient from transparency to complete opacity on the edges so the backgrounds of both divs blend into each other.
To illustrate, here's the code that I'm using right now in the body of my index.html:
<div class="hero">
<div class="hero-inner">
<h1>My awesome hero element</h1>
</div>
</div>
... and this is what's in my style.css
.hero {
background-color: black;
width: 800px;
}
.hero-inner {
width: 700px;
height: 200px;
margin: auto;
background-image: url('http://i.imgur.com/PXzVXmR.png');
}
.hero-inner h1 {
position: absolute;
font-family: Arial, sans-serif;
color: white;
padding: 10px;
background-color: rgba(0, 0, 0, 0.7);
left: 50px;
top: 20px;
font-size: 48px;
}
Here's the jsFiddle. How would I make the background image in .hero-inner blend in with the background color of .hero on the edges? I've got a similar effect on Photoshop that does the job but I'd like to know if this could be done with CSS3 gradients
You can draw radial background gradient, but code is really ugly and looks heavy.
Here is a gradient editor that may be useful: http://www.colorzilla.com/gradient-editor/
background: -moz-radial-gradient(center, ellipse cover, rgba(255,48,48,1) 23%, rgba(205,57,71,1) 40%, rgba(80,79,130,0) 83%, rgba(30,87,153,0) 100%);
background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(23%,rgba(255,48,48,1)), color-stop(40%,rgba(205,57,71,1)), color-stop(83%,rgba(80,79,130,0)), color-stop(100%,rgba(30,87,153,0)));
background: -webkit-radial-gradient(center, ellipse cover, rgba(255,48,48,1) 23%,rgba(205,57,71,1) 40%,rgba(80,79,130,0) 83%,rgba(30,87,153,0) 100%);
background: -o-radial-gradient(center, ellipse cover, rgba(255,48,48,1) 23%,rgba(205,57,71,1) 40%,rgba(80,79,130,0) 83%,rgba(30,87,153,0) 100%);
background: -ms-radial-gradient(center, ellipse cover, rgba(255,48,48,1) 23%,rgba(205,57,71,1) 40%,rgba(80,79,130,0) 83%,rgba(30,87,153,0) 100%);
background: radial-gradient(ellipse at center, rgba(255,48,48,1) 23%,rgba(205,57,71,1) 40%,rgba(80,79,130,0) 83%,rgba(30,87,153,0) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ff3030', endColorstr='#001e5799',GradientType=1 );
For that matter, can I place any wide div in a narrower div? What I'm trying to do can be explained by looking at this page.
What I'm trying to do is have the div with the 1300px-wide SVG graphic – whose id is "wide2" – overlap over the div called "center." The problem is that, when I just put wide2 into center, it aligns left. Both the classes of div have margin-left: auto and margin-right: auto CSS properties, which work, assuming the div contained in "center" is narrower than "center."
My solution so far has been closing "center", then immediately opening "wide2", and then, immediately after closing that one, re-opening "center." It's not a great system, especially given the shape of the SVG in question.
Can anyone help me out?
(per request) The CSS of the classes in question.
div.center
{
display: block;
margin-left: auto;
margin-right: auto;
margin-top: 0;
margin-bottom: 0;
padding-bottom: 0;
padding-top: 0;
height: 100%;
width: 1000px;
background: #bebebe; /* Old browsers /
background: -moz-linear-gradient(left, #bebebe 0%, #ffffff 12%, #ffffff 88%, #bebebe 100%); / FF3.6+ /
background: -webkit-gradient(linear, left top, right top, color-stop(0%,#bebebe), color-stop(12%,#ffffff), color-stop(88%,#ffffff), color-stop(100%,#bebebe)); / Chrome,Safari4+ /
background: -webkit-linear-gradient(left, #bebebe 0%,#ffffff 12%,#ffffff 88%,#bebebe 100%); / Chrome10+,Safari5.1+ /
background: -o-linear-gradient(left, #bebebe 0%,#ffffff 12%,#ffffff 88%,#bebebe 100%); / Opera 11.10+ /
background: -ms-linear-gradient(left, #bebebe 0%,#ffffff 12%,#ffffff 88%,#bebebe 100%); / IE10+ /
background: linear-gradient(left, #bebebe 0%,#ffffff 12%,#ffffff 88%,#bebebe 100%); / W3C /
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#bebebe', endColorstr='#bebebe',GradientType=1 ); / IE6-9 */
border-bottom: 0;
border-top: 0;
margin-top: 0;
margin-bottom: 0;
padding-bottom: 0;
padding-top: 0;
}
div.wide2
{
display: block;
margin-left: auto;
margin-right: auto;
margin-top: 0;
margin-bottom: 0;
padding-bottom: 0;
padding-top: 0;
height: 180;
width: 1300px;
border-bottom: 0;
border-top: 0;
margin-top: 0;
margin-bottom: 0;
padding-bottom: 0;
padding-top: 0;
}
Here is a CSS solution.
Add the following lines into your .wide2 css class:
margin-left: 50%;
transform: translate(-50%);
What's happening is you first move the wider div to the center of the narrower div, then translate the inner div left.
You can see it in action here: https://jsfiddle.net/89f31era/
The question is very unclear. I presume you want to
a div which is narrow, lets call it div1, width - 500px
a div which is wider, lets call it div2, width - 1000px
place div2 inside div1
Scroll div1 horizontally so as to see center div2 on div1.
You may use the ScrollLeft DOM property to perform scrolling. Ex:
<div style="background-color:#093; width:200px; overflow:scroll" id="sc1">
<div style="background-color:#033; width:400px;">
</div>
</div>
<script type="text/javascript">
document.getElementById("sc1").scrollLeft="30";
</script>