I need to remove a little space between my divided blocks - html

There is a little space between my two divided blocks.
https://i.imgur.com/l411V0t.png here you can see my problem. I've can’t figure out why the blocks act like this.
body, main {
width: 100%;
margin: 0;
background: black;
}
.container {
display: block;
height: 200px;
margin: auto;
}
.block {
width: 100%;
height: 100%;
background:
linear-gradient(-135deg, transparent 45px, wheat 0) top right,
linear-gradient(45deg, transparent 45px, wheat 0) bottom left;
background-size: 100% 50%;
background-repeat: no-repeat;
}
<main>
<div class="container">
<div class="block">
</div>
</div>
</main>

In Firefox there is no gap to be found, in Edge and IE it shows so it seems to be a sizing issue. Increasing the background size to 51% closes the gap also in Edge.
I'll try to find how the different browsers calculate background sizes.
body, main {
width: 100%;
margin: 0;
background: black;
}
.container {
display: block;
height: 200px;
margin: auto;
}
.block {
width: 100%;
height: 100%;
background:
linear-gradient(-135deg, transparent 45px, wheat 0) top right,
linear-gradient(45deg, transparent 45px, wheat 0) bottom left;
background-size: 100% 51%;
background-repeat: no-repeat;
}
<main>
<div class="container">
<div class="block">
</div>
</div>
</main>

Interesting question, while when the container height is set to even number pixel, the line will be removed. When the container height is odd pixel, the line will be displayed.
The key factor should be background-size: 100% 50%; , so you could use scss round function to skip the rounding problem here.

Related

Background for a page thats 90% white and 10% image that scales

I want to do the following and until now I neither got it to work on my own nor did I find something similar online. I am building a page that will not be scrollable and I want a white background but with a rainbow stripe at the bottom of the page.
I kinda got it to work like this with a div (I tried it as a background for the whole page, but it blurres because css doesn't crop the image, it compresses it):
.rainbow {
position: fixed;
height: 10%;
width: 100%;
bottom: 0px;
background: white url('../img/rainbow.jpg') no-repeat bottom fixed;
background-size: contain;
}
But the problem with this code is, that it does not scale properly: Passing a certain point the image isn't visible all the way, because it gets cut on both sides(left and right) the hight works.
I hope y'all know what I want to do.
Thanks in advance
Instead of using an image, you could achieve that with HTML and CSS.
.rainbow {
position: fixed;
height: 10%;
width: 100%;
bottom: 0px;
}
.color {
position: relative;
float: left;
height: 100%;
width: calc(100% / 6);
}
#blue {
background: blue;
}
#green {
background: green;
}
#yellow {
background: yellow;
}
#orange {
background: orange;
}
#red {
background: red;
}
#purple {
background: purple;
}
<div class="rainbow">
<div id="blue" class="color"></div>
<div id="green" class="color"></div>
<div id="yellow" class="color"></div>
<div id="orange" class="color"></div>
<div id="red" class="color"></div>
<div id="purple" class="color"></div>
</div>
Use gradient as background and no need image or a lot of code:
html {
min-height:100%;
background:
linear-gradient(to right,
blue calc(1*100%/6),
green calc(1*100%/6) calc(2*100%/6),
yellow calc(2*100%/6) calc(3*100%/6),
orange calc(3*100%/6) calc(4*100%/6),
red calc(4*100%/6) calc(5*100%/6),
purple 0)
bottom/100% 10% no-repeat;
}
Or if you want it inside a fixed element:
.box {
position:fixed;
bottom:0;
left:0;
right:0;
height:10%;
background:
linear-gradient(to right,
blue calc(1*100%/6),
green calc(1*100%/6) calc(2*100%/6),
yellow calc(2*100%/6) calc(3*100%/6),
orange calc(3*100%/6) calc(4*100%/6),
red calc(4*100%/6) calc(5*100%/6),
purple 0);
}
<div class="box"></div>
height: 10%; will scale the thickness. If you want the thickness consistent when you resize, just use px instead. I found 75px was about the same size as 10% when in full screen.
For the image, I just increased the width of your image to 2500x905 px This scaled nicely with no blur in both my monitors.
.rainbow {
position: fixed;
height: 10%;
width: 100%;
bottom: 0px;
left: 0px;
background: white url('http://foregotten.net/imgs/pen/rainbow1.jpg') no-repeat bottom fixed;
background-size: contain;
}
https://jsfiddle.net/Foregotten/5yLev3bf/6/

Making skewed elements on image transparent

I've tried following a guide on Youtube for help with this, and I can get it to work - sort of.
I'm trying to place two divs inside a section, where the top one is to house an image, and the bottom one be place for text etc.
The thing I'd like, is for the the top one to have a skewed razorblade dip in the middle, so the image sort of bleeds onto the bottom div.
I've managed to make the skew elements and place them where I'd like, but I when I turn them transparent, they seem to disappear.
Example: https://imgur.com/DsqNvZI
My CSS:
.section_1 {
height: 800px;
width: auto;
background: red;
}
.section_image {
height: 400px;
width: auto;
background: green;
position: relative;
background-image: url(lolsovs.jpg);
}
.section_image::after, .section_image::before {
position: absolute;
content: '';
width: 150px;
height: 150px;
background: green;
z-index: 100;
bottom: -1em;
}
.section_image::after {
left: 50%;
transform: skew(0, -20deg);
z-index: 100;
}
.section_image::before {
right: 50%;
transform: skew(0, 20deg);
}
.section_text {
background: purple;
height: 400px;
width: auto;
z-index: -100;
}
I'm still a novice when it comes to all of this stuff, so go gentle on me!
Thanks in advance!
but I when I turn them transparent, they seem to disappear.
Which is logical since you made them transparent. I advise you to consider another way to achieve this. You may simply consider some linear-gradient to color the bottom part to have this transparent part on the top:
.image {
height: 200px;
background:url(https://lorempixel.com/400/200/) center/cover no-repeat;
}
.bottom {
height:200px;
margin-top:-50px;
background:
linear-gradient(to bottom left,transparent 50%,purple 51%)calc(50% - 21px) 0/40px 50px no-repeat,
linear-gradient(to bottom right,transparent 50%,purple 51%)calc(50% + 20px) 0/40px 50px no-repeat,
linear-gradient(purple,purple)100% 0/calc(50% - 40px) 50px no-repeat,
linear-gradient(purple,purple)0 0/calc(50% - 40px) 50px no-repeat,
linear-gradient(purple,purple)0 50px/100% 100% no-repeat;
}
<div class="image">
</div>
<div class="bottom">
</div>
And for better handling you can use CSS variable to adjust dimension:
.image {
height: 200px;
background:url(https://lorempixel.com/400/200/) center/cover no-repeat;
}
.bottom {
height:200px;
margin-top:calc(-1 * var(--h,50px));
background:
linear-gradient(to bottom left,transparent 50%,purple 51%)calc(50% - (var(--w,50px) /2)) 0/var(--w,50px) var(--h,50px) no-repeat,
linear-gradient(to bottom right,transparent 50%,purple 51%)calc(50% + (var(--w,50px) /2)) 0/var(--w,50px) var(--h,50px) no-repeat,
linear-gradient(purple,purple)100% 0/calc(50% - var(--w,50px)) var(--h,50px) no-repeat,
linear-gradient(purple,purple)0 0/calc(50% - var(--w,50px)) var(--h,50px) no-repeat,
linear-gradient(purple,purple)0 var(--h,50px)/100% 100% no-repeat;
}
<div class="image">
</div>
<div class="bottom" style="--h:80px;--w:100px">
</div>

Diagonal shape 100% height CSS

Alright, here is the thing. This is what I'm trying to accomplish, which I did so far:
The problem is I use hardcoded pixels right now, but it really needs to be more responsive. So it needs a height of 100% (not 200px like now). And the total width of the diagonal and content containers needs to be 50%, like the image above (so not hardcoded 100px like now). The main problem seems to be the diagonal, cause it almost seems I can only use pixels and not percentages. So if the content block gets more content, it will expand, but the diagonal will not, which is a problem.
It looks like a position absolute could fix it, but then I can't really place the content and diagonal blocks next to each other anymore. Now I gave them two different colors to be clear, but in the live example they need to look like one shape with the same background color.
.shape {
width:400px;
margin:0 auto;
display: block;
height: 200px;
position: relative;
background-image: url('https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcSQdX7yx0pVXUlaNF7WkbSJpZp5r0TflV3WdsojKKK1Xon_1hh08l4OL1yd');
}
.diagonal {
height:0;
border-width: 0px 0 200px 100px;
border-style:solid;
border-color: transparent transparent transparent #d71f55 ;
float: left;
}
.content {
height: 100%;
width: 100px;
background-color: #888;
float: left;
color: #fff;
}
<div class="shape">
<div class="content">
Content goes here
Like this
</div>
<div class="diagonal"></div>
</div>
EDIT:
By the way, I already tried using two backgrounds as well, like:
background-color: #f87f73;
background-image: -webkit-linear-gradient( -28deg, #f87f73 0%, #f87f73 60%, #292423 60%, #292423 60%);
background-image: linear-gradient( -28deg, #f87f73 0%, #f87f73 60%, #292423 60%, #292423 60%);
But that really got ugly. Too pixelated.
Edit 2:
Browser which needs to be supported:
OS: windows 8/10 :
** browsers: Chrome 47/48
** Firefox 43/44
** Internet Explorer 11
OS: mac OSX 10.9/10.10
** Chrome 47/48
** Firefox 43/44
** Safari 8/9
OS: android 5/6
** Chrome latest version
OS: iOS 8/9
** Safari latest version
You can use viewport related units for the border as described in Shape with a slanted side (responsive). This will allow you to make the shape 50% width and 100% height of the viewport and responsive:
* {
margin: 0;
padding: 0;
}
.shape {
width: 100%;
margin: 0 auto;
display: block;
height: 100vh;
position: relative;
background-image: url('https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcSQdX7yx0pVXUlaNF7WkbSJpZp5r0TflV3WdsojKKK1Xon_1hh08l4OL1yd');
}
.diagonal {
height: 0;
border-width: 0 0 100vh 25vw;
border-style: solid;
border-color: transparent transparent transparent #d71f55;
float: left;
}
.content {
height: 100vh;
width: 25vw;
background-color: #888;
float: left;
color: #fff;
}
<div class="shape">
<div class="content">
Content goes here Like this
</div>
<div class="diagonal"></div>
</div>
Viewport related units (vh and vw) have good browser support. For more info, see canIuse
This is probably how I would approach it. Using a hard 50/50 gradient rather than a border makes it pretty trivial. It seems to render ok in chrome but I haven't checked other browsers. If you want this inside a container remember to set the container to position: relative
.shape {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: auto;
height: auto;
display: block;
background-image: url('https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcSQdX7yx0pVXUlaNF7WkbSJpZp5r0TflV3WdsojKKK1Xon_1hh08l4OL1yd');
}
.content {
height: 100%;
width: 25%;
background-color: #888;
color: #fff;
float: left;
}
.diagonal {
height: 100%;
width: 25%;
background: linear-gradient(to bottom right, #888 50%, transparent 50%);
float: left;
border: none;
}
<div class="shape">
<div class="content">
Content goes here Like this
</div>
<div class="diagonal"></div>
</div>

How to place background images on the top of each other?

I have three background images and I would like them to be on the top of each other. Besides that, I would like to place them manually and not just align.
How can I do this?
My codepen
<div class="first"></div>
<div class="second"></div>
<div class="third"></div>
-
.first {
background: url("http://www.quicksprout.com/images/foggygoldengatebridge.jpg") no-repeat;
background-size: 100% 100%;
height: 400px;
}
.second {
background: url("https://estherpgl.files.wordpress.com/2012/06/no-big-deal1.gif") no-repeat;
background-size: 300px;
height: 200px;
}
.third {
background: url("https://pbs.twimg.com/profile_images/604644048/sign051.gif") no-repeat;
background-size: 80px;
height: 100px;
}
With CSS3, you can apply multiple backgrounds to elements. You can also set custom background-position for each background.
The first value is the horizontal position and the second value is the vertical. The top left corner is 0% 0%. The right bottom corner is 100% 100%. If you only specify one value, the other value will be 50%. Default value is: 0% 0%
body, html {
margin: 0;
padding: 0;
}
div {
width: 100%;
height: 100vh;
background-image: url("https://pbs.twimg.com/profile_images/604644048/sign051.gif"),
url("https://estherpgl.files.wordpress.com/2012/06/no-big-deal1.gif"),
url("http://www.quicksprout.com/images/foggygoldengatebridge.jpg");
background-size: 80px, 300px, cover;
background-repeat: no-repeat;
background-position: 50% 90%, 50% bottom, center;
}
<div></div>
You can place the DIVs on top of each other, with position:absolute. Then your DIVs need a width in order to be visible. Each DIV now can have a z-index with which you can determine who goes on top.
See this fork of your pen.
You can use multiple backgrounds for just one div, using css3, like so:
background:
url(3.png) 600px 10px no-repeat, /* On top, like z-index: 3; */
url(2.png) 100px 100px no-repeat, /* like z-index: 2; */
url(1.png) 50px 50px no-repeat; /* On bottom, like z-index: 1; */
The example code above uses shorthand, but you can also write it like this:
background: url(3.png), url(2.png), url(1.png);/*left to right: top, middle, bottom*/
background-size: 600px 10px, 100px 100px, 50px 50px;
Learn more about multiple backgrounds.
Try out this one :
<div id="container">
<div id="main_image"></div>
<div id="overlay_image"></div>
</div>
#container{
position: relative;
width: 200px;
height: 200px;
}
#main_image{
width: 100%;
height: 100%;
background: blue;
}
#overlay_image{
position: absolute;
bottom: 10px;
right: 10px;
width: 30px;
height: 30px;
background: red;
}
in your case you might just need to change the
background : url("https://estherpgl.files.wordpress.com/2012/06/no-big-deal1.gif") no-repeat;
also you need to adjust the pixel of the images .
Hope this helps

Chrome zoom out breaks linear-gradient background

I am using a gradient background to display an alternating background for absolute positioned rows.
When zooming out in Chrome the layout gets messed up.
The calculation of the gradient background size seems to be different to the calculation of the top margins.
I have created a JSFiddle to illustrate the problem: http://jsfiddle.net/4y3k2/4/. When zooming out to e.g. 75% an offset appears between the foreground and background. The offset sums up more and more so that the layout looks completely broken for the last rows.
Here is my code:
#container {
position: absolute;
height: 2000px;
width: 100px;
background: linear-gradient(red 50%, green 50%, green);
background-size: 40px 40px;
}
.row {
position: absolute;
}
<div id="container">
<div class="row" style="top: 920px;"></div>
</div>
Everything works fine on IE and Firefox.
You can do this without calculating top every single time
for each row.
Instead set the parent div to be a block and use
predefined height and width for each row while floating them to the left:
#container {
position: absolute;
height: 2000px;
width: 100px;
background: linear-gradient(red 50%, green 50%, green);
background-size: 40px 40px;
display: block;
}
.row {
float: left;
width: 100px;
height: 20px;
}
http://jsfiddle.net/4y3k2/11/