Wierd white space between border and content - html

I see whitespace between the div's border and the nav in chrome only at a specific screen size. I also see it in the fiddle so I don't have any extra code.
Also same happens in the snippet, I see the white space only when I expand it to full page.
*{
padding: 0;
margin: 0;
font-size: 0;
line-height: 0;
}
div{
min-height: 100vh;
border: 0.5vw solid red;
width: 100%;
box-sizing: border-box;
}
nav{
background: black;
height: 11vh;
}
<div>
<nav>
</nav>
</div>

The problem is this:
border: 0.5vw solid red;
and that doesn't give you a whole number as such it anti-alias the border with the white DIV and what you are likely be seeing is more orange than white.
I've come up with a hack by having 2 separate divs one for the nav and that div background is black so your border is anti-alias to black rather than white.
Fiddle: http://jsfiddle.net/dg45wfc8/
*{
padding: 0;
margin: 0;
font-size: 0;
line-height: 0;
}
.content-div {
min-height: calc(((100vh - 11vh) - 0.5vw));
border: 0.5vw solid red;
width: 100%;
box-sizing: border-box;
border-width: 0 0.5vw 0.5vw 0.5vw;
border-style: solid;
border-color: red;
}
nav{
background: black;
height: 11vh;
}
.nav-div {
border-width: 0.5vw 0.5vw 0 0.5vw;
border-style: solid;
border-color: red;
background: black;
}
<div class="nav-div">
<nav>
</nav>
</div>
<div class="content-div">>
</div>

You can add margin-top:-1px to remove the white space coming under the div with border. I used this to fix my white space issue, it works!
<div> test </div>
div{
border: 3px solid #FB982E;
margin-top: -1px;
}

The problem is with the unit vw you are using in it. When I changed it to the px the white gap gets eliminated.
*{
padding: 0px;
margin: 0px;
font-size: 0px;
line-height: 0px;
}
.div{
border: 5px solid red;
width: 100%;
box-sizing: border-box;
}
nav{
background: black;
height: 11vh;
}
<div class="div">
<nav>
</nav>
</div>

Related

Setting an <hr>'s background-image, cross-browser issues? [duplicate]

Any idea why there's a thin grey line above my green and how to get rid of it?
Thanks
https://jsfiddle.net/Lc7gym88/
hr {
border-bottom: 4px solid #469551;
width: 30%;
margin-left: auto;
margin-right: auto;
margin-bottom: 0px !important;
height: 0;
}
It's because <hr/> has border (at least in FireFox since <hr/> has browser dependent style).
Remove border first.
hr {
border: none;
border-bottom: 4px solid #469551;
width: 30%;
margin-left: auto;
margin-right: auto;
margin-bottom: 0px !important;
height: 0;
}
body {
background-color: black;
}
<br/>
<hr/>
Replace this:
border-bottom: 4px solid #469551;
by this:
border: 4px solid #469551;
Here is the JSFiddle demo
Removed default <hr> border and uses height and background
hr {
background: #469551;
width: 30%;
margin-left: auto;
margin-right: auto;
margin-bottom: 0px !important;
height: 4px;
border:none;
}
Example : https://jsfiddle.net/Lc7gym88/1/
by default tag <hr> taking border so you need first border zero. then add height check my demo

How to move triangle over to the center right side of the screen in css?

This may be a silly question, but I have the following code in html:
<h1 class="page-title">
Paintings
</h1>
<hr>
</header>
<div class="arrow1">
<div class="triangle-right">
</div>
</div>
and this in css:
.page-title {
font-size: 75px;
text-align: center;
font-weight: 100;
font-family: 'Quicksand', sans-serif;
margin: 0 auto;
}
.triangle-right {
width: 0;
height: 0;
border-top: 30px solid transparent;
border-left: 40px solid red;
border-bottom: 30px solid transparent;
}
The triangle sits in the top corner of the screen, right below the header. I want to move it over to the right side of the screen and in the center. I also want to create another triangle on the left side and do the same.
My goal here is to create two triangle buttons. Can someone help me achieve this?
I'm not quite sure what you mean by having it center, like horizontally or vertically, but here is a solution that you might find helpful :)
.page-title {
font-size: 75px;
text-align: center;
font-weight: 100;
font-family: 'Quicksand', sans-serif;
margin: 0 auto;
}
.triangle-right {
width: 0;
height: 0;
border-top: 30px solid transparent;
border-left: 40px solid red;
border-bottom: 30px solid transparent;
float: right;
}
.triangle-left {
width: 0;
height: 0;
border-top: 30px solid transparent;
border-right: 40px solid red;
border-bottom: 30px solid transparent;
float: left;
}
.arrow1 {
margin-top: 100px;
}
<h1 class="page-title">Paintings</h1>
<hr>
<div class="arrow1">
<div class="triangle-left"></div>
<div class="triangle-right"></div>
</div>
At the moment i've just set the margin-top: 100px; you can just adjust it so it fits what you want :)
jsfiddle
Hope this one helps. M not sure what you want exactly.
display: inline-block;
use that display;

line break <hr> not rendering as expected

Any idea why there's a thin grey line above my green and how to get rid of it?
Thanks
https://jsfiddle.net/Lc7gym88/
hr {
border-bottom: 4px solid #469551;
width: 30%;
margin-left: auto;
margin-right: auto;
margin-bottom: 0px !important;
height: 0;
}
It's because <hr/> has border (at least in FireFox since <hr/> has browser dependent style).
Remove border first.
hr {
border: none;
border-bottom: 4px solid #469551;
width: 30%;
margin-left: auto;
margin-right: auto;
margin-bottom: 0px !important;
height: 0;
}
body {
background-color: black;
}
<br/>
<hr/>
Replace this:
border-bottom: 4px solid #469551;
by this:
border: 4px solid #469551;
Here is the JSFiddle demo
Removed default <hr> border and uses height and background
hr {
background: #469551;
width: 30%;
margin-left: auto;
margin-right: auto;
margin-bottom: 0px !important;
height: 4px;
border:none;
}
Example : https://jsfiddle.net/Lc7gym88/1/
by default tag <hr> taking border so you need first border zero. then add height check my demo

padding/margin bottom not working, i want to understand why

I have a header element in a header div but for some reason i can't seem to add any bottom margin or padding to it. Margin/padding top, left, and right work find however. is there a reason for this? here is my code.
html
<div id="Container">
<div id="Header">
<h1>My Webpage</h1>
</div>
</div>
css
#Container {
position: relative;
width: 96%;
height: 98%;
left:2%;
background-color: black;
border-radius: 10px;
box-shadow: 0px 0px 15px 5px;
}
/----------------------------------------/
#Header {
position: absolute;
height: 15%;
width: 100%;
/*background-color: red;*/
border-bottom: 2px solid #e8e2e2;
}
#Header h1 {
font-size: 2.5em;
text-align: center;
color:#e8e2e2;
/*background-color: red;*/
}
I would avoid using position styling like that; it tends to interfere with the way block elements interact with each other. Based on the styles and markup provided, I don't see a reason why padding/margin would not be working; however your example doesn't actually show any padding/margin applied, so it's hard to say what might be going wrong.
I would alter your styling thusly:
#Container {
width: 96%;
margin-left: auto;
margin-right: auto;
background-color: black;
border-radius: 10px;
box-shadow: 0px 0px 15px 5px;
}
#Header {
height: 15%; /* This should really be a static number, not a percentage*/
width: 100%;
border-bottom: 2px solid #e8e2e2;
margin-bottom: 20px; /* This will push elements below your header div down by 20 px*/
}
Try to add pading to header tag's self. Because it is relative to other containers.
#Container {
position:relative;
width: 96%;
height: 98%;
left:2%;
background-color: black;
border-radius: 10px;
box-shadow: 0px 0px 15px 5px;
}
#Header {
position:relative;
height: 15%;
width: 100%;
/*background-color: red;*/
border-bottom: 2px solid #e8e2e2;
}
#Header h1 {
position:relative;
padding-top:20px;
font-size: 2.5em;
text-align: center;
color:#e8e2e2;
/*background-color: red;*/
}
<div id="Container">
<div id="Header">
<h1>My Webpage</h1>
</div>
</div>
Firstly, please add #for Container as in #Container in css.
Below is the code where I have added margin bottom for h1. Please let me know if you still have any troubles.
<html>
<head>
<style type="text/css">
#Container {
position: relative;
width: 96%;
height: 98%;
left:2%;
background-color: black;
border-radius: 10px;
box-shadow: 0px 0px 15px 5px;
}
#Header {
position: absolute;
height: 15%;
width: 100%;
/*background-color: red;*/
border-bottom: 2px solid #e8e2e2;
}
#Header h1 {
font-size: 2.5em;
text-align: center;
color:#e8e2e2;
border:1px solid red;
margin-bottom:10px;
}
</style>
</head>
<body>
<div id="Container">
<div id="Header">
<h1>My Webpage</h1>
<p>some text here</p>
</div>
</div>
</body>
</html>
Hope this helps.
Thanks
Padding-bottom and margin-bottom does actually work, it's just that it's not visible because you're currently setting the height of #Header to 15% and then giving it that light grey bottom border. This is what gives the illusion that padding-bottom or margin-bottom doesn't work.
See working version here http://codepen.io/sajadtorkamani/pen/zxxzgo
HTML
<div id="Container">
<div id="Header">
<h1>My Webpage</h1>
</div>
</div>
CSS
Container {
position: relative;
width: 96%;
height: 98%;
left:2%;
background-color: black;
border-radius: 10px;
box-shadow: 0px 0px 15px 5px;
}
#Header {
position: absolute;
/* height: 15%; */
width: 100%;
/*background-color: red;*/
border-bottom: 2px solid #e8e2e2;
}
#Header h1 {
font-size: 2.5em;
text-align: center;
color:#e8e2e2;
padding-bottom: 20px;
/*background-color: red;*/
}
Just commenting out height: 15% for #Header solves the issue.

Make floating element "maximally wide"

I have some floating elements on a page.
What I want is the div that is floated left to be "maximally wide" so that it is as wide as it possibly can be without causing the red div ("I go at the right") to spill over onto the next line.
An example is here: The width:100%; doesn't produce the desired effect!
** I don't want the green element ("I want to be as wide as possible") to go "under" the red element. Its very important that they both stay separate i.e. .. I think they must both be floated!
<div class="container">
<div class="a1">i go at the right</div>
<div class="a2">i want to be as wide as possible,</div>
<div class="clear"></div>
</div>
<style>
div
{
border: solid 2px #000;
background-color: #eee;
margin: 8px;
padding: 8px;
}
div.a1
{
float:right;
background-color: #a00;
border: solid 2px #f00;
margin: 12px;
padding: 6px;
}
div.a2
{
float: left;
/*width: 100%;*/ /*this doens't produce desired effect!*/
background-color: #0b0;
border: solid 2px #0f0;
margin: 12px;
padding: 14px;
}
.clear
{
border: none;
padding: 0 ;
margin: 0;
clear:both;
}
</style>
Work with percentages:
div.a1
{
float:right;
background-color: #a00;
border: solid 2px #f00;
margin: 2%px;
padding: 6px;
width: 8%;
}
div.a2
{
float: left;
width: 84%;
background-color: #0b0;
border: solid 2px #0f0;
margin: 2%px;
padding: 14px;
}
Play with the widths, heights and margins % to get the desired look. Just remember that margin: sets right and left margins therefore margin: 2% uses 4% of the wrapper's width. Margins + widths should sum 100%, in this case (2%*2)*2 + 84% + 8% = 100%.