I am trying to take this simple page with text on the left and an image on the right and add a media query so that the image fades to the background and becomes very light behind the text. I have tried adding linear gradients but nothing seems to be working. I set the image to display none at first thinking i would just add it again as a background image after since css moves from top to bottom but that just made my screen background white. Then I added this linear gradient which is not working at all although it is showing up in dev tools and not crossed out or anything.
I tried setting home-img to display none and then adding background image to body or section.
As you can see in the first image, it looks fine. The second is where I am having trouble with the code. I would like the background to be very light so you can read the text. Attached are my code snippets.
I tried editing home-img in the media query.https://github.com/aloha-suzanne/propelagency
HTML:
<section class="home">
<img
src="images/home-img.jpg"
class="home-img"
alt="man in striped shirt sitting on a bean bag chair while typing on his laptop"
/>
<div class="home-content">
<h1>Everything you need to succeed online.</h1>
<p>
We use strategic creativity to distinguish our clients from
competitors, let their message stand out, connect and resonate with
the audience.
</p>
Get started
</div>
</section>
CSS:
section {
display: flex;
flex-direction: column;
height: 100vh;
align-items: center;
padding: 100px;
margin-top: 60px;
}
section.home {
flex-direction: row;
margin-top: 0;
}
.home-img {
position: absolute;
bottom: 0;
right: 0;
height: 110%;
}
#media (max-width: 995px) {
.logo {
top: 10px;
left: 40px;
font-size: 1.5rem;
}
section {
padding: 100px 40px;
}
.navigation ul li a {
font-size: 2rem;
}
section {
background-image: linear-gradient(
rgba(255, 255, 255, 0.561),
rgba(255, 255, 255, 0.561)
),
url(images/home-img.jpg);
background-size: cover;
}
}
#media (max-width: 680px) {
h1 {
font-size: 1.5rem;
margin-top: 150px;
}
.home-content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
}
I've tried setting the home image to display: none and then adding it again as a background image with a linear gradient. That is making the background appear gray but not applying the image.
I think your linear gradient syntax isn't quite correct. This gradient generator is excellent for creating gradients which work.
section {
background: linear-gradient(180deg, rgba(255,255,255,0) 40%, rgba(255,255,255,0.9) 50%), url(https://images.pexels.com/photos/3277805/pexels-photo-3277805.jpeg);
background-size: cover;
width: 300px;
padding: 10em 1em 1em;
}
<section>
<h1>Everything you need to succeed online.</h1>
<p>
We use strategic creativity to distinguish our clients from
competitors, let their message stand out, connect and resonate with
the audience.
</p>
<p>Get started</p>
</section>
Related
Having a little trouble removing a very thin border that is appearing around our :before and :after elements. This only seems to appear on a mobile device - doesn't even pop up in Chrome's device tools.
Problem:
Here's how the HTML/CSS looks.
.container {
position: relative;
display: flex;
flex-wrap: wrap;
justify-content: center;
list-style: none;
padding: 100px 0px;
margin-bottom: 56px;
width: 100%;
}
container:after {
content: "";
background-image: url("$asset");
background-size: cover;
background-position: bottom;
position: absolute;
left: 0;
top: -15px;
width: 100%;
height: 16px;
border: 0;
outline: 0;
}
<div class="container">
<div class="bg"></div>
<section>
//Headings and Links here
</section>
</div>
I've tried making absolutely sure borders and outlines are set to none - and also adding and taking away a pixel or two from the top and bottom margins, but nothing really seems to work. It's also a bit inconsistent, the lines don't necessarily show on every page that the component is on.
Replace border: 0; with: border: none; very simple CSS Code. Also, the outline code is just for things like text, this has nothing to do with the border.
It's a chrome bug lads. Second answer here nailed it.
The solutions is reducing the height/width to 0 and putting padding in to account for the space instead. Seems to have worked in my case.
I'm trying to get this cloud-like/gaussian blue effect, but I can't quite get it. I've tried using drop shadows with the same background color but it's not exactly right. Anyone know how to do it?
The given image doesn’t look so much like a CSS drop shadow as mentioned in the question, more like an image put in an element on top of which is a div with something like a linear gradient, or even multiples of these, semi transparent.
This sort of thing
background-image: linear-gradient(to bottom right, rgba(0,0,0,0.5),rgba(255,255,255,0.5));
But more sophisticated. Playing around with tones and opacities and positioning is probably the only way to get exactly what is wanted, the good thing about linear gradients being they let you do that.
I'm using a pseudo-element of the .splash container, makes it smaller than it's parent. On that pseudo-element, I have a partially transparent background and a box-shadow.
I do need to place all children of said container on top of the pseudo-class.
As you can see, the background begin to fade before the edge of the parent element that contains all text.
section {
height: 200px;
display: flex;
justify-content: center;
align-items: center;
background-color: #121212
}
.splash {
--splash-background-color: rgba(255, 255, 255, 0.3);
--splash-background-size-decrement: 60px;
position: relative;
z-index: 2;
}
.splash > * {
position: relative;
z-index: 1;
}
.splash::before {
content: '';
position: absolute;
left: var(--splash-background-size-decrement);
right: var(--splash-background-size-decrement);
top: var(--splash-background-size-decrement);
bottom: var(--splash-background-size-decrement);
background-color: var(--splash-background-color);
box-shadow: 0px 0px 50px 60px var(--splash-background-color);
}
<section>
<div class="splash">
<h1>Some text here</h1>
<p>Some text here. Some text here</p>
<p>Some text here. Some text here</p>
</div>
<section>
You can achieve this using the SVG image. You can add SVG image in CSS file or you can add SVG code in HTML file. I am not able to attach SVG file here.
This is the final output.
<style>
body{
/*background-image: url("#"); Add background Image*/
background-repeat: no-repeat;
background-size: 100%;
display: flex;
height: 100vh;
justify-content: center;
align-items: center;
margin: 0 auto;
max-width: 800px;
max-height: 800px;
}
.container{
width: 800px;
height: 800px;
/*background-image: url(".svg");*/
/*or .svg code in html file*/
background-repeat: no-repeat;
}
</style>
<body>
<div class="container"></div>
</body>
I have a grid of numbers and the selected one must be shown with a background gradient. So I used the normal procedure with flex-box, as we can see in the code. But the number isn't in the exact center of the square as it's supposed it should be.
.cell {
/* Square definition */
width: 100px;
height: 100px;
border: 1px solid black;
font-size: 2rem;
/* Centering */
display: flex;
justify-content: center;
align-items: center;
/* Background at the center */
color: white;
background: radial-gradient(ellipse at center, red 0%,red 50%, transparent 55%);
}
<div class="cell">15</div>
Why does this happen? How can I make the number be exactly in the middle of the square without any extra markup?
EDIT: On the left it's how it looks now, on the right it's how I think it should look like. The browser is Chrome on Linux.
EDIT II: There must be an issue with how this markup is rendered on Linux. Here's how I see the codepen courtesy of G-Cyr provided in a comment:
I tried the same codepen on Windows and it shows the number perfectly centered.
I think this is not a flex-box issue, but something to do with the line-height.
One way to overcome this is to adjust line-height manually by experimenting a bit like so:
.cell {
/* Square definition */
width: 100px;
height: 100px;
border: 1px solid black;
font-size: 2rem;
/* Centering */
display: flex;
justify-content: center;
line-height:6.7rem;
color: white;
background: radial-gradient(ellipse at center, red 0%,red 50%, transparent 55%);
}
<div class="cell">75</div>
I made a website using an HTML5 template and adjusting it. Everything worked fine so far (apart from probably having messy files).
Now, my issue:
I am using a parallax background image inside a section-element, and it is not responsive on mobile. If I resize my browser window, it works fine. But if I look at the actual size on my smartphone screen, it's not working.
This is the code I used in my CSS-file. I tried to do it with code that I found in this community and merged it with what was already inside the template.
.wrapper.rechtsgebiete {
background-color: #ffffff;
color: rgba(255, 255, 255, 0.75);
padding: 10em 0 6em 0 ;
display: -moz-flex;
display: -webkit-flex;
display: -ms-flex;
display: flex;
-moz-align-items: center;
-webkit-align-items: center;
-ms-align-items: center;
align-items: center;
-moz-justify-content: center;
-webkit-justify-content: center;
-ms-justify-content: center;
justify-content: center;
background-attachment: fixed;
background-color: rgba(51,153,255, 0.80);
background-image: url(../../images/la-rechtsgebiete.jpg);
background-position: top left;
background-size: cover;
border: none;
min-height: 50vh !important;
position: relative;
text-align: center;
width: 100%;
}
This is the HTML-element:
<section id="rechtsgebiete" class="wrapper rechtsgebiete" style="padding-top: 30vh; padding-bottom: 25vh;">
<div class="inner"><center>
<h1 class="font-volkhov2"><span style="color:white;">Services & Rechtsgebiete</span></h1></center>
</div>
</section>
Here you can see the issue; the first header-image works fine, everything else doesn't: http://lexadvice.de/leistungen.html
How can I solve this issue?
I tried changing the position value, but I guess it might have something to do with the width-property. Trial and error did not get me far this time.
I solved the issue with setting the background on scroll. Now the images are displaying correctly on iPhone.
background-attachment: scroll;
Thanks for your help #Akash Shrivastava.
One of the media style rules is overriding the background-attachment: fixed; in file: leistungen-banner.css
#media screen and (max-width: 1280px)
#banner {
padding: 6em 0 3em 0;
background-attachment: scroll;
}
}
that's why its not working on mobile. Please fix that.
Alternatively you can add and inline rule background-attachment:fixed to your #banner element.
Refer below screenshot (taken from chrome dev tools):
I was looking for a solution to make my opening background image to be 100% of the viewport and after using Josh powel''s answer here Page height to 100% of viewport? it works on chrome on mac but not on any other browser (on mac or windows) When I say 'it works on chrome on mac', it works in most instances however if I stretch the browser too high, it doesn't fit to cover and I see my next bit of content so it's like it only works for heights up to x...
here's my code:
<section class="intro">
<div class="intro-body">
</div>
</section>
.intro {
display: table;
width: 100%;
height: 100%;
padding: 350px 0 330px;
text-align: center;
color: #fff;
position: relative;
background: url(http://www.wallsave.com/wallpapers/1920x1200/plain-blue-gradient/2567400/plain-blue-gradient-pc-mac-hd-2567400.jpg) no-repeat center;
background-size:cover;
}
.intro-page {
padding: 150px 0 130px;
background: url(http://www.wallsave.com/wallpapers/1920x1200/plain-blue-gradient/2567400/plain-blue-gradient-pc-mac-hd-2567400.jpg) no-repeat center;
background-size: cover;
}
function windowH() {
var wH = $(window).height();
$('.intro, .intro-page').css({height: wH});
}
Fiddle here http://jsfiddle.net/9h98f/1/
If anyone can shed any light, that'd be great.
In order to make an element 100% height of the page, you must also have:
html,body { height: 100%; min-height: 100%; }
It's much better and more reliably to do this in CSS than by using JS.
Alternatively, you could just put the background image on the body (with background-size: cover like you are using).