CSS textarea image background with opacity without impacting the foreground text - html

I have a textarea that user can change its size.
I need to have an image background for it but I do not want the image disturbs the text so the image should be partially transparent without impacting the opacity of the text that user can type on top of it.
I followed this link which suggests using ::before but it does not work on my Firefox browser.
<textarea class="hero">
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.
</textarea>
CSS
.hero {
position: relative;
/* height: 100vh; */
/* width: 100%; */
display: flex;
align-items: center;
justify-content: center;
}
.hero::before {
content: "";
background-image: url('https://placekitten.com/1200/800');
background-size: cover;
position: absolute;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
opacity: 0.75;
}
https://jsfiddle.net/z86yfLvh/1/
How should I fix this?

The easiest solution here would be wrapping your textarea element into a container, put background on it and tune the background of your textarea down, through background-color with alpha inside the rgba().
Like this:
.hero {
background-color: rgba(255, 255, 255, .7)
}
.hero-container {
background-image: url('https://placekitten.com/1200/800');
background-size: cover;
display: inline-block;
}
<div class="hero-container">
<textarea class="hero">
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.
</textarea>
</div>
I should mention also that ::before won't work with textarea because it would have to render it inside the textarea which can't contain any HTML elements directly. It's a hard limitation.
Alternative solution that also solves another issue that OP mentioned in the comment:
.hero {
background-color: rgba(255, 255, 255, .7);
width: 100%;
height: 100%;
resize: none;
}
.hero-container {
background-image: url('https://placekitten.com/1200/800');
background-size: cover;
resize: both;
overflow: auto;
width: 100%;
}
<div class="hero-container">
<textarea class="hero">
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.
</textarea>
</div>
I'm using resize: none on textarea to disable the ability to resize it and I'm adding it to the container instead, while width: 100%; height: 100% makes sure textarea stretches with the container too.

Related

Container gets cuts off when using flex for a dialog in Internet Explorer 11

I am trying to create a cross-browser dialog box system. Basically, you click a link and the dialog pops down. Surprisingly, I got it to work on all major browsers, including IE 11. The only issue is if the content inside the dialog box exceeds the window, the box gets cut off in IE 11. Here's the code:
/* Core styles */
html,
body {
position: absolute;
height: 100%;
width: 100%;
margin: 0;
padding: 0;
left: 0;
top: 0;
}
.page {
position: absolute;
height: 100%;
width: 100%;
overflow: hidden;
}
.content-wrapper {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
width: 100%;
box-sizing: border-box;
overflow: auto;
}
.card {
position: relative;
box-sizing: border-box;
margin: 3rem;
padding: 3rem;
color: rgba(0, 0, 0, 0.8);
background-color: #ffffff;
border-radius: 0.4rem;
border: 1px solid rgba(0, 0, 0, 0.2);
-moz-box-shadow: none;
-webkit-box-shadow: none;
box-shadow: none;
}
/* Dialog styles */
.dialog-outer {
position: absolute;
top: -100%;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.8);
-webkit-transition: all .4s cubic-bezier(.25, .8, .25, 1);
transition: all .4s cubic-bezier(.25, .8, .25, 1);
z-index: 99;
outline: none;
}
.dialog-outer .dialog-inner {
height: 100%;
overflow: auto;
}
.dialog-outer .dialog-inner .dialog-content {
position: absolute;
box-sizing: border-box;
display: flex;
flex-direction: column;
top: -100%;
left: 0;
width: 100%;
height: 100%;
overflow: auto;
}
.dialog-outer .dialog-inner .dialog-content .card {
margin: auto;
}
.dialog-outer:target {
top: 0;
}
.dialog-outer:target ~ .page .content-wrapper {
overflow: hidden;
}
.dialog-outer:target .dialog-content {
top: 0;
}
<!-- Dialog 1 -->
<div class="dialog-outer" id="dialog-1">
<div class="dialog-inner">
<div class="dialog-content">
<div class="card" style="width: 400px;">
<strong>Dialog 1</strong>
<br /><br />
<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>
Close
</div>
</div>
</div>
</div>
<!-- Dialog 2 -->
<div class="dialog-outer" id="dialog-2">
<div class="dialog-inner">
<div class="dialog-content">
<div class="card" style="width: 400px;">
<strong>Dialog 2 (long scrolling content)</strong>
<br /><br />
<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>
<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>
<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>
Close
</div>
</div>
</div>
</div>
<!-- Page -->
<div class="page">
<div class="content-wrapper">
<div style="padding: 20px;">
<!-- Toggles -->
Toggle dialog 1
<br /><br />
Toggle dialog 2
</div>
</div>
</div>
The huge chunks of code basically generates 2 dialog boxes. One where the content is tiny, so it does not exceed the page length, the other need requires scroll. Unfortunately, the second dialog box gets cut off in IE 11. It works on all the other browsers I tested on, including some old versions of Edge and Firefox. What exactly is the issue on IE 11?
The ideal answer would be one that requires no changes to the HTML markup, and the core styles.
You can download the above code as an HTML file here: https://anonfile.com/933cv8o0o0/dialog_html
Thanks for any help!
I think the issue is with flexbox. In the flex value of browser compatibility, it says:
IE incorrectly positions inline block content inside flex containers.
The issue can be fixed if you remove display: flex; in #dialog-2. You could change the following css styles like this:
.dialog-outer .dialog-inner .dialog-content {
position: absolute;
box-sizing: border-box;
/*display: flex;*/
flex-direction: column;
top: -100%;
left: 0;
width: 100%;
height: 100%;
overflow: auto;
}
#dialog-1 .dialog-inner .dialog-content {
display: flex;
}

Two divs within another div overlap

I asked a similar question already but haven't found an answer. I am now at a different section of my website but have the the issue here as well. The code is super basic, so I am hoping this will help to solve the issue.
Some context: My front page is sectioned in 3 container divs, each of them with 100vh, so they should take up the entire screen, even when someone resizes the browser. The second div in the code below (.showcase) should stick to the bottom of the Container div (that's why I added position: absolute and bottom: 0).
My issue is now that the two divs in the Container div 1, keep overlapping when I reduce the browser height for example. But I want them to 'push' each other away from each other, basically not giving space for the other div to overlap. So that when I, for example, would add a padding to the two divs, that the padding still shows on the page even if resizing the browser. And no matter what I added (display: block, Flexbox, even putting the divs into a table etc) all of this didn't help and the content of the two divs keeps overlapping.
Can anyone help me here? I literally don't know how to go from here...
Here is the code:
.Container1 {
overflow: hidden;
height: 100vh;
width: 100%;
margin: 0;
background: rgb(74, 105, 113);
background: linear-gradient(90deg, rgba(74, 105, 113, 1) 0%, rgba(129, 161, 170, 1) 60%, rgba(181, 207, 214, 1) 100%);
text-align: center;
display: block;
}
.hp_slogan {
padding-top: 20%;
padding-bottom: 3%;
}
.showcase {
position: absolute;
bottom: 0;
display: block;
}
<div class="Container1">
<div class="hp_slogan">
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="showcase">
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 believe this will solve your problem If I understood correctly what you need.
.Container1 {
overflow:hidden;
height: 100vh;
width: 100%;
margin: 0;
background: rgb(74,105,113);
background: linear-gradient(90deg, rgba(74,105,113,1) 0%, rgba(129,161,170,1) 60%, rgba(181,207,214,1) 100%);
text-align: center;
display: flex;
flex-direction:column;
}
.hp_slogan {
padding-top: 20%;
margin-bottom:20px;
padding-bottom: 3%;
}
.showcase {
bottom: 0;
}
You can simulate it in JSFiddle with this link
See if this works for you. Used flexbox to distance two divs
.Container1 {
display: flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
overflow: hidden;
height: 100vh;
width: 100%;
margin: 0;
background: rgb(74, 105, 113);
background: linear-gradient(90deg, rgba(74, 105, 113, 1) 0%, rgba(129, 161, 170, 1) 60%, rgba(181, 207, 214, 1) 100%);
text-align: center;
}
<div class="Container1">
<div class="hp_slogan">
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="showcase">
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>

How to fill the width of a background image about half way with content overlaying on top?

I'm trying to make the background-image fill the entire width of the parent div positioned in the top left corner relative to the image size (in this case 600x375) while keeping it at 100% width across the parent div as well. In addition to doing this, I have content overlaying on top of the background-image which is the intended effect. I tried background-size but that covers the whole div which I don't want. I want the background-color:red to remain the full background color of the parent div as it is now but have the background-image about half way depending on the image size. I also tried width and height attributes on the :after property but it seems to shifts the background-image around and not change the actual size of the image. What is the appropriate approach to making the background-image size fit and stretched across it but not covering the entire parent div.
Here's the jsfiddle: https://jsfiddle.net/TheAmazingKnight/6xgrftLj/4/
.container {
z-index: 10;
position: relative;
}
#parent {
padding-top: 70px;
padding-bottom: 35px;
content: '';
background-color: red;
background-repeat: no-repeat;
width: 100%;
height: 500px;
background-position-y: 50%;
background-position-x: 50%;
position: relative;
}
#parent:after {
content: '';
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-repeat: no-repeat;
background-position-y: 50%;
background-position-x: 50%;
background-image: url(https://via.placeholder.com/600x375);
height: 675px;
width: 900px;
}
<div id="parent">
<div class="container" style="
z-index: 10;
position: relative;
">
<h1>Heading 1</h1>
<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>
<span>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.</span>
<h3>Lorem ipsum dolor</h3>
<p>Download</p>
</div>
</div>
I've written a solution for you. In my solution i didn't use the image as background. I used the image as a child element of the div(#parent) and positioned it as absolute. I made some changes in both of your html and css file. Hope it will help you.
.container {
z-index: 10;
position: relative;
}
#parent {
position: relative;
content: '';
background-color: red;
background-repeat: no-repeat;
width: 100%;
height: 500px;
position: relative;
}
#parent img {
position: absolute;
z-index: -1;
top: 0;
left: 0;
width: 100%;
height: 250px;
object-fit: cover;
}
<div id="parent">
<div class="container"
>
<img src="https://via.placeholder.com/600x375" alt="">
<h1>Heading 1</h1>
<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>
<span>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.</span>
<h3>Lorem ipsum dolor</h3>
<p>Download</p>
</div>
</div>

CSS / Div container margins issue

I have a container div set to a fixed position at top of page and several relative position divs scrollable within the container. I can set margin left, right and bottom. But the top margin is ignored and runs up against the top of the container. What am I doing wrong here?
#container {
position: fixed;
width: 32rem;
height: 32rem;
background-color: #000000;
overflow: hidden;
}
#div1 {
position: relative;
width: 30em;
height: 40em;
margin: 5rem 1rem 5rem 1rem;
<div id="container">
<div id="div1"></div>
</div>
You need to add overflow:hidden and change height:22em in #div1
I think you want something like this and I hope it will helps you.
#container {
position: fixed;
width: 32rem;
height: 32rem;
background-color: #000;
overflow: hidden;
}
#div1 {
height: 22em;
margin: 5rem 1rem;
overflow: hidden;
position: relative;
width: 30em;
color:#fff;
}
<div id="container">
<div id="div1">
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.
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.
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.
</div>
</div>
Is this the desired output? http://jsfiddle.net/t9rkpspu/
#container {
position: fixed;
width: 32rem;
height: 32rem;
background-color: #000000;
overflow: hidden;
}
#div1 {
color: white;
position: relative;
width: 30em;
height: 40em;
margin: 5rem 1rem 5rem 1rem;
}

-webkit- textarea losing top & bottom padding on vertical scrollbar

I have a textarea element with fixed width & height and no resize and when the vertical scrollbar appears the padding (top & bottom) of the element is ignored.
Here is a plnkr demo: http://plnkr.co/edit/jOeYXqkOZk3FCT24BRrk?p=preview
This happens only with Chrome (tested on Chromium, Linux version).
Here is my styling for the textarea element:
textarea{
background-color: #1c1b1b;
border-bottom: 3px solid #343434;
border-radius: 4px;
color: #fff;
display: block;
height: 165px;
margin-bottom: 21px;
padding: 10px;
resize: none;
width: 90%;
}
*One solution would be to wrap the textarea element inside a div with that specific padding, but then the scrollbar will not overlap that padding and will look kinda strange.
Edit: ok, maybe it won't look as strange as I thought, but I just wonder if there is a more elegant fix, within css maybe.
I've tried to think of a workaround, depending on your own hint. You've got it right, but didn't implement it yet. :) I just coded your idea. What I did was to enclose within a wrapper, and setting before and after pseudo elements to just hide the top and bottom parts. I hope that would solve your issue.
It would also run perfectly in Chrome, Firefox as well as in IE.
.container {
width: 90%;
position: relative;
}
textarea {
background-color: #1c1b1b;
border:0;
border-radius: 4px;
color: #fff;
display: block;
height: 165px;
margin-bottom: 21px;
padding: 10px;
resize: none;
width: 100%;
border-radius: 4px;
}
.container:before, .container:after {
content:'';
display: block;
height: 10px;
background: #1c1b1b;
position: absolute;
left: 4px;
right: 18px;
}
.container:before {
top: 0px;
}
.container:after {
bottom: 0px;
}
<div class="container">
<textarea>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. 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. 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.</textarea>
</div>