This is what i want to achieve ^ (this is the view on an iphone5 320x568)
But when i resize the window (to iphone 6 375x667 ) i get this
HTML:
<div id="container">
<div class="slicedimage">
<div class="textboxtransparant">
<h2>Since 1928</h2>
<div class="divider"></div>
<br/>
<p>Nullam id dolor id nibh ultricies vehicula ut id elit. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Maecenas sed diam eget risus varius blandit sit amet non magna.
</p>
<i class="fa fa-angle-down fa-3x" aria-hidden="true"></i>
</div>
<div class="transparantblack"></div>
</div>
<div class="slicedimage">
<div class="textboxblack">
<p>Nullam id dolor id nibh ultricies vehicula ut id elit. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Maecenas sed diam eget risus varius blandit sit amet non
</p>
</div>
<div class="blacktransparant"></div>
<div class ="line"></div>
</div>
CSS:
body {
margin: 0;
padding: 0;
font-size: 16px;
/*font-family: Georgia;*/
font-family: sans-serif;
max-width: 640px;
color: black;
}
#container {
display: block;
height:900px;
width: 100%;
position: relative;
top: 50px;
margin: 0;
color: white;
text-align: center;
}
.slicedimage {
background-image:url('http://i.stack.imgur.com/yEQ6k.jpg');
width:100%;
}
.textboxblack {
background-color:black;
}
.line {
position: absolute;
width:1px;
height: 50px;
bottom: 80px; /*half the height*/
left: 50%;
border-left: 1px solid white;
}
.transparantblack {
height: 100px;
width: 100%;
background: linear-gradient(to bottom right, rgba(255, 255, 255, 0) 49.9%, rgba(0, 0, 0, 1) 50.1%);
}
.blacktransparant {
height: 100px;
width: 100%;
background: linear-gradient(to top left, rgba(255, 255, 255, 0) 49.9%, rgba(0, 0, 0, 1) 50.1%);
}
.blackgray {
height:300px;
width:100%;
background:linear-gradient(341deg, #8a8a8a 0%, #8a8a8a 31.9%, #000 32.1%, #000 100%);
}
updated the post and since stack overflow is asking me to add more information since my post is mostly code. Yeah u get the point, lets see if this is enough. "information"
Your goal was to keep the white line under the text, in the middle of the blacktransparent element.
To achieve this you need to make from the line element, a child of the blacktransparant div:
<div class="blacktransparant">
<div class="line"></div>
</div>
and set the blacktransparant to be relative:
.blacktransparant {
height: 100px;
width: 100%;
background: linear-gradient(to top left, rgba(255, 255, 255, 0) 49.9%, rgba(0, 0, 0, 1) 50.1%);
/* Add this */
position: relative;
}
After this you only have to set the arrow in the right place relatively to the blacktransparant div:
.line {
position: absolute;
width: 1px;
height: 50px;
/* bottom: 80px; Change to 25px */
bottom: 25px;
left: 50%;
border-left: 1px solid white;
}
Related
I have the following issue where I don't really know on how to word-wrap the overlay text to my desires. I want the text to cut-off at the bottom of the overlay (or a few pixels above the bottom) and I want it to end it with a triple dot, so something like this: eu dolor sed, euismod ...
$('.container').mouseenter (function () {
//alert($(this).find('.soverlay').innerHeight()); //returns 56.8 px
var hgt = 'calc(100% - ' + parseInt($(this).find('.soverlay').innerHeight()+5) + 'px)';
$(this).find('.overlay').css({'height' : hgt});
});
$('.container').mouseleave (function () {
//alert($('.container .soverlay').innerHeight()); //returns 56.8 px
$(this).find('.overlay').css({'height' : '0px'});
});
.container {
position: relative;
width: 50%;
max-width: 250px;
}
.image {
border-radius: 10px;
display: inline-block;
width: 100%;
height: auto;
box-sizing: border-box;
}
.soverlay {
border-radius: 10px 10px 0px 0px;
box-sizing: border-box;
position: absolute;
top: 0;
background: rgb(0, 0, 0);
background: rgba(0, 0, 0, 0.5); /* Black see-through */
color: #f1f1f1;
width: 100%;
transition: .5s ease;
color: white;
font-size: 16px;
padding: 10px;
text-align: center;
overflow: hidden; /* remove on hover-in; add on hover-out*/
white-space: nowrap; /*remove on hover-in; add on hover-out */
text-overflow: ellipsis;
}
.overlay {
border-radius: 0px 0px 10px 10px;
position: absolute;
bottom: 4px;
left: 0;
right: 0;
background-color: #008CBA;
overflow: hidden;
width: 100%;
height: 0;
transition: .5s ease;
background: rgb(0, 0, 0);
background: rgba(0, 0, 0, 0.5); /* Black see-through */
font-size: 12px;
color: white;
}
.container:hover .overlay {
/* height: calc(100% - 57px); /* change height depending on 'soverlay' height */
border-top: 3px solid yellow;
}
.container:hover .soverlay{
overflow: unset;
white-space: unset;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<body>
<h2>Image Overlay Title</h2>
<p>Hover over the image to see the effect.</p>
<div class="container">
<img src="https://www.w3schools.com/howto/img_avatar.png" alt="Avatar" class="image">
<div class="soverlay">Some people just have very long names</div>
<div class="overlay">This is a very long job description which doesn't really fit in this div. Now the question is how do I cut of the text at the bottom of the overlay. </br></br>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce hendrerit convallis ligula, eget sollicitudin dolor lobortis ut. Duis venenatis, est vel volutpat dictum, magna mi pellentesque dolor, eu suscipit ligula augue eleifend justo. Nunc eleifend diam velit, id maximus eros tristique et. Donec sagittis mattis velit. Morbi gravida tincidunt metus in suscipit. Curabitur pharetra orci nec nunc sodales cursus. Morbi hendrerit id orci non vulputate. Duis nulla turpis, bibendum eu dolor sed, euismod mollis velit. Nullam tellus enim, condimentum porta rutrum ac, feugiat in ex. Sed tristique metus nunc, ut elementum elit hendrerit et. Quisque sed interdum ipsum. Etiam posuere.
</div>
</div>
</body>
</html>
I've managed to make a work-around using PHP by just cutting the length of each string at a certain length and appending the triple dots, but I actually want to try and do it with CSS only (to further improve my front-end skills).
You should add fix width to the .soverlay Div
.soverlay{width:250px;}
and then use the following CSS property
word-wrap: break-word;
I have to draw a squiggly line and that needs to be drawn using CSS3. The squiggly line should look like the image attached.
I tried to create using CSS ONLY, but not able to get it right. Any help is appreciated. Here is the fiddle I created https://jsfiddle.net/anirbankundu/myzmknLu/
.jagged-edge{
display: inline-block;
background-color: none;
border-left: none;
width: 1%;
height: 20px;
position: relative;
right: 1%;
}
.jagged-edge:after {
content: '';
position: absolute;
background: linear-gradient(-20deg,transparent 0,transparent
45%,#bcbcbc 45%,#bcbcbc 50%,#C4DCED 50%,#C4DCED 100%) 0 3px,linear-
gradient(-155deg,transparent 0,transparent 45%,#bcbcbc 45%,#bcbcbc
50%,#C4DCED 50%,#C4DCED 100%) 0 3px;
background-size: 100% 6px;
width: 100%;
height: 100%;
left: 45%;
z-index: 0;
}
<div class="jagged-edge">
</div>
I believe this is what you are looking for. I'm sure there could be a more semantic approach but this gets it done. Play with the settings to achieve precise visual. Cheers
$color: #336699;
.wrapper {
padding: 50px;
}
.top-line {
background-color: $color;
display: block;
height: 50px;
position: relative;
width: 3px;
&:after {
background-color: $color;
bottom: -6px;
content: '';
display: block;
height: 3px;
position: absolute;
transform: rotate(25deg);
width: 30px;
}
}
.middle-line {
background-color: $color;
bottom: -10px;
display: block;
height: 3px;
left: -20px;
position: relative;
width: 50px;
}
.bottom-line {
background-color: $color;
display: block;
height: 50px;
margin-top: 20px;
position: relative;
width: 3px;
&:before {
background-color: $color;
content: '';
display: block;
height: 3px;
left: -21px;
position: absolute;
top: -7px;
transform: rotate(25deg);
width: 25px;
}
}
https://codepen.io/garynorris88/pen/yXGYMM
For what it's worth, here's an SVG that you could use as a background on an element to the right or left side of the div.
<svg viewbox="0 0, 20, 70" height="70">
<path d="M 10 0 L 10 30 L 16 35 L 4 35 L 10 40 L 10 70" stroke="#555" stroke-width="2" stroke-linejoin="round" fill="none"/>
</svg>
So the line looks like it has a sideways 'z' in it to me. So I used css to add a one (rotated) via :before pseudo class.
If you like it I can try to tweak as I see a 1 pixel gap and your squiggly is a bit more 'smushed'
Markup:
.squiggly-line {
height: 100px;
border-left: 2px solid #4c6675;
position: relative;
}
.squiggly-line:before {
content: 'z';
font-size: 22px;
position: absolute;
top: 40%;
left:-6px;
background: white;
line-height: 9px;
vertical-align: -2px;
display: inline-block;
transform: rotate(49deg) scaleY(0.7);
color: #4c6675;
font-weight: 600;
font-family: 'Arial';
}
<div class="squiggly-line"></div>
<div class="squiggly-line"></div>
CSS:
.squiggly-line {
height: 100px;
border-left: 2px solid #888;
position: relative;
}
.squiggly-line:before {
content: 'z';
font-size: 22px;
position: absolute;
top: 40%;
left:-6px;
background: white;
line-height: 9px;
vertical-align: -2px;
display: inline-block;
transform: rotate(40deg);
color: #888;
font-weight: 600;
font-family: 'Arial';
}
Use a .svg file for this task and let other browser use a straight line, is what I would do today, because I find that cleaner.
Gimp is a nice program for creating vector graphics, be sure to use crop document to content feature and I'd set the dimensions correctly in the svg as well, save a few lines of css (instead of using other width property).
But you can have older browsers use a png as well (if you care about ~5% of users not seeing that line using this technique):
background: url(../old-browsers.png);
background: linear-gradient(transparent, transparent), url(../path/to/svg);
/*width: something */
Advantage: more freedom and ease
Con: less visually attractive for a small group of users
You may also give a look at background-image and background-size using gradients to draw each bits through a single class and no extra markup:
.jagged {
background:
linear-gradient(0deg, turquoise, turquoise) no-repeat 1em top,
linear-gradient(0deg, turquoise, turquoise) no-repeat 1em bottom ,
linear-gradient(-45deg, transparent 48%, turquoise 48%,turquoise 53%, transparent 53%) no-repeat -0.15em calc(50% + 0.25em),
linear-gradient(-45deg, transparent 48%, turquoise 48%,turquoise 53%, transparent 53%) no-repeat -0.65em calc(50% - 0.25em),
linear-gradient(90deg, turquoise ,turquoise ) no-repeat 0.5em 50%
gold /* you can add here a bg-color or add another background-image */;
background-size:
2px calc(50% - 0.5em),
2px calc(50% - 0.5em) ,
3em 0.5em,
3em 0.5em,
1em 1px ;
padding:2em;
}
/* example bis */
.jagged + .jagged {
background:
linear-gradient(0deg, turquoise, turquoise) no-repeat 1em top,
linear-gradient(0deg, turquoise, turquoise) no-repeat 1em bottom ,
linear-gradient(-45deg, transparent 48%, turquoise 48%,turquoise 53%, transparent 53%) no-repeat -0.15em calc(50% + 0.25em),
linear-gradient(-45deg, transparent 48%, turquoise 48%,turquoise 53%, transparent 53%) no-repeat -0.65em calc(50% - 0.25em),
linear-gradient(90deg, turquoise ,turquoise ) no-repeat 0.5em 50%,
url(http://lorempixel.com/600/800/nature/6) ;
background-size:
3px calc(50% - 0.5em),
3px calc(50% - 0.5em) ,
3em 0.5em,
3em 0.5em,
1em 2px,
cover;
color:turquoise;
text-shadow: 0 0 1px black;
font-size:1.5em;
<p class='jagged'>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p><p class='jagged'>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>
https://codepen.io/gc-nomade/pen/weRMBJ
I'm trying to replicate this mock up design.
Design:
Current:
Is there a way to make sure the "Shop All" ignores the overflow:hidden, but the before and after obey the overflow:hidden?
Or is there another method I can try to implement this?
Html
<div id="outer">
<div id="opaq">
<div id="inner">
<h1>Performance Parts</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi efficitur in arcu at placerat. Aenean sed lorem tincidunt, maximus purus eget, ornare metus. Nam interdum lobortis imperdiet. Nunc gravida urna urna. Vestibulum vitae lectus leo. Etiam fermentum nunc vel nulla tincidunt, sit amet molestie lectus pulvinar.</p>
<div id="shop">Shop all</div>
</div>
</div>
</div>
Css
#outer{
max-width:500px;
text-align:center;
background-image: url("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRNyPOuKMHtvXNa5dnlc8xGXvW-nVfguLdlj9sj4-K6cTA0Zbf7");
}
#opaq{
background-color: rgba(48, 44, 44, 0.7);
padding:5px;
}
#inner{
border:1px solid red;
margin:10px;
color:white;
border-bottom:none;
overflow:hidden;
}
#shop{
position:relative;
top:8px;
display: inline-block;
}
#shop:after{
content: "";
position: absolute;
border-bottom: 1px solid white;
top: 9px;
width: 600px;
left: 100%;
margin-left: 15px;
}
#shop:before{
content: "";
position: absolute;
border-bottom: 1px solid white;
top: 9px;
width: 600px;
right: 100%;
margin-right: 15px;
}
* {
margin: 0;
padding: 0;
font-family: sans-serif;
}
.wrapper {
background-image: linear-gradient(rgba(0, 0, 0, .3), rgba(0, 0, 0, .3)), url(http://beerhold.it/400/300);
background-repeat: no-repeat;
background-size: cover;
width: 400px;
height: 200px;
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
}
fieldset {
width: 90%;
height: 90%;
margin-top: .7em;
transform: rotate3d(0, 0, 1, 180deg);
border: 3px solid rgba(255, 255, 255, .4);
}
legend {
font-size: 1.4em;
font-weight: 700;
}
legend span,
fieldset .text {
display: block;
transform: rotate3d(0, 0, 1, 180deg);
color: white;
text-shadow: 0 0 4px black;
padding: 0 1em;
}
legend span {
color: yellow;
}
fieldset .text {
height: 100%;
}
fieldset .text h1 {
padding: .3em 0;
text-align: center;
}
fieldset .text p {
line-height: 1;
}
<div class="wrapper">
<fieldset>
<legend align="center"><span>SHOP ALL</span>
</legend>
<div class="text">
<h1>Lorem ipsum</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut a justo nisl. Phasellus consequat tincidunt elit, sed interdum nibh blandit ut. Nunc augue erat, rutrum ac vehicula nec, pulvinar in eros.
</p>
</div>
</fieldset>
</div>
Use this css; notice i have added comments to the code i change or added
#outer{
max-width:500px;
text-align:center;
background-image: url("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRNyPOuKMHtvXNa5dnlc8xGXvW-nVfguLdlj9sj4-K6cTA0Zbf7");
}
#opaq{
background-color: rgba(48, 44, 44, 0.7);
padding:5px;
}
#inner{
border:1px solid red;
margin:10px;
color:white;
border-bottom:none;
}
#shop{
position:relative;
top:8px;
display: inline-block;
z-index:200; /*added*/
}
#shop:after{
content: "";
position: absolute;
border-bottom: 1px solid white;
top: 9px;
width: 364%; /* changed */
left: 100%;
margin-left: 15px;
}
#shop:before{
content: "";
position: absolute;
border-bottom: 1px solid white;
top: 9px;
width: 364%; /* changed */
right: 100%;
margin-right: 15px;
}
border split into table cells:
body
{
font-family:arial;
background-image:url("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRNyPOuKMHtvXNa5dnlc8xGXvW-nVfguLdlj9sj4-K6cTA0Zbf7");
background-size:cover;
margin:0px;
}
.box div
{
border:0px solid RGBa(255,255,255,0.5);
}
.shade
{
background-color:RGBa(50,50,50,0.7);
padding:20px;
position:fixed;
top:0px;
right:0px;
bottom:0px;
left:0px;
}
h1
{
text-align:center;
text-transform:uppercase;
}
.bottomborder
{
display:table;
table-layout:fixed;
}
.box .left
{
width:50%;
border-width:0px 0px 2px 2px;
}
.box .right
{
width:50%;
border-width:0px 2px 2px 0px;
}
.box .col
{
display:table-cell;
}
.shopall
{
padding: 0px 15px;
white-space: nowrap;
position: relative;
top: 10px;
color:RGB(200,150,0);
font-weight:bold;
font-size:20px;
text-transform:uppercase;
}
.box
{
margin-left:auto;
margin-right:auto;
width:1100px;
margin-top:15px;
max-width: 100%;
}
.box .content
{
padding:5px 55px 10px 55px;
border-width:2px 2px 0px 2px;
border-top-left-radius:0px;
border-top-right-radius:0px;
color:white;
}
<body>
<div class="shade">
<div class="box">
<div class="content">
<h1>Performance & Parts </h1>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi efficitur in arcu at placerat. Aenean sed lorem tincidunt, maximus purus eget, ornare metus. Nam interdum lobortis imperdiet.
</div>
<div class="bottomborder">
<div class="left col">
</div>
<div class="col">
<div class="shopall">
shop all
</div>
</div>
<div class="right col">
</div>
</div>
</div>
</div>
</body>
You may try a negative margin and some flex to draw side borders, and it will keep a coherent HTML with title coming first in the code :
div {
margin:2em;
display:flex;
flex-flow:column;
text-align:center;
border:solid;
border-bottom-color:transparent;
background:rgba(0,0,0,0.2);
box-shadow: 0 0 0 2em rgba(0,0,0,0.2);
}
div h2 {
order:1;
display:flex;
margin:0 0 -0.6em 0;
font-variant:small-caps;
}
h2:before,
h2:after {
content:'';
flex:1;
border-bottom:solid;
margin:auto 1em auto -3px ;
}
h2:after {
margin: auto -3px auto 1em;
}
p {padding:0.25em 0.5em;}
html {background:url(http://lorempixel.com/800/600/city/6);
background-size:cover;
color:white;
text-shadow:0 0 1px black;
}
<div>
<h1>HTML Ipsum Presents</h1>
<h2>shop all</h2>
<p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris
placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis
tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis.</p>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
Mauris placerat eleifend leo.</p>
</div>
This question already has answers here:
How can I show only corner borders?
(20 answers)
Closed 6 years ago.
I would like to create an specific outline for a box using css.
Something like this image:
Please, any help? :(
You can look at gradients, background-clip and background-size:
example possible http://codepen.io/gc-nomade/pen/aZbrEQ
div {
margin: 1em auto;
width: 600px;
max-width: 70%;
padding: 40px;
/* set offset here for border corners */
background: linear-gradient(white, white) top left no-repeat, linear-gradient(white, white) top left no-repeat, linear-gradient(white, white) top right no-repeat, linear-gradient(white, white) top right no-repeat, linear-gradient(white, white) bottom left no-repeat, linear-gradient(white, white) bottom left no-repeat, linear-gradient(white, white) bottom right no-repeat, linear-gradient(white, white) bottom right no-repeat, rgba(255, 255, 255, 0.15);
/* color receive
background-clip:content-box;
so it is not drawn on padding areas */
background-clip: border-box, border-box, border-box, border-box, border-box, border-box, border-box, border-box, content-box;
background-size: 2px 60px, 80px 2px;
/* here give length and thickness of border corners */
color: white;
}
p,
h2 {
padding: 1em;
margin:0;
}
html {
height: 100%;
background: url(http://lorempixel.com/640/480/nature/6);
background-size: cover
}
body {
min-height: 100%;
background: rgba(0, 0, 0, 0.5);
margin: 0;
padding: 4em;
}
<div>
<h2>title</h2>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus
lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor,
facilisis luctus, metus</p>
</div>
Just to prove how simple your question is.
::before and ::after hides parts of the border.
z-index for overlay.
.dirt {
position: relative;
width: 200px;
height: 100px;
line-height: 100px;
text-align: center;
background-color: rgba(251, 145, 156, 1);
border: 2px solid rgba(231, 0, 0, 1);
box-sizing: border-box;
}
.dirt > span {
position: relative;
z-index: 15;
background-color: rgba(255,255,255,0.5);
padding: 25px;
}
.dirt::after,
.dirt::before {
content: '';
position: absolute;
background-color: rgba(251, 145, 156, 1);
/*same color*/
}
.dirt::before {
top: 20%;
bottom: 20%;
left: -2px;
/*border-width*/
right: -2px;
/*border-width*/
}
.dirt::after {
top: -2px;
/*border-width*/
bottom: -2px;
/*border-width*/
left: 20%;
right: 20%;
}
<p>An example: (do not use)</p>
<div class="dirt">
<span>My little dirt text</span>
</div>
I am seeing something strange in both firefox and chrome when I increase
the zoom level inside these browsers, although I see nothing wrong with
my CSS.
Here is the whole story:
I have a right-floated top-level div containing three right-floated right.
The three inner divs have all box-model measurements in pixels which add
up to the width of the enclosing container. Everything looks fine when
the browser size is 100%, but when I start making the browser smaller
with CTRL+scrollwheel or CTRL+minus the rightmost margin shrinks
down too fast and eventually becomes zero, forcing my rightmost
floated inner div to fall down below the other two!
I can't make sense out of this, almost seems like some integer division
is being performed incorrectly in the browser code, but alas firefox and
chrome both display the same result.
Here is the example (just zoom out with CTRL-minus to see what I mean):
Click Here to View What I Mean on Example Site
Just to narrow things down a bit, the tags of interest are the following:
div#mainContent
div#contentLeft
div#contentCenter
div#contentRight
I've searched stackoverflow for an answer and found the following
posts which seem related to my question but was not able to apply
them to the problem I am experiencing:
http://
stackoverflow.com/questions/6955313/div-moves-incorrectly-on-browser-resize
http://
stackoverflow.com/questions/18246882/divs-move-when-resizing-page
http://
stackoverflow.com/questions/17637231/moving-an-image-when-browser-resizes
http://
stackoverflow.com/questions/5316380/how-to-stop-divs-moving-when-the-browser-is-resized
I've duplicated the html and css code below for your convenience:
Here is the HTML:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Pinco</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="wrapper">
<header>
<div class="logo">
<a href="http://pinco.com">
<img class="logo" src="images/PincoLogo5.png" alt="Pinco" />
</a>
</div>
<div class="titolo">
<h1>Benvenuti!</h1>
<h2>Siete arrivati al sito pinco.</h2>
</div>
<nav>
<ul class="menu">
<li>Menù Qui</li>
<li>Menù Quo</li>
<li>Menù Qua</li>
</ul>
</nav>
</header>
<div id="mainContent">
<div id="contentLeft">
<section>
<article>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tempor turpis est, nec varius est pharetra scelerisque. Sed eu pellentesque purus, at cursus nisi. In bibendum tristique nunc eu mattis. Nulla pretium tincidunt ipsum, non imperdiet metus tincidunt ac. In et lobortis elit, nec lobortis purus. Cras ac viverra risus. Proin dapibus tortor justo, a vulputate ipsum lacinia sed. In hac habitasse platea dictumst. Phasellus sit amet malesuada velit. Fusce diam neque, cursus id dui ac, blandit vehicula tortor.
Phasellus interdum ipsum eu leo condimentum, in dignissim erat tincidunt. Ut fermentum consectetur tellus, dignissim volutpat orci suscipit ac. Praesent scelerisque urna metus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Duis pulvinar, sem a sodales eleifend, odio elit blandit risus, a dapibus ligula orci non augue. Nullam vitae cursus tortor, eget malesuada lectus. Nulla facilisi. Cras pharetra nisi sit amet orci dignissim, a eleifend odio hendrerit.
</p>
</article>
</section>
</div>
<div id="contentCenter">
<section>
<article>
<p>
Maecenas vitae purus at orci euismod pretium. Nam gravida gravida bibendum. Donec nec dolor vel magna consequat laoreet in a urna. Phasellus cursus ultrices lorem ut sagittis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Vivamus purus felis, ornare quis ante vel, commodo scelerisque tortor. Integer vel facilisis mauris.
</p>
<img src="images/auto1.jpg" width="272" height="272" />
<p>
In urna purus, fringilla a urna a, ultrices convallis orci. Duis mattis sit amet leo sed luctus. Donec nec sem non nunc mattis semper quis vitae enim. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Suspendisse dictum porta quam, vel lobortis enim bibendum et. Donec iaculis tortor id metus interdum, hendrerit tincidunt orci tempor. Sed dignissim cursus mattis.
</p>
</article>
</section>
</div>
<div id="contentRight">
<section>
<article>
<img src="images/auto2.jpg" width="272" height="272" />
<img src="images/auto3.jpg" width="272" height="272" />
<p>
Cras eu quam lobortis, sodales felis ultricies, rhoncus neque. Aenean nisi eros, blandit ac lacus sit amet, vulputate sodales mi. Nunc eget purus ultricies, aliquam quam sit amet, porttitor velit. In imperdiet justo in quam tristique, eget semper nisi pellentesque. Cras fringilla eros enim, in euismod nisl imperdiet ac.
Fusce tempor justo vitae faucibus luctus.
</p>
</article>
</section>
</div>
</div>
<footer>
<div class="footerText">
<p>
Copyright © Pinco
<br />Lorem ipsum dolor sit amet, consectetur adipiscing elit.
<br />Fusce ornare turpis orci, nec egestas leo feugiat ac.
<br />Morbi eget sem facilisis, laoreet erat ut, tristique odio. Proin sollicitudin quis nisi id consequat.
</p>
</div>
<div class="footerLogo">
<img class="footerLogo" src="images/auto4.jpg" width="80" height="80" />
</div>
</footer>
</div>
</body>
</html>
and here is the CSS:
/* CSS Document */
* { margin: 0; border: 0; padding: 0; }
body { background: #8B0000; /* darkred */; }
body { margin: 0; border: 0; padding: 0; }
div#wrapper { margin: 0 auto; width: 960px; height: 100%; background: #FFC0CB /* pink */; }
header { position: relative; background: #005b97; height: 140px; }
header div.logo { float: left; width: 360px; height: 140px; }
header div.logo img.logo { width: 360px; height: 140px; }
header div.titolo { float: left; padding: 12px 0 0 35px; color: black; }
header div.titolo h1 { font-size: 36px; font-weight: bold; }
header div.titolo h2 { font-size: 24px; font-style: italic; font-weight: bold; color: white;}
header nav { position: absolute; right: 0; bottom: 0; }
header ul.menu { background: black; }
header ul.menu li { display: inline-block; padding: 3px 15px; font-weight: bold; }
div#mainContent { float: left; width: 100%; /* width: 960px; *//* height: 860px; */ padding: 30px 0; text-align: justify; }
div#mainContent img { margin: 12px 0; }
div#contentLeft { height: 900px; float: left; margin-left: 12px; border: 1px solid black; padding: 15px; width: 272px; background: #ccc; }
div#contentCenter { height: 900px; float: left; margin-left: 12px; border: 1px solid transparent; padding: 15px; width: 272px; background: #E00; }
div#contentRight { height: 900px; float: left; margin-left: 12px; border: 1px solid black; padding: 15px; width: 272px; background: #ccc; }
footer { clear: both; padding: 12px; background: #306; color: white; height: 80px; font-style: italic; font-weight: bold; }
footer div.footerText { float: left; }
footer div.footerLogo { float: right; }
a { color: white; text-decoration: none; }
EDIT 1:
I've checked all measurements again and carefully plugged in numbers until they
satisfied the following equation for the three uniform columns in the main area
with uniform collapsed margin areas on all sides:
TEXT_AREA * 3 + MARGIN * 4 + BORDER * 6 = 960px (the width of the
wrapper)
TEXT_AREA = WIDTH + 2 * PADDING
BORDER = 1
subject to the margin and padding set to reasonable values of course,
and here are some numbers which seemed OK which solve these constraints:
TEXT_AREA = 290px
MARGIN = 15px
BORDER = 1px
PADDING = 15px
WIDTH = 268px
which translates to the following:
div#mainContent { float: left; width: 960px; padding: 15px 0; text-align: justify; }
div#contentLeft { height: 900px; float: left; margin: 0 0 0 15px; border: 1px solid black; padding: 15px; width: 268px; background: #ccc; }
div#contentCenter { height: 900px; float: left; margin: 0 0 0 15px; border: 1px solid transparent; padding: 15px; width: 268px; background: #E00; }
div#contentRight { height: 900px; float: left; margin: 0 15px 0 15px; border: 1px solid black; padding: 15px; width: 268px; background: #ccc; }
However even now that everything is uniform, I still get the problem that when I zoom
out the rightmost column falls down below the others. One solution is to do the following:
div#contentRight { height: 900px; float: left; margin: 0 0 /* 15px */ 0 15px; border: 1px solid black; padding: 15px; width: 268px; background: #ccc; }
so that now the right column has no right margin, but the visual result is the same.
Now, when I zoom out, the rightmost column does not fall down, but its right margin
is so small compared to the others, so really, there is still a small problem.
Edit 2:
OK, I've done some more searching and found an even better solution. The solution
consists in having the margins in between the div column elements the same and having
the left and right margin adjust automatically. In order to achieve this, I had to
do away with floats, and use "display: inline-block" which IMHO is much more suitable
than floats and was designed for the purpose at hand:
div#mainContent { padding: 15px 0; width: 960px; text-align: center; }
div#contentLeft { display: inline-block; vertical-align: top; height: 900px; margin: 0 0 0 0/*15px*/; border: 1px solid black; padding: 15px; width: 268px; background: #ccc; }
div#contentCenter { display: inline-block; vertical-align: top; height: 900px; margin: 0 0 0 15px; border: 1px solid transparent; padding: 15px; width: 268px; background: #E00; }
div#contentRight { display: inline-block; vertical-align: top; height: 900px; margin: 0 0/* 15px */ 0 15px; border: 1px solid black; padding: 15px; width: 268px; background: #ccc; }
div#mainContent section { text-align: justify; }
Now, at a normal zoom level all left margins will be 15px plus the last element's right
margin which will also be 15px. On the other hand, if I zoom out, there is some pixel
rounding going on, but the rounding is applied more or less equally on both sides,
which is somewhat better. This works in Firefox.
Edit 3:
Alas, I've tried reducing the in-between margins a bit, which makes the problem
go away with Chrome, but one of the div elements still drops down in IE10.
div#mainContent { padding: 15px 0; text-align: center; }
div#contentLeft { display: inline-block; vertical-align: top; height: 900px; margin: 0 0 0 0/* 20px increased from 15px */; border: 1px solid black; padding: 15px; width: 268px; background: #ccc; overflow: hidden; }
div#contentCenter { display: inline-block; vertical-align: top; height: 900px; margin: 0 0 0 10px/* reduced from 15px */; border: 1px solid transparent; padding: 15px; width: 268px; background: #E00; overflow: hidden; }
div#contentRight { display: inline-block; vertical-align: top; height: 900px; margin: 0 0/* 20px increased from 15px */ 0 10px/* reduced from 15px */; border: 1px solid black; padding: 15px; width: 268px; background: #ccc; overflow: hidden; }
div#mainContent section { text-align: justify; }
Edit 4:
I've come up with a solution which works in Firefox, Chrome, and IE10.
Basically, I've created three div wrappers around the three columns
and taken measurements again ensuring all measurements are symmetric.
Here is the source code:
HTML File:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Pinco</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="wrapper">
<header>
<div class="logo">
<a href="http://pinco.com">
<img class="logo" src="images/PincoLogo5.png" alt="Pinco" />
</a>
</div>
<div class="titolo">
<h1>Benvenuti!</h1>
<h2>Siete arrivati al sito pinco.</h2>
</div>
<nav>
<ul class="menu">
<li>Menù Qui</li>
<li>Menù Quo</li>
<li>Menù Qua</li>
</ul>
</nav>
</header>
<div id="mainContent">
<div id="wrapperLeft">
<div id="contentLeft">
<section>
<article>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tempor turpis est, nec varius est pharetra scelerisque. Sed eu pellentesque purus, at cursus nisi. In bibendum tristique nunc eu mattis. Nulla pretium tincidunt ipsum, non imperdiet metus tincidunt ac. In et lobortis elit, nec lobortis purus. Cras ac viverra risus. Proin dapibus tortor justo, a vulputate ipsum lacinia sed. In hac habitasse platea dictumst. Phasellus sit amet malesuada velit. Fusce diam neque, cursus id dui ac, blandit vehicula tortor.
Phasellus interdum ipsum eu leo condimentum, in dignissim erat tincidunt. Ut fermentum consectetur tellus, dignissim volutpat orci suscipit ac. Praesent scelerisque urna metus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Duis pulvinar, sem a sodales eleifend, odio elit blandit risus, a dapibus ligula orci non augue. Nullam vitae cursus tortor, eget malesuada lectus. Nulla facilisi. Cras pharetra nisi sit amet orci dignissim, a eleifend odio hendrerit.
</p>
</article>
</section>
</div>
</div>
<div id="wrapperCenter">
<div id="contentCenter">
<section>
<article>
<p>
Maecenas vitae purus at orci euismod pretium. Nam gravida gravida bibendum. Donec nec dolor vel magna consequat laoreet in a urna. Phasellus cursus ultrices lorem ut sagittis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Vivamus purus felis, ornare quis ante vel, commodo scelerisque tortor. Integer vel facilisis mauris.
</p>
<img src="images/auto1.jpg" alt="Auto 1" width="268" height="268" />
<p>
In urna purus, fringilla a urna a, ultrices convallis orci. Duis mattis sit amet leo sed luctus. Donec nec sem non nunc mattis semper quis vitae enim. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
</p>
</article>
</section>
</div>
</div>
<div id="wrapperRight">
<div id="contentRight">
<section>
<article>
<img src="images/auto2.jpg" alt="Auto 2" width="268" height="268" style="margin-top: 0" />
<img src="images/auto3.jpg" alt="Auto 3" width="268" height="268" style="margin-top: 0" />
<p>
Cras eu quam lobortis, sodales felis ultricies, rhoncus neque. Aenean nisi eros, blandit ac lacus sit amet, vulputate sodales mi. Nunc eget purus ultricies, aliquam quam sit amet, porttitor velit. In imperdiet justo in quam tristique, eget semper nisi pellentesque. Cras fringilla eros enim, in euismod nisl imperdiet ac.
Fusce tempor justo vitae faucibus luctus.
</p>
</article>
</section>
</div>
</div>
</div>
<footer>
<img class="footerLogo" src="images/auto4.jpg" alt="Auto 4" width="80" height="80" />
<p class="footerText">
Copyright © Pinco Inc.
<br />Lorem ipsum dolor sit amet, consectetur adipiscing elit.
<br />Fusce ornare turpis orci, nec egestas leo feugiat ac.
<br />Morbi eget sem facilisis, laoreet erat ut, tristique odio. Proin sollicitudin quis nisi id consequat.
</p>
</footer>
</div>
</body>
</html>
CSS File:
/* CSS Document */
*, body, article, secton, p { margin: 0; border: 0; padding: 0; }
body { background: #8B0000; /* darkred */; }
body { margin: 0; border: 0; padding: 0; }
div#wrapper { margin: 0 auto; width: 960px; height: 100%; background: #FFC0CB /* pink */; }
header { position: relative; background: #005b97; height: 140px; }
header div.logo { float: left; width: 360px; height: 140px; }
header div.logo img.logo { width: 360px; height: 140px; }
header div.titolo { float: left; padding: 12px 0 0 35px; color: black; }
header div.titolo h1 { font-size: 36px; font-weight: bold; }
header div.titolo h2 { font-size: 24px; font-style: italic; font-weight: bold; color: white;}
header nav { position: absolute; right: 0; bottom: 0; }
header ul.menu { background: black; }
header ul.menu li { display: inline-block; padding: 3px 15px; font-weight: bold; }
div#mainContent { float: left; padding: 15px 0; height: 900px; }
#wrapperLeft { float: left; margin-left: 15px; width: 305px; }
#wrapperCenter { float: left; margin: 0 15px 0 15px; width: 290px; }
#wrapperRight { float: left; margin-right: 15px; width: 305px; }
div#contentLeft { border: 1px solid black; padding: 15px; width: 273px; height: 868px; background: #ccc; overflow: hidden; }
div#contentCenter { border: 1px solid transparent; padding: 15px; width: 258px; height: 868px; background: #E00; overflow: hidden; }
div#contentRight { border: 1px solid black; padding: 15px; width: 273px; height: 868px; background: #ccc; overflow: hidden; }
div#mainContent section { text-align: justify; }
div#mainContent img { margin: 12px 0; }
footer { clear: both; padding: 12px; background: #306; color: white; height: 80px; font-size: 12px; font-style: italic; font-weight: bold; overflow: hidden; }
footer img.footerLogo { float: right; }
a { color: white; text-decoration: none; }
This is probably caused by sub-pixel rounding.
As you zoom, your browser may calculate pixel values with fractions of pixels. As a result of rounding these values up or down, pixel-perfect layouts can break. (Different browsers handle this in different ways.)
I had decent luck converting your pixel values to percentage values.
Here are the values that worked for me:
div#contentLeft,
div#contentCenter,
div#contentRight {
margin-left: 1.1%;
padding: 1.56%;
width: 28.3%;
}
Edit:
Here's another method, which essentially centers the three boxes in div#mainContent rather than spacing them so tightly with margins. It allows them a little more room to flex when zoomed.
I removed the margin-left from div#contentLeft and added the following CSS to center the three boxes:
div#wrapper {
overflow:hidden; /* ADDED THIS TO AVOID HORIZONTAL SCROLL */
}
div#mainContent {
position: relative; /* ADDED THIS */
left: 50%; /* ADDED THIS */
float: left;
padding: 30px 0px;
text-align: justify;
}
div#contentLeft {
position: relative; /* ADDED THIS */
left: -50%; /* ADDED THIS */
background: none repeat scroll 0% 0% #CCCCCC;
border: 1px solid black;
float: left;
height: 900px;
padding: 15px;
width: 272px;
/* margin-left:12px; REMOVED THIS */
}
div#contentCenter {
position: relative; /* ADDED THIS */
left: -50%; /* ADDED THIS */
background: none repeat scroll 0% 0% #EE0000;
border: 1px solid transparent;
float: left;
height: 900px;
margin-left: 12px;
padding: 15px;
width: 272px;
}
div#contentRight {
position: relative; /* ADDED THIS */
left: -50%; /* ADDED THIS */
background: none repeat scroll 0% 0% #CCCCCC;
border: 1px solid black;
float: left;
height: 900px;
margin-left: 12px;
padding: 15px;
width: 272px;
}
The boxes remain floated on one row even when Firefox is zoomed all the way out.