Remove weird white space between nested divs on Chrome - html

How can you remove the weird white space between two nested divs on Chrome.
<div class="bar">
<div class="progress">
</div>
</div>
.bar {
width: 200px;
height: 6px;
border: 1px solid black;
border-radius: 3px;
}
.progress {
height: 100%;
width: 50%;
background: black;
}
Here is the link to the fiddle: http://jsfiddle.net/hfob7yz4/1/.
On Chrome it looks like
this for me with the weird margin.
On Firefox it looks pretty normal like expected:
firefox-img
It also depends on the screen width. The problem only shows up on my laptop.
Thanks

The reason is that there is a border around the main div, and gets visible on some screens
to avoid this add
.bar {
box-sizing: border-box;
}
read more here

You are hitting a sort of edge effect when on different zoom levels - there are bits of pixel 'left behind' in the system's calculations as it tries to map part CSS pixels to the several screen pixels that might make up a CSS pixel on modern screens.
Instead of needing a second, inner div, you could paint the progress with a background image using a linear-gradient - this can be altered by JS dynamically as required.
.bar {
--progress: 50%;
width: 200px;
height: 6px;
border: 1px solid black;
border-radius: 3px;
background-image: linear-gradient(to right, black 0 var(--progress), transparent var(--progress) 100%);
}
}
<div class="bar">
</div>

Related

removing white space on a page between sections separated by a div

my html for spacer
<main>
<section>...
</section><div class="spacer layer1">
</div><section>...
</section>
</main>
my css for spacer
.spacer {
aspect-ratio: 1080/300;
width: 100%;
background-repeat: no-repeat;
background-size: cover;
background-position: center;
}
.layer1 {
background-image: url(waves/col1.svg);
border-top: 2px solid #d96459;
border-bottom: 2px solid #f2ae72;
}
the issue :
the white space as shown seems to appear and disappear based on width on a computer screen while it stays on the mobile screen as shown in the picture.
I can't seem to find a workaround. Any help is appreciated.
Assuming your SVG fills the entire viewbox, my guess is that the scaling sometimes results in the edges landing on fractional screen pixel boundaries.
Assuming you're seeing a transparent gap (as opposed to a white-ish rendering artifact) you might be able to use a negative vertical margins on the spacer to create a pixel or two of overlap.
section {
min-height: 50px;
background: tomato;
}
.spacer {
margin: -5px 0; /* exaggerated for visibility. probably don't need this much. */
background: bisque;
opacity: .5; /* so you can see the overlap */
min-height: 30px;
}
<section></section>
<div class="spacer"></div>
<section></section>

How to scale an html element to an absolute size, not via a factor

Let's say I have a dynamically created element and I don't know its size. I want to scale it to always fit certain other size as defined in pixels. Unfortunately scale only accepts a factor.
Is there a css way to achieve that?
transform: scale(0.1); // unfortunately 0.1 is factor
Without Javascript I believe that what you need is the CSS property display:contents. Keep in mind that not every browser accepts it. Here is an example on Codepen.
HTML:
<div class="content">
<div class="inner">
<p>This is the inner box. If display: contents works in your browser you will see a full width box with a red border.</p>
<p>If display: contents does not work or if you remove the display property from .content you will see a 400 pixel box with a grey border and background color, inside will be nested the box with the red border.</p>
</div>
</div>
CSS:
.content {
border: 2px solid #999;
background-color: #ccc;
border-radius: 5px;
padding: 10px;
width: 400px;
display: contents;
}
.inner {
border: 2px solid red;
border-radius: 5px;
padding: 10px;
}

Use CSS to give my web page a white foreground, gray background (mimic MS Word)

I'm rendering a large document (500 pgs) as a web page. My users are used to Word. Can I use CSS to mimic the look from the image below, a uniform 'page' with a white background with a fixed width, and the rest of their browser showing a gray background? Like the image below, except without the ribbon and all that:
The only think I can think of is to put the entire document inside a massive div tag, but is there a better way? Thanks.
This can be done fairly easily with 2 divs and a bit of css.
I also gave the white a border as per the image.
.container {
background: #9099ae;
width: 100vw;
height: 100vh;
padding: 40px 200px;
}
.content {
background: #fff;
width: 100vw;
height: 100vh;
margin: 0 auto;
border: 2px solid #000;
border-right: 4px solid #000;
}
<div class="container">
<div class="content">
</div>
</div>

Chrome renders element with border too large. Why?

I've got a webpage with a div fully filling up another div.
<div id="outer">
<div id="inner"/>
</div>
The style is as follows:
#outer {
background: blue;
border: 1px solid red;
height: 44px;
width: 44px;
}
#inner {
background: yellow;
border: 1px solid green;
height: 42px;
width: 42px;
}
Feel free to check out the corresponding codepen.
In Firefox this renders fine. In Chrome the background of the outer div shows because it renders as too large. In addition, the border is too far away. Here are the renderings.
See the extra blue rim on the bottom and right for Chrome (left) that's not present for Firefox (right). Why is this? And how can I prevent it? (I'm guessing it has something to do with Chrome rounding off pixels when scaling? Is Codepen scaling its output or something?)

border-image doesn't wrap around the entire border

How would I get the image that I'm using to wrap around the entire border? It only shows up on the top and bottom. I used border-image.com to scale it down, but I can only get the desired result on either top or bottom, or left and right borders. I basically want the image to wrap around repeatedly in a consistent manner as is (company's logo repeated throughout all the borders) without having to stretch, manipulate, or scale it in any way. I would really appreciate any help ? Here's what I have so far
HTML:
<div id="outer_container">
...
</div>
CSS:
#outer_container {
height: 1495px;
width: 925px;
margin-right: auto;
margin-left: auto;
background-repeat: repeat-x;
background-attachment: fixed;
background-color: #E7EAF5;
border-radius: 15px;
border-style: solid;
border-width: 38px 38px 38px 38px;
border-image: url(http://lorempixel.com/81/81/) 81 0 fill repeat stretch;
}
The problem is the 0 that you are adding after the 81. If you remove the number the border will apply to all the borders
border-image: url(http://lorempixel.com/81/81/) 40 fill repeat stretch;
http://jsfiddle.net/4rjw6/
You can use divs to accomplish this:
HTML:
<div id="div-top"></div>
<div id="div-left"></div>
<div id="container">
</div>
<div id="div-right"></div>
<div id="div-bottom"></div>
CSS:
#div-top,
#div-bottom {
width: 925px;
height: 81px;
background: url('http://lorempixel.com/81/81/') repeat-x;
clear: both;
}
#div-left,
#div-right {
width: 81px;
height: 1495px;
background: url('http://lorempixel.com/81/81/') repeat-y;
}
#div-left,
#div-right,
#container {
float: left;
}
#container {
height: 1495px;
width: 763px;
background-attachment: fixed;
background-color: #E7EAF5;
}
Fiddle: http://jsfiddle.net/6MghG/1/
(Note that you'd need to enlarge the fiddle preview box for it to show up correctly; it should work fine in a browser window.)
Another advantage of this is wider browser compatibility - for example, IE10 does not support border-image.
You might find it easier to specify the properties of your border one by one. I tried this in Chrome with your fiddle: http://jsfiddle.net/6MghG/2/
border-image-source:url(http://lorempixel.com/81/81/); /* where the image comes from */
border-image-slice: 33.3%; /* chop that image into 9 pieces each one-ninth the total area */
border-image-width: 50px; /* just how wide to draw the border. Overrides border-width. */
border-image-repeat: round; /* change the image size along the edges to make it fit neatly */
And that looked OK to me. You have to take the logo you want to use and put nine copies of it in a single image to use this technique.