I'm trying to add a background image behind my Form component in a react App, but the background shows up only on part of the screen. I want it to be spread across the entire screen. This is the code for my Signup component that nests the Form component inside of it.
Is there an easier/better way to do this? I am new to React and web development. Thanks!
import React from "react";
import Form from "../Form";
import logo from "../../images/logo.png";
import background from "../../images/login_background.png";
class Signup extends React.Component {
onSubmit = fields => {
console.log("Got", fields);
};
render() {
return (
<div
style={{
backgroundImage: `url(${background})`,
backgroundSize: "cover"
}}
>
<div
style={{ position: "relative", top: "200px" }}
className="ui centered aligned grid"
>
<div>{/* <img src={logo} alt="intecreate logo" /> */}</div>
<div className="ui raised segment">
<Form onSubmit={fields => this.onSubmit(fields)} />
</div>
</div>
</div>
);
}
}
export default Signup;
Give more 200px to the background
Because you use top: 200px you have to make up for it and increase the div of the background.
One way is to add height: calc(100% + 200px);
It will help to get a work link in codepen for instance.
And better you use class and not inline style for the beginning :)
After comment adding example
Simple example that show what I mean.
The father must have height.
body{
margin: 0;
}
.centered{
text-align: center;
height: 200px;
}
.wrap{
background-image:url(https://images.pexels.com/photos/255379/pexels-photo-255379.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500);
background-size: cover;
height: calc(100% + 50px);
}
.segment{
background-color: #3791e1;
height: 200px;
width: 150px;
top: 50px;
position: relative;
margin: 0 auto;
}
<div class="ui centered aligned grid">
<div class="wrap">
<div class="ui raised segment">
Form
</div>
</div>
</div>
Related
I have a background image that is not staying within its div and will overflow into other contents. The background image div is on the same z-index and is nested within the background gradient div which contains the navbar and CTA section. I have tried just adding the background image to the same css class as the background gradient, but that has caused other issues to arise since I cannot resize it to how large it is supposed to be so I am just using the method I stated above. Can someone please help me with this? link to code sandbox is here codesandbox
what its doing:
what it needs to look like:
code below:
import styles from './style';
import { Navbar, CTA, BodyTop, BodyBottom, BodyMiddle, Footer } from './components';
const App = () => (
<div className='w-full overflow-hidden'>
<div className='bg-cta-gradient z-[0] h-[450px]'>
<div className={`flex-col h-[450px] relative overflow-hidden ${styles.paddingX} ${styles.flexCenter}`}>
<div className="background-img z-[-0] absolute overflow-hidden "></div>
<div className={`mt-5 margin-bottom absolute z-[2] ${styles.boxWidth}`}>
<Navbar />
</div>
<div className={`z-[0] ${styles.boxWidth}`}>
<CTA />
</div>
</div>
</div>
<div className={`bg-bodyColor z-[2] ${styles.flexStart}`}>
<div className={`${styles.boxWidth}`}>
<BodyTop />
<BodyMiddle />
<BodyBottom />
<Footer />
</div>
</div>
</div>
);
export default App;
code for css:
#media screen and (max-width: 760px) {
.bg-cta-gradient {
background: linear-gradient(hsl(13, 100%, 72%), hsl(353, 100%, 62%));
border-radius: 0px 0px 0px 70px;
}
.background-img {
background-image: url('./assets/bg-pattern-intro-mobile.svg') !important;
background-repeat: no-repeat;
background-size: contain;
width: 1300px;
height: 1300px;
overflow: hidden;
margin-left: 200px;
margin-top: 250px;
}
It seems that the container of this section is not having a border radius matching the shape of the left bottom corner.
That mismatched corner is causing the background image to overflow when on a smaller screen width.
Here is a quick fix that could be tried for this issue: (live demo: codesandbox)
Add a fix class to the CSS in index.css:
/* if it works, change the class name to a proper one later */
.fix-bg-img {
border-radius: 0px 0px 0px 70px;
}
Add the fix class to the said container in App.jsx:
import styles from "./style";
import {
Navbar,
CTA,
BodyTop,
BodyBottom,
BodyMiddle,
Footer,
} from "./components";
const App = () => (
<div className="w-full overflow-hidden">
<div className="bg-cta-gradient z-[0] h-[450px]">
<div
// Add the fix here 👇
className={`fix-bg-img flex-col h-[450px] relative overflow-hidden ${styles.paddingX} ${styles.flexCenter}`}
>
<div className="background-img z-[-0] absolute overflow-hidden "></div>
<div className={`mt-5 margin-bottom absolute z-[2] ${styles.boxWidth}`}>
<Navbar />
</div>
<div className={`z-[0] ${styles.boxWidth}`}>
<CTA />
</div>
</div>
</div>
<div className={`bg-bodyColor z-[2] ${styles.flexStart}`}>
<div className={`${styles.boxWidth}`}>
<BodyTop />
<BodyMiddle />
<BodyBottom />
<Footer />
</div>
</div>
</div>
);
export default App;
Hope this will help.
I'm building carousel with react, and content images are horizontally aligned.
If I say 3 tags are in div with width 1200px, how can I control these images what I want whether it's overflow container div or not? ( cf. It's not important, however I'm using React.js)
sorry for skipping my codes so far. I'm trying to handle this with styled-components"
const SliderContainer = styled.div`
overflow: hidden;
width: 100%;
position:relative;
`;
const Slider = styled.div`
width:100%;
overflow:hidden;
display: flex;
`
const IMG = styled.img`
width: 100%;
height: 70vh;
`;
export const Slide: SFC<{
src?: string,
alt?: string
}> =({
src,
alt
}) => {
return(
<IMG src={src} alt={alt}/>
)
}
export const Carousel: FC = () => {
return(
<SliderContainer>
<Slider>
<Slide src={"1.png"}/>
<Slide src={"2.png"}/>
<Slide src={"3.png"}/>
</Slider>
</SliderContainer>
)
<div class="parent">
<div class="container">
<img id="img1" />
<img id="img2" />
<img id="img3" />
</div>
</div>
when we want those images( or contents) in div which has container as a classname over flow <div class="parent"></div>
we should specify the length of <div class="container"></div>
so in this case
.parent{
width: 100%;
overflow;
}
.container{
display: flex; // so we have 3 images horizontally
width: 1028px; // whatever but more than .parent widh
}
.img{
width:100%;
height: auto;
}
the reason we should specify .container div width is, we have flex display in this case, so whole img width might be auto resize through this flex properties.
and .parent's overflow: hidden property only make sense when it's child tag has large length more than itself.
I have a splitted layout, like you can see in the following example screens. By default the fixed app vue content takes 40% of the interface left and the router view 60% on the right.
Now the problem: one of the components, in this example router link 3 should be fullscreen. I don't know how the router component can overlap the app vue. It's always beneath it.
router link 1:
router link 2:
router link 3:
Here is my current code
app.vue:
<template>
<div class="left">
<router-link to="/link1">
<router-link to="/link2">
<router-link to="/link3">
</div>
// some content
<router-view></router-view>
</template>
<style>
.left {
width: 40%;
position: fixed;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
</style>
component 1 and 2:
<template>
<div class="container">
// same content
</div>
</template>
<style>
.container {
display: inline-block;
margin-left: 40%;
width: 60%;
height: 100vh;
}
</style>
component 3:
<template>
<div class="container">
// same content
</div>
</template>
<style>
.container {
display: inline-block;
width: 100%;
height: 100vh;
}
</style>
You can use "position: absolute" on the style for the component3. You can also give it a higher z-index to make it appear on top. For example:
<template>
<div class="container">
// same content
</div>
</template>
<style>
.container {
display: inline-block;
position: absolute;
z-index: 100;
width: 100%;
height: 100vh;
}
</style>
You should also be able to use v-bind class to apply a class to a component already displayed on the page. That would give a similar result to what you see in WYSIWYG editors full page option.
Ok, so this is a simple css question, but I can't seem to find a straight answer on the web to save my life. I've got this set up:
<div id="app">
<div id="header_div"></div>
<div id="menu_div"></div>
<div id="content_div"></div>
</div>
and then some css:
#mixin relPos {
position: relative;
margin-top: 5px;
width: 100%;
}
/*** App level ***/
#app {
position: absolute;
word-wrap: break-word;
height: 100%;
width: 100%;
}
/*** Landing Page ***/
#header_div {
#include blackBorder;
#include relPos;
left: 0;
height: 30%;
}
#menu_div {
#include blackBorder;
#include relPos;
height: 10%;
}
#content_div {
#include blackBorder;
#include relPos;
height: 56%;
overflow: scroll;
}
but the dang divs are not responding to the percentage height style element... any ideas?
For context, I'm building a React.js site so I'm actually using scss files for my styling elements after rending them with React elements. Pretty sure that doesn't matter but just because I don't actually know everything, I'll mention that here. :) Thanks in advance for any help!
- Jon
#top {
position:absolute;
top:0;
left:0;
height: 100%;
width: 100%;
}
#one {
position:relative;
margin-top:1%;
height: 30%;
width: 100%;
background-color:red;
}
#two {
position:relative;
margin-top:1%;
height: 10%;
width: 100%;
background-color:green;
}
#three {
position:relative;
margin-top:1%;
height: 57%; /* not 60% to account for the 5px margin */
width: 100%;
background-color:blue;
}
<div id="top">
<div id="one"></div>
<div id="two"></div>
<div id="three"></div>
</div>
Instead of using multiple position: relative; use the float: property across for cleaner code.
You can achieve this cleanly with 3 float:left;. Keep the parent div position:relative; and the 3 inner, float:left;. Nest another div around all these elements with your position:absolute; if still necessary.
So here's my React code:
import React from 'react';
import ReactDOM from 'react-dom';
class LandingPage extends React.Component
{
render()
{
return(
<div>
<div id="header_div">
<h1> Header picture goes here </h1>
</div>
<div id="menu_div">
<h2> here's for the menu buttons </h2>
</div>
<div id="content_div">
<h3> and... the content to be loaded based on first load or menu button mash </h3>
</div>
</div>
);
}
};
export default LandingPage;
And because I'm using react elements, I had to return one div with the three I'm trying to style in it for my LandingPage element... so my structure was actually ... and so on. Because of this, the container div was not app and there for it didn't matter if I did my styling on app, I needed to do it on the other div in the middle. I added a id="main" to the middle div and styled it as I had my #app styled... Once I did, it was all good! Thanks guys!
I would like to vertical align my jumbotron on the screen when the user navigates to it no matter what the screen size, I would then like to be able to scroll down and it not move with the screen
I would like to use inline styles if possible
<div class="jumbotron text-center">
<h1>Search Form Here</h1>
</div>
You can do this without jQuery. First put the jumbotron in a wrapper:
<div class="wrapper">
<div class="jumbotron text-center">
<h1>Search Form Here</h1>
</div>
</div>
Then make the wrapper the full height of the viewport using vh units:
.wrapper {
position: relative;
height: 100vh;
}
Finally, use absolute positioning and transforms to center the jumbotron:
.jumbotron {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
You can make the jumbotron and height and width you want, and it will always be centered in the container. All of these styles could be inline, just move them to style attributes on their respective DIVs. The values never need to change.
I solved this issue using CSS Flexbox. No Javascript or jQuery.
Here's my code, I added the class vertical-center and then in the CSS file -
.vertical-center {
min-height: 100%;
min-height: 100vh;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
You can see an example of this at - http://codepen.io/jjmax/full/avdVBE
You could use jQuery for this which, incidentally, creates inline CSS.
Your HTML plus a containing div:
<div class="wrapper">
<div class="jumbotron text-center">
<h1>Search Form Here</h1>
</div>
</div>
A jQuery function:
function myJumbotron() {
var winHeight = $(window).height();
// make wrapper div whole height of window
$('.wrapper').css({
height: winHeight
});
// make jumbotron be in the middle vertically
$('.jumbotron').css({
marginTop: (winHeight / 2) + 'px'
});
}
Call function on document ready:
$(document).ready(function() {
myJumbotron();
});