I am trying to do this shape in HTML/CSS for my mobile app:
https://embed.plnkr.co/9k8jbJyzUiSMSoSHlOti/
.boundary {
width: 100.13723%;
padding-bottom: 5.24078%;
position: relative;
overflow: hidden;
background-color: white;
}
.boundary:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transform-origin: top left;
transform: rotate(3deg);
background-color: green;
}
.inner {
height: 100%;
width: 100%;
background-color: green;
}
<div class="boundary"></div>
<div class="inner">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis auteirure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
In my browser, when I inspect the element and change the zoom (to 75%), there is a gap between 2 <div>. When I deploy my application in my device, I can see this same gap.
What is going on ?
This is how I make the shape:
I create a first div to do the inclined line. I make a responsive triangle (I picked some information from this Question)
1) In my div, I insert a first pseudo-element and give it 100% width and height of parent. I apply a rotation : I define a transform origin in the top left, and rotate the pseudo element 3 degrees clockwise with transform: rotate(3deg)
2) I have to adjust width and height: I use percentages and padding-bottom to maintain the aspect ratio (more information here) so:
[rectangle height] : padding-bottom = tan(3deg) * 100% = 100.13723% (100% is the screen width)[hypotenuse of triangle = new rectangle width] : width = tan(3deg) * 100% / sin(3deg) = 5.24078%.
3) To hide the unwanted parts of the pseudo element (everything that overflows the <div> with the red border) I set overflow: hidden on the container.
I make a second <div> after the first inclined <div>. This <div> is simple, without special transformation, and contains Lorem ipsum.
This usually happens while transforming elements because browser starts doing antialiasing with elements' edges.
Antialiasing is something of an unsung hero in web graphics; it’s the
reason we have clear text and smooth vector shapes on our screens.
While zooming out/in browser doesn't rescale element properly, e.g. if you zoom out an element of 1px height to 0.75%, browser should redraw element to 0.75px but browser cannot draw 0.75px, it either can create it 1 or it will try to make edges smooth with making pixel blur or 50% opacity.
In above picture you can see the same triangle being drawn, but on the left it has antialiasing enabled and on the right it’s been disabled. As you can see, when antialiasing is enabled the pixels are shades of gray when the triangle only passes through part of the pixel. When disabled, however, the pixel is filled in as either solid black or solid white and the shape looks jagged.
Using backface-visibility: hidden; or overlapping elements with negative margins while scaling/transforming is the better option to avoid this issue.
Demo without using backface-visibility: hidden;
html,
body {
transform: scale(.8);
}
.boundary {
width: 100.13723%;
padding-bottom: 5.24078%;
position: relative;
overflow: hidden;
background-color: white;
}
.boundary:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transform-origin: top left;
transform: rotate(3deg);
background-color: green;
}
.inner {
height: 100%;
width: 100%;
background-color: green;
}
<div class="boundary"></div>
<div class="inner">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
Demo with using backface-visibility: hidden;
html,
body {
transform: scale(.8);
}
.boundary {
width: 100.13723%;
padding-bottom: 5.24078%;
position: relative;
overflow: hidden;
background-color: white;
}
.boundary:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transform-origin: top left;
transform: rotate(3deg);
background-color: green;
}
.inner {
height: 100%;
width: 100%;
background-color: green;
backface-visibility: hidden;
-webkit-backface-visibility: hidden;
}
<div class="boundary"></div>
<div class="inner">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
Demo provided by OP in comment solved by using backface-visibility: hidden; and overlapping elements with negative margin
html,
body {
transform: scale(.75);
}
.inner {
height: 100%;
width: 100%;
background-color: green;
backface-visibility: hidden;
-webkit-backface-visibility: hidden;
}
.inner-2 {
background-color: red;
backface-visibility: hidden;
-webkit-backface-visibility: hidden;
}
.inner-3 {
background-color: blue;
backface-visibility: hidden;
-webkit-backface-visibility: hidden;
}
.boundary {
width: 100.13723%;
padding-bottom: 5.24078%;
position: relative;
overflow: hidden;
background-color: white;
margin-top: -2px;
}
.boundary:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transform-origin: top left;
transform: rotate(3deg);
background-color: green;
backface-visibility: hidden;
}
.boundary-2 {
background-color: green;
}
.boundary-2:before {
transform-origin: top right;
transform: rotate(-3deg);
background-color: red;
}
.boundary-3 {
background-color: red;
}
.boundary-3:before {
transform-origin: top left;
transform: rotate(3deg);
background-color: blue;
}
<div class="boundary"></div>
<div class="inner">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<div class="boundary boundary-2"></div>
<div class="inner inner-2">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<div class="boundary boundary-3"></div>
<div class="inner inner-3">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
PS: Don't forget to use viewport meta tag for responsiveness.
Source Antialiasing-101
I think I have fixed it by using skew and adding a border and a negative margin at the top.
Here's a CodePen and below is my CSS:
.boundary {
padding-bottom: 5.24078%;
position: relative;
overflow: hidden;
background-color: white;
}
.boundary:before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 105%;
height: 105%;
transform-origin: top left;
background-color: green;
transform: skew(0, 3deg);
z-index: 10;
}
.inner {
height: 100%;
width: 100%;
background-color: green;
color: #fff;
z-index: 50;
position: relative;
border-top: 1px solid green;
margin-top: -1px;
}
Gap is still there even if you do not apply any transformation.
.boundary {
width: 100.13723%;
padding-bottom: 5.24078%;
position: relative;
overflow: hidden;
background-color: white;
}
.boundary:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
/*transform-origin: top left;*/
/*transform: rotate(3deg);*/
background-color: green;
}
.inner {
height: 100%;
width: 100%;
background-color: green;
}
<div class="boundary"></div>
<div class="inner">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis auteirure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
So transform:rotate() or something are not causing any troubles.
Now your problem can be solved by
.inner {
margin-top: -2px;
/* experiment different value or unit for different zoom levels*/
height: 100%;
width: 100%;
background-color: green;
}
For me it is rendering problem. If you change
top: 0px;
to
top: 1px;
everything should be fine.
Related
I want realise this page
this is my work
the probleme is i can't superimpose the div who contain the text "LUCETTE" under the div who contain the picture
my code html:
* {
font-size: 16px;
font-family: 'playfair_displayblack';
}
.container {
position: relative;
}
.central {
display: flex;
width: 66vw;
height: 55vh;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, 50%);
z-index: 2;
}
.left {
flex: 1;
}
.right {
flex: 2;
background-color: #2b563b;
overflow: hidden;
}
.belle {
max-width: 100%;
max-height: 100%;
display: block;
border: 9px solid whitesmoke;
}
.bas {
display: flex;
flex-direction: row;
}
.pied {
bottom: 100px;
width: 90vw;
height: 30vh;
margin-left: auto;
margin-right: auto;
}
.titre span {
text-align: center;
text-transform: uppercase;
font-size: 16rem;
font-weight: bolder;
font-family: 'playfair_displayitalic';
position: absolute;
bottom: 0;
z-index: -1;
}
<main class="container">
<div class="central">
<div class="left">
<img src="images/chantal.jpg" alt="" class="belle">
</div>
<div class="right">
<section>
<header>
<h1> <span>strategy</span> </h1>
</header>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</section>
</div>
</div>
<div class="pied">
<h1 class="titre"> <span>lucette</span> </h1>
</div>
</main>
THANKS .
i'm tryng to superimpose the div who contain the image on top of the div who contain the text "LUCETTE".
but the text "LUCETTE" is on the top of my page .
Try this:
* {
font-size: 16px;
font-family: 'playfair_displayblack';
}
.container {
position: relative;
padding-top: 100px;
height: 100vh;
display: flex;
justify-content: center;
}
.central {
display: flex;
width: 66vw;
height: 55vh;
z-index: 2;
}
.left {
flex: 1;
}
.right {
flex: 2;
background-color: #2b563b;
overflow: hidden;
}
.belle {
max-width: 100%;
max-height: 100%;
display: block;
border: 9px solid whitesmoke;
}
.bas {
display: flex;
flex-direction: row;
}
.pied {
bottom: 100px;
width: 90vw;
height: 30vh;
margin-left: auto;
margin-right: auto;
}
.pied {
font-weight: bolder;
font-family: serif;
position: absolute;
width: 0px;
overflow: visible;
bottom: 35%;
left: 50%;
}
.pied h1 {
position: absolute;
text-align: center;
text-transform: uppercase;
font-size: 16rem;
transform: translate(-50%, 0);
font-family: 'playfair_displayitalic';
top: 0;
left: 50%;
}
<main class="container">
<div class="central">
<div class="left">
<img src="images/chantal.jpg" alt="" class="belle">
</div>
<div class="right">
<section>
<header>
<h1> <span>strategy</span> </h1>
</header>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</section>
</div>
</div>
<div class="pied"><h1>lucette</h1></div>
</main>
Mind the fact that you might need to tweak the bottom attribute of .pied as I did not have that font.
Main issue in your code was that you didn't set position: absolute for the main container of the text. I did some tweaks to ensure that text is also centered etc.
Using absolute position removes items from the normal flow of the page, and can often lead to isolation and z-index mistakes.
I'm attaching a method using a grid layout to superimpose items. Grids are usually easier to debug.
Just to be clear absolute positions can be used, this is just an alternative.
section {
display: grid;
}
.behind {
height: 5rem;
width: 5rem;
background-color: red;
grid-area: 1 / 1;
}
.front {
height: 3rem;
width: 3rem;
background-color: blue;
/* Can also use grid-area */
grid-column: 1;
grid-row: 1;
}
<section>
<div class="behind"></div>
<div class="front"></div>
</section>
enter image description here
Now the result is better but the problem now i want move the bloc center ho contain the picture and the texte in the the middle on the page but i can 't
I want to upscale image on hover, but the problem is I can make it overlapse its own container with overflow: hidden only by making img absolute positioned, wherefore all article content 'thinks' that there is no image in container.
article {
background: #e8e8e8;
color: #484848;
overflow: hidden;
padding: 0.5rem;
margin: 2rem auto 0 auto;
width: 60vw;
}
section {
float: left;
margin-right: 0.5rem;
}
p {
margin: 0;
}
img {
transition: 0.2s linear;
object-fit: cover;
width: 128px;
height: 128px;
}
img:hover {
position: absolute;
transform: scale( 1.5 );
}
<article>
<section>
<img src=https://image.freepik.com/free-vector/repeating-geometrical-square-background-pattern-vector-graphic-design-from-random-rotated-squares-with-opacity-effect_1164-1119.jpg>
<img src=https://image.freepik.com/free-vector/repeating-geometrical-square-background-pattern-vector-graphic-design-from-random-rotated-squares-with-opacity-effect_1164-1119.jpg>
</section>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</article>
How to freeze all article content after img becomes absolute positioned?
Please, no JS solutions.
float:left on p done the work!.
article {
background: #e8e8e8;
color: #484848;
overflow: hidden;
padding: 0.5rem;
margin: 2rem auto 0 auto;
width: 60vw;
}
section {
float: left;
margin-right: 0.5rem;
}
p {
margin: 0;
float:left;
}
img {
transition: 0.2s linear;
object-fit: cover;
width: 128px;
height: 128px;
}
img:hover {
position: absolute;
transform: scale( 1.5 );
}
<article>
<section>
<img src=https://image.freepik.com/free-vector/repeating-geometrical-square-background-pattern-vector-graphic-design-from-random-rotated-squares-with-opacity-effect_1164-1119.jpg>
<img src=https://image.freepik.com/free-vector/repeating-geometrical-square-background-pattern-vector-graphic-design-from-random-rotated-squares-with-opacity-effect_1164-1119.jpg>
</section>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</article>
As you want p to don't interact with images then before hover text will also don't interact with image and don't change it's own position.
The trick is to put the element you want to animate into a container, and then trigger the animation when you hover the container.
article {
background: #e8e8e8;
color: #484848;
padding: 0.5rem;
margin: 2rem auto 0 auto;
width: 60vw;
}
section {
float: left;
margin-right: 0.5rem;
}
p {
margin: 0;
}
img {
transition: 0.2s linear;
object-fit: cover;
width: 128px;
height: 128px;
}
.image-container {
display: inline-block;
}
.image-container:hover > img {
transform: scale( 1.5 );
}
<article>
<section>
<div class="image-container">
<img src=https://image.freepik.com/free-vector/repeating-geometrical-square-background-pattern-vector-graphic-design-from-random-rotated-squares-with-opacity-effect_1164-1119.jpg>
</div>
<div class="image-container">
<img src=https://image.freepik.com/free-vector/repeating-geometrical-square-background-pattern-vector-graphic-design-from-random-rotated-squares-with-opacity-effect_1164-1119.jpg>
</div>
</section>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</article>
This question already has answers here:
Can I set background image and opacity in the same property?
(15 answers)
Closed 3 years ago.
The background img of the header should be translucent and the text should be fully visible.
I've tried a multitude of fixes on this site and others including using :before
HTML:
<div class="banner">
<div class="bannerimage">
<div class="bannertext">
<h1>Welcome to my Portfolio</h1>
<h2>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</h2>
A link <span><i class="fas fa-caret-right"></i></span>
</div>
</div>
</div>
CSS:
.banner {
width: 100%;
}
.bannerimage {
background-image: url("img/banner.jpg");
position: relative;
height: 500px;
}
.bannerimage:before{
content: '';
position: absolute;
top: 0;
right: 0;
left: 0;
bottom: 0;
background: rgba(0,0,0,0.7);
opacity: 0.4;
}
.bannertext {
color: 111;
position: relative;
text-align: right;
}
Background should be translucent foreground text should be solid.
You can use this code
body {
margin: 0;
padding: 0;
}
.banner {
width: 100%;
}
.bannerimage {
width: 100%;
height: 500px;
display: block;
position: relative;
background: rgba(0,0,0,0.7);
}
.bannerimage::after {
content: "";
background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/652/codepen.png);
background-repeat: no-repeat;
background-position: center;
background-size: cover;
position: relative;
opacity: 0.4;
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
z-index: -1;
}
.bannertext {
color: 111;
position: relative;
text-align: right;
}
.bannertext h1 {
margin-top: 0px;
color: #fff;
}
.bannertext h2 {
color: #fff;
}
.bannertext a {
color: #fff;
}
<div class="banner">
<div class="bannerimage">
<div class="bannertext">
<h1>Welcome to my Portfolio</h1>
<h2>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</h2>
A link <span><i class="fas fa-caret-right"></i></span>
</div>
</div>
</div>
If you give opacity to parent .banner-image it will affect its child. So update your code like:
.banner {
width: 100%;
position: relative;
}
.bannerimage {
background-image: url(https://via.placeholder.com/1000x700);
position: relative;
height: 500px;
opacity: 0.5;
background-size: cover;
}
.bannertext {
color: #111;
text-align: right;
position: absolute;
top: 0;
width: 100%;
}
<div class="banner">
<div class="bannerimage">
</div>
<div class="bannertext">
<h1>Welcome to my Portfolio</h1>
<h2>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</h2>
A link <span><i class="fas fa-caret-right"></i></span>
</div>
</div>
I updated my chrome to version 55 and now my position: fixed; in a div overflow: hidden; doesn't work anymore.
Here is the example:
http://codepen.io/PRDev/pen/mOvwOO
.container {
background: #d3d3d3;
}
.overflow {
position: relative;
width: 100%;
height: 100vh;
overflow: hidden;
z-index: 1;
}
.parallax {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #dfdfdf;
}
.next-section {
position: relative;
z-index: 10;
height: 200vh;
}
<div class="container">
<div class="overflow">
<div class="parallax">
<h1>Headline</h1>
<p>Lorem ipsum</p>
</div>
</div>
<div class="next-section">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
</div>
When I'm scrolling to down, the text is still visible outside div overflow hidden, on safari and chrome 54 it is hidden but not in latest Chrome 55.
On chrome 54 text in .overflow hide behind text in next-section, on chrome 55 this text in overflow is visible behind next-section
I dont think this is an issue with how overflow:hidden; works. That dictates what happens to content that overflows its parent. What you are doing is moving one div over another and the reason you see the one behind is because .next-section didnt have a background.
give .next-section the same bg color background: #dfdfdf;
body {
margin: 0;
}
.container {
background: #d3d3d3;
}
.overflow {
position: relative;
width: 100%;
height: 100vh;
overflow: hidden;
z-index: 1;
}
.parallax {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #dfdfdf;
}
.next-section {
background: #dfdfdf;
position: relative;
z-index: 10;
height: 200vh;
}
<div class="container">
<div class="overflow">
<div class="parallax">
<h1>Headline</h1>
<p>Lorem ipsum</p>
</div>
</div>
<div class="next-section">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
</div>
I am trying to display a double column layout. In the left column there is a picture which can be displayed as 30% or the available width but no more than 300px. In the right column there is a description that spans the rest of the browser width.
I do not know a priori how long the description is and I want to limit the height of the description field so I am using textarea to enable scrolling if needed.
This is my current HTML code:
<div class="tile-panel">
<div class="tile-preview-panel">
<img class="tile-img" src="{{ thumbnail_url }}">
</div>
<div class="tile-desc-panel">
<textarea readonly class="form-control tile-description"> {{ desc }} </textarea>
</div>
</div>
And my CSS:
.tile-panel {
width: 100%;
overflow: auto;
}
.tile-preview-panel {
width: 30%;
float:left;
max-width: 300px;
}
.tile-desc-panel {
overflow: hidden;
}
.tile-img {
width: 100%;
}
.tile-description {
resize: none;
background-color:inherit !important;
width: 100%;
}
.tile-description[readonly] {
cursor: default; !important;
}
The only remaining bit is the height of the textarea. I want it always to be the height of the tile-preview-panel, regardless of the width of the browser. Is this achievable with pure CSS?
Here is a start, this one using your existing textarea,
.tile-panel {
display: table;
width: 100%;
}
.tile-preview-panel {
display: table-cell;
width: 30%;
}
.tile-desc-panel {
display: table-cell;
position: relative;
}
.tile-img {
width: 100%;
}
.tile-description {
resize: none;
background-color:inherit !important;
width: 100%;
height: 100%;
box-sizing: border-box;
left: 0;
top: 0;
position: absolute;
}
.tile-description[readonly] {
cursor: default; !important;
}
#media (min-width: 1000px){
.tile-preview-panel {
width: 300px;
}
}
<div class="tile-panel">
<div class="tile-preview-panel">
<img class="tile-img" src="http://lorempixel.com/300/300/sports/1/">
</div>
<div class="tile-desc-panel">
<textarea readonly class="form-control tile-description"> {{ desc }} </textarea>
</div>
</div>
and here is a version using a div instead, so you can style the text more, use links etc.
.tile-panel {
display: table;
width: 100%;
}
.tile-preview-panel {
display: table-cell;
width: 30%;
padding-right: 5px;
}
.tile-desc-panel {
display: table-cell;
position: relative;
background-color: #ddd;
border: 1px solid #999;
}
.tile-img {
width: 100%;
vertical-align: top;
}
.tile-description {
left: 0;
right: 0;
top: 0;
bottom: 0;
position: absolute;
overflow: auto;
padding-left: 10px;
}
#media (min-width: 1000px) {
.tile-preview-panel {
width: 300px;
}
}
<div class="tile-panel">
<div class="tile-preview-panel"><img class="tile-img" src="http://lorempixel.com/300/300/nature/5/"></div>
<div class="tile-desc-panel">
<div class="tile-description">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
</div>
</div>
Also flex can be used, though it has slightly less browser support.
.container {
display: flex;
width: 100%;
}
.pic {
flex: 0 0 20%;
max-width: 200px;
padding-right: 10px;
}
.text {
flex: 1;
position: relative;
overflow: auto;
background-color: #ddd;
border: 1px solid #999;
}
.pic img {
width: 100%;
vertical-align: top;
}
.text div {
left: 0;
right: 0;
top: 0;
bottom: 0;
position: absolute;
padding-left: 10px;
}
<div class="container">
<div class="pic">
<img src="http://lorempixel.com/300/300/nature/1/">
</div>
<div class="text">
<div class="tile-description">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
</div>
</div>
i would use javascript for this
put this in the head
<script>
function sameheight(){
var divHeight = document.getElementById('DIV ID YOU WANT TO GET HEIGHT OF').style.height;
document.getElementById('DIV ID YOU WANT THE SAME SIZE').style.height = divHeight;
}
</script>
And put on your body
<body onload="sameheight()">
This should work:
.tile-panel {
width: 100%;
position: relative;
}
.tile-preview-panel {
position: relative;
width: 74%;
}
.tile-desc-panel {
position: absolute;
top: 0;
right:0;
bottom:0;
margin-left: 1.5%;
width: 24.5%;
height: 100%;
background: #232323;
overflow: hidden;
}
.tile-img {
width: 100%;
}
.tile-description {
resize: none;
background-color:inherit !important;
width: 100%;
}
.tile-description[readonly] {
cursor: default; !important;
}
textarea {
border: none;
}
<div class="tile-panel">
<div class="tile-preview-panel">
<img class="tile-img" src="http://placehold.it/640x260">
</div>
<div class="tile-desc-panel">
<textarea readonly class="form-control tile-description"> {{ desc }} </textarea>
</div>
</div>
Another variant of using javascript as #user1899614 suggested but with ES6 and getBoundingClientRect() method:
const makeDimensionsEqual = (someTextareaSelector, someParentElementSelector) => {
document.querySelectorAll(someTextareaSelector)[0].style.height =
document.querySelectorAll(someParentElementSelector)[0]
.getBoundingClientRect().height + "px"
}
const someTextareaSelector = '...'
const someParentElementSelector = '...'
makeDimensionsEqual(someTextareaSelector, someParentElementSelector)