I'm Transferring some design to a web page, but I can't seem to get the background image to show. I've checked various solutions online and they keep telling me to add the 'background-image' property, which I have done. Yet it doesn't work. I've pasted the code below. I apologise if it's a very obvious mistake as I'm not quite familiar with CSS.
Could someone please point out where my mistake is?
import React from "react";
import styled from "styled-components";
// Assets
import HeaderImage from "../../assets/img/covlie_homepage_illustration.png";
export default function Header() {
return (
<Wrapper id="home" className="container flexSpaceCenter">
<LeftSide className="flexCenter">
<div>
<h1 className="extraBold font60">Some Text</h1>
<HeaderP className="font13 semiBold">
Some Text
</HeaderP>
</div>
</LeftSide>
<RightSide>
<ImageWrapper>
<Img className="radius8" src={HeaderImage} alt="office" style={{zIndex: 9}} />
</ImageWrapper>
<GreyDiv className="lightBg"></GreyDiv>
</RightSide>
</Wrapper>
);
}
const Wrapper = styled.section`
padding-top: 80px;
width: 100%;
min-height: 840px;
background-image: transparent url('../../assets/img/page_heade_rbackground_image.png') 0% 0% no-repeat padding-box;
#media (max-width: 960px) {
flex-direction: column;
}
`;
const LeftSide = styled.div`
width: 50%;
height: 100%;
#media (max-width: 960px) {
width: 100%;
order: 2;
margin: 50px 0;
text-align: center;
}
#media (max-width: 560px) {
margin: 80px 0 50px 0;
}
`;
const RightSide = styled.div`
width: 50%;
height: 100%;
#media (max-width: 960px) {
width: 100%;
order: 1;
margin-top: 30px;
}
`;
const HeaderP = styled.div`
max-width: 470px;
padding: 15px 0 50px 0;
line-height: 1.5rem;
#media (max-width: 960px) {
padding: 15px 0 50px 0;
text-align: center;
max-width: 100%;
}
`;
const GreyDiv = styled.div`
width: 30%;
height: 700px;
position: absolute;
top: 0;
right: 0;
z-index: 0;
#media (max-width: 960px) {
display: none;
}
`;
const ImageWrapper = styled.div`
display: flex;
justify-content: flex-end;
position: relative;
z-index: 9;
#media (max-width: 960px) {
width: 100%;
justify-content: center;
}
`;
const Img = styled.img`
#media (max-width: 560px) {
width: 80%;
height: auto;
}
`;
I finally discovered the issue. I'm using styled components, and the implementation for styled components is different. First I should have imported the image
import bgImg from "../../assets/img/page_heade_rbackground_image.png"
Then implemented like this
const Wrapper = styled.section`
padding-top: 80px;
width: 100%;
min-height: 840px;
background-image: url(${bgImg});
#media (max-width: 960px) {
flex-direction: column;
}
`;
Don't know if this will help but the background image is set to transparent.
background-image: transparent url('../
I see that when you figured it out you didn't use transparent :)
Related
I am trying to replace a header content when the screen height decreases by removing a large image I have in a div which is basically a logo and placing it as a little logo in the center at the top of the middle of the page only when the screen height goes from 800px and below.
Below is the code to give you an idea of what the header container looks like.
Header.jsx
import React from 'react'
import './header.css'
import CTA from './CTA'
import Logo from '../../assets/fts_blacks1.png'
import HeaderSocials from './HeaderSocials'
const Header = () => {
return (
<header>
<div className="container header__container">
<h5>Welcome To</h5>
<h1>Favourite Tech Solutions</h1>
<h5 className="text-light">The Digital Interdependence</h5>
<CTA />
<HeaderSocials />
<div className="me">
<img src={Logo} alt="Logo" />
</div>
<a href="#contact" className='scroll_down'>Scroll me</a>
</div>
</header>
)
}
export default Header
header.css
header{
/* height: 100vh; */
padding-top: 7rem;
overflow: hidden;
}
.header__container{
text-align: center;
height: 100%;
position: relative;
}
/* cta section */
.cta{
margin-top: 2.5rem;
display: flex;
gap: 1.2rem;
justify-content: center;
}
/* header socials section */
.header_socials{
display: flex;
flex-direction: column;
align-items: center;
gap: 0.8rem;
position: absolute;
left: 0;
bottom: 3rem;
}
.header_socials::after{
content: "";
width: 1px;
height: 2rem;
background: var(--color-primary);
}
/* header image section */
.me{
background: linear-gradient(var(--color-primary), transparent);
width: 22rem;
height: 30rem;
position: absolute;
left: calc(50% - 11rem);
margin-top: 4rem;
border-radius: 12rem 12rem 0 0;
overflow: hidden;
padding: 7.5rem 2.5rem 1.5rem 4rem;
}
/* scroll section */
.scroll_down{
position: absolute;
right: -2.3rem;
bottom: 5rem;
transform: rotate(90deg);
font-weight: 300;
font-size: 0.9rem;
}
#media screen and (max-width: 600px){
.header_socials,
.scroll_down{
display: none;
}
}
There is nothing in my code to show the media screen height at 800px because I dont know how to go about it that is why I am asking here
As you can see above, the image is in a div tag with className = 'me'
This is the image i want to take off entirely from that position when the screen height reduces and and place it at the top of the <h1> Favourite Tech Solutions</h1>
Could you update your problem to be a bit more precise? You do not seem to have #media screen and (max-width: 800px) in your css to even target the div you want to remove. Also, I would use Class here instead of className.
Once you do, you could have the following:
#media screen and (max-width: 800px) {
.header__container {
display:none;
}
}
I have a div element and I want my image within it to scale to the full width of the parent however for some reason its not taking up the full width. I could use object-fit: cover; but I don't want to crop the image I want it to fill up the space of the parent. Id also like to scale it so it remains a square the whole time so it always scales as an equal square. I am a little confused as to why its not taking up the parents container. It seems to be wanting to keep its aspect ratio but I want it to stretch to the parent container both via its height and width properties.
html:
import React from 'react';
const ThreeGridTeaser = (props) => {
return (
<div className="specific-offer-container mt-0">
<div className="three-grid-teaser-wrapper">
<div className="three-grid-teaser-container">
{props.gridData.map((item, index) => (
<div key={index} className="three-grid-teaser-block">
<div className="three-grid-image-container hidden">
<img src={item.image}
/>
</div>
<div className="product-text-container hidden">
<ul>
<li className="product-title">{item.title}</li>
<li className="product-description">{item.description}</li>
</ul>
</div>
</div>
))}
</div>
</div>
</div>
)
}
export default ThreeGridTeaser;
SASS:
.three-grid-teaser-wrapper {
width: 100%;
height: auto;
display: flex;
justify-content: center;
}
.three-grid-teaser-container {
width: 100%;
justify-content: center;
flex-wrap: wrap;
height: auto;
display: flex;
grid-gap: 20px;
gap: 20px;
#media (max-width: 1199.98px) {
gap: 25px;
}
#media (max-width: 767.98px) {
width: 100%;
}
}
.three-grid-teaser-block {
display: flex;
width: 32%;
height: fit-content;
#media (max-width: 1199.98px) {
width: 48%;
}
#media (max-width: 767.98px) {
width:47%;
}
justify-content: center;
flex-direction: column;
}
.hover-text-underline {
text-decoration: underline;
text-underline-position: under;
}
.three-grid-image-container {
height: 300px;
#media (max-width: 1199.98px) {
height: 350px;
}
#media (max-width: 767.98px) {
height: 180px;
}
width: 100%;
max-width: 100%;
img {
display: block;
max-width: 100%;
max-height: 100%;
width: 100%;
height: 100%;
}
}
.product-text-container {
ul {
margin-top: 10px;
padding: 0;
li:last-child {
padding-top: 5px;
}
li {
list-style: none;
}
}
}
.product-title {
font-family: $terminaDemi;
font-size: 12px;
#media (max-width: 767.98px) {
font-size: 8px;
}
}
.product-description {
font-family: $Montserrat;
font-size: 18px;
#media (max-width: 767.98px) {
font-size: 12px;
}
}
This is because the image has reached its maximum height in relation to the div. I mean, an image 300px wide and 400px high inside a 400px square div, in this case if you put a width of 100% in the image, the maximum that it will reach in its width is 300px, in the case of you don't want to resize it.
DemonstraĆ§Ć£o
Update
'object-fit: contain' makes the image fit in the space it has proportionally available, if you want it to maintain its proportion and fill the entire space, use the 'object-fit: cover'
look at this
https://jsfiddle.net/gxnvuq6s/8/
have you tried looking at the background-size: cover; style? you can then also position your image with background-position: center center;
I am using styled components to style my react project, components are working fine, but for some reason media queries are not applied. Here's a snippet that works when using regular css:
import styled from 'styled-components';
export const Block = styled.div `
margin: 20px;
padding: 10px;
border-radius: 10px;
display: flex;
flex-direction: column;
align-self: center;
background-color: #DAD870;
flex: 1;
min-width: 200px;
height: auto;
transition-duration: 1s;
font-family: sans-serif;
&:hover {
transform: scale(1.1);
}
#media (max-width: 1024px) {
width: 42%;
min-width: 158px;
}
#media (max-width: 480px) {
width: 40%;
min-width: 148px;
}
`;
I don't really use react but it looks like you are trying to use #media inside of an element, I don't think that works, instead try something like:
div{
min-width: 200px;
}
#media (max-width: 1024px) {
div{
width: 42%;
min-width: 158px;
}
}
#media (max-width: 480px) {
div{
width: 40%;
min-width: 148px;
}
}
I don't know how to show you like the way you did it but basically you need to declare it separately, hope it helped.
I am trying to understand how to make a web page which will go in full height and width in asp.net. I know to use width: 100% for the background but I am not understanding how to change the width and height of other buttons, , and other stuff..
I search on google and youtube for that but I am not getting a good tutorial to explain how I should make it.
Should I use jquery or javascript? I'm trying to stay far from those at the moment.
Can any one please give me a simple explanation about this?
Best way to control ui styles, should be CSS.
For example, setting a element to full width and height
.full_width {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
}
.element_inside {
width: 100px;
border: 1px solid red;
}
.button_inside {
width: 125px;
height: 60px;
line-height: 60px;
}
<div class="full_width">
I am full width element
<div class="element_inside">
Low width
</div>
<button class="button_inside">
Button
</button>
<button style="width: 100%;">
Button full width
</button>
</div>
But it uses absolute position.
You could use something like this too.
html {
display: table;
width: 100%;
min-height: 100%;
}
body {
display: table-row;
}
.full_width {
width: 250px;
display: table-cell;
vertical-align: top;
min-height: 100%;
}
.full_width {
border: 1px solid #f00;
}
<div class="full_width">
full width container
</div>
For responsive layout, and different screen different size, you can use following codes:
#media (min-width: 768px) {
.container {
width: 740px;
}
}
#media (min-width: 992px) {
.container {
width: 960px;
}
}
#media (min-width: 1200px) {
.container {
width: 1160px;
}
}
#media (min-width: SCREEN_WIDTH_IN_PIXELS) {
.container { // my element width for this screen
width: 1160px;
}
}
Use different css container class for buttons. For ex;
.body{
width: 100%
}
button {
color: #666;
border-color: #EBEBEB;
background-color: #EBEBEB;
text-align: center;
height:200px;
width:200px;
}
And then use for button,
<button class="button">Button</button>
I want my .container element to be at a width of 100% when it reaches a screen size of 900px. The problem is that I use .container on every page and only want to affect the appearance of .container in the #sub-top div.
the hardest thing is terminology for me but i think this is the closest to what i have the ability to describe.
As you can see below, i am trying to get the .container class to go to 100% rather than 85% when it reaches a screen size of 900px or smaller.
#media
.container{
width: 85%;
height: auto;
}
#sub-top{
background-color: gray;
height: auto;
}
#media (min-width: 900px) {
#sub-top .container {
width: 100% !important;
height: auto;
}
}
<div id="sub-top">
<div class="container">
<div class ="content">
<p> HERE IS CONTENT </p>
</div>
</div>
</div>
Try this instead:
#media screen and (max-width: 900px) {
#sub-top .container {
width: 100%;
height: auto;
}
}
This works:
.container {
width: 85%;
height: auto;
background-color: gray;
}
#sub-top {
height: auto;
}
#media (max-width: 900px) {
#sub-top .container {
width: 100% !important;
height: auto;
}