Hello I have a parent with positon absolut and height: self that is not with the height of children like this:
css:
const UserProfile = styled.div`
display: flex;
justify-content: center;
align-items: center;
padding: 0 0.5rem;
cursor: pointer;
position: relative;
& .user_text {
cursor: pointer;
display: flex !important;
flex-direction: column;
padding-right: 0.75rem !important;
span:first-of-type {
font-size: 1rem;
color: #b5b5c3 !important;
font-weight: 500 !important;
text-align: right !important;
}
span:last-of-type {
font-size: 1rem;
color: #464e5f !important;
font-weight: 600 !important;
text-align: right !important;
}
}
& .user_avatar {
border-radius: 50%;
flex-shrink: 0;
position: relative;
transition: border-color 0.2s;
width: 45px;
z-index: 1;
img {
min-height: 100%;
object-fit: cover;
-o-object-fit: cover;
width: 100%;
}
}
`;
const UserCanvas = styled.div`
position: absolute;
min-width: 10rem;
display: ${props => (props.isOpen ? "block" : "none")};
border: 1px solid rgba(0, 0, 0, 0.15);
border-color: rgba(120, 130, 140, 0.13);
box-shadow: 0 3px 12px rgba(0, 0, 0, 0.05);
top: 100%;
bottom: 0;
font-size: 1rem;
color: #212529;
background-color: #fff;
background-clip: padding-box;
border-radius: 0.25rem;
& .test {
min-width: 10rem;
height: 200px;
}
`;
jsx:
<UserProfile onClick={() => setOpen(!isOpen)}>
<div className="user_text">
<span>SpiriT</span>
<span>Web Developer</span>
</div>
<div className="user_avatar">
<img src={LogoImage} />
</div>
<UserCanvas isOpen={isOpen}>
<div className="test">a</div>
</UserCanvas>
</UserProfile>
example:
https://codesandbox.io/s/youthful-hooks-ceo85?file=/src/App.js:743-2099
basically i need the div with position absolute and height auto to follow the height of yours children
Change the display to table for the parent component and table-row t like this:
const UserCanvas = styled.div`
// ... other properties
display: ${props => (props.isOpen ? "table" : "none")};
& .test {
min-width: 10rem;
height: auto;
display: table-row;
}
`;
Alternately, you can add height: max-content; to the Parent Component.
Related
I'm sure the answer is right in front of me, but I have searched and searched for hours and have been unable to come up with a fix. I am wondering how to have my background image fill the whole screen. It fills most of the screen, except where the header would be. I can get the full screen background image, only when I comment out the "Form" component. When I go to inspect the portion that is not filled, it says it shows as html, which I suspect is pulled from the index.html file in the public folder. I would greatly appreciate any and all help on this.
App.js
import React from 'react';
import './App.css';
import Form from './Form';
import wallstreet from './images/wallstreet.png';
function App() {
return (
<div className="App">
<div className="overlay"
style={{backgroundImage: `url(${wallstreet})`}} />
<Form />
</div>
);
}
export default App;
App.css
#import url('https://fonts.googleapis.com/css2?family=PT+Sans&display=swap');
* {
box-sizing: border-box;
margin: 0;
padding: 0;
font-family: 'PT Sans', sans-serif;
}
.overlay {
position: fixed;
min-width: 100%;
min-height: 100%;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
Form.js
import React, { useState } from 'react';
import FormSignup from './FormSignup';
import FormSuccess from './FormSuccess';
import './Form.css';
const Form = () => {
const [isSubmitted, setIsSubmitted] = useState(false)
function submitForm() {
setIsSubmitted(true);
}
return (
<>
<div className="form-container">
<span className="close-btn">x</span>
<div className="form-content-left">
<img className='form-img' src='images/bullish.png' alt='bullish' />
</div>
{!isSubmitted ? (<FormSignup submitForm=
{submitForm} />) : <FormSuccess />}
</div>
</>
);
};
export default Form;
Form.css
.form-container {
margin: 100px auto;
width: 1000px;
box-shadow: 0 5px 8px 0 rgba(0, 0, 0, 0.2), 0 7px 20px 0 rgba(0, 0, 0, 0.2);
position: relative;
border-radius: 10px;
height: 600px;
display: grid;
grid-template-columns: 1fr 1fr;
}
.close-btn {
position: absolute;
top: 2%;
right: 3%;
font-size: 1.5rem;
z-index: 1;
color: #fff;
cursor: pointer;
}
.form-content-left {
background: linear-gradient(
90deg,
rgb(39, 176, 255) 0%,
rgb(0, 232, 236) 100%
);
border-radius: 10px 0 0 10px;
position: relative;
}
.form-img {
width: 80%;
height: 80%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.form-img-2 {
width: 60%;
height: 60%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.form-success {
text-align: center;
font-size: 24px;
margin-top: 80px;
color: #fff;
}
.form-content-right {
border-radius: 0 10px 10px 0;
position: relative;
background: linear-gradient(90deg, rgb(40, 40, 40) 0%, rgb(17, 17, 17) 100%);
}
.form {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 90%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.form h1 {
font-size: 1rem;
text-align: start;
width: 80%;
margin-bottom: 1rem;
color: #fff;
}
.form-inputs {
margin-bottom: 0.5rem;
width: 80%;
}
.form-inputs p {
font-size: 0.8rem;
margin-top: 0.5rem;
color: #f00e0e;
}
.form-label {
display: inline-block;
font-size: 0.8rem;
margin-bottom: 6px;
color: #fff;
}
.form-input {
display: block;
padding-left: 10px;
outline: none;
border-radius: 2px;
height: 40px;
width: 100%;
border: none;
}
.form-input::placeholder {
color: #595959;
font-size: 12px;
}
.form-input-btn {
width: 80%;
height: 50px;
margin-top: 10px;
border-radius: 2px;
background: linear-gradient(
90deg,
rgb(39, 176, 255) 0%,
rgb(0, 232, 236) 100%
);
outline: none;
border: none;
color: #fff;
font-size: 1rem;
}
.form-input-btn:hover {
cursor: pointer;
background: linear-gradient(
90deg,
rgb(39, 143, 255) 0%,
rgb(12, 99, 250) 100%
);
transition: all 0.4s ease-out;
}
.form-input-login {
font-size: 0.8rem;
margin-top: 10px;
color: #fff;
width: 80%;
text-align: center;
}
.form-input-login a {
text-decoration: none;
color: #27cdff;
font-weight: 6
00;
}
Did you try 100vh and 100vw along with position absolute.
also search if any of the parent element is having relative position
hey guys I have 3 elements I'm using z-index and position property.
the first one is the main navbar (working fine)
the 2nd is sidenav
the 3rd is a button.
the button must have the position relative.
when I'm scrolling the main navbar is taking over the button which is great !
but the side navbar is not.
I did try to change the z-index on each element.
the mobile navbar is the main navbar which working fine.
.mobile-navbar {
background-color: rgb(0, 0, 0);
position: fixed;
z-index: 1;
width: 100%;
display: flex;
justify-content: space-between;
img {
background-color: rgba(0, 0, 0, 0.274);
}
div {
display: flex;
justify-content: center;
align-items: center;
a {
font-size: 2rem;
color: #fff;
margin: 5px;
text-decoration: none;
span {
background-color: red;
border-radius: 10px;
padding: 0 3px;
}
}
}
}
.side-nav {
position: fixed;
z-index: 0;
width: 100%;
height: 100vh;
transform: translateX(-100%);
transition: 300ms ease-out;
&-active {
position: fixed;
width: 100%;
height: 100vh;
background-color: rgb(12, 6, 39);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
transform: translateX(0);
transition: 300ms ease-out;
button.close-nav {
padding: 5px;
background-color: rgb(14, 12, 12);
color: #fff;
border: none;
font-size: 2rem;
font-weight: 700;
}
.dynamic-links {
height: 30%;
button {
padding: 5px;
font-size: 2rem;
background: rgba(0, 0, 0, 0);
color: #fff;
border: none;
}
.sidenav-link {
color: #fff;
text-decoration: none;
font-size: 2rem;
margin: 0 10px;
}
}
.sidenav-links {
display: flex;
flex-direction: column;
height: 50%;
.sidnav-link {
color: #fff;
margin: 10px 0;
font-size: 2rem;
text-decoration: none;
text-align: center;
}
}
}
}
the button I need to use position relative and taking over the side-navbar:
button {
position: relative;
z-index: 0;
cursor: pointer;
font-size: 1.3rem;
padding: 10px 15px;
border: none;
outline: #06a821;
border-radius: 30px;
color: #fff;
letter-spacing: 0.3rem;
background: linear-gradient(
90deg,
rgba(5, 116, 197, 1) 35%,
rgba(106, 183, 239, 1) 100%
);
transition: ease-in-out 300ms;
&::before {
position: absolute;
border: 1px solid #fff;
left: 5px;
right: 5px;
top: 5px;
bottom: 5px;
border-radius: 30px;
content: "";
}
only had to add the z-index in the active class.
befor :
.side-nav {
position: fixed;
z-index: 0;
width: 100%;
height: 100vh;
transform: translateX(-100%);
transition: 300ms ease-out;
&-active {
position: fixed;
width: 100%;
height: 100vh;
background-color: rgb(12, 6, 39);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
transform: translateX(0);
transition: 300ms ease-out
after:
.side-nav {
position: fixed;
width: 100%;
height: 100vh;
transform: translateX(-100%);
transition: 300ms ease-out;
&-active {
position: fixed;
z-index: 1;
width: 100%;
height: 100vh;
background-color: rgb(12, 6, 39);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
transform: translateX(0);
transition: 300ms ease-out;
So i making shop and i want to styling the image.
Right now i don't see the faces in the div:
I know it's little thing,but i can't make this happen:
Menu-item component:
import React from "react";
import "./menu-item.styles.scss";
const MenuItem = ({ title, imageUrl, size }) => (
<div className={`${size} menu-item`}>
<div
className="img"
style={{
backgroundImage: `url(${imageUrl})`
}}
/>
<div className="content">
<h1 className="title">{title}</h1>
</div>
</div>
);
export default MenuItem;
Menu-item styling:
.menu-item {
min-width: 30%;
height: 240px;
flex: 1 1 auto;
display: flex;
align-items: center;
justify-content: center;
border: 1px solid black;
margin: 0 7.5px 10px;
border-radius: 10px;
.img {
width: 100%;
height: 100%;
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
position: relative;
right: 0px;
border-radius: 10px;
}
&:hover {
.title {
transition: ease-in 0.6s;
opacity: 1;
cursor: pointer;
}
}
&.small-sneakers {
background-position: center;
}
&.large {
height: 420px;
}
&:first-child {
margin-right: 7.5px;
}
&:last-child {
margin-left: 7.5px;
}
.content {
display: flex;
align-items: center;
justify-content: center;
position: absolute;
}
.title {
font-weight: bold;
margin-bottom: 6px;
font-size: 22px;
color: white;
text-transform: uppercase;
align-items: center;
opacity: 0;
z-index: 3;
position: absolute;
}
}
When i try to do background-position: top -50px center,then the image not responsive :/
Thanks for the help!
When you are using background-position: top -50px center you will break the intention of background-size: cover; because it (cover) will determine whether to "crop" the image horizontally or vertically based on the size of the image, so if the cropping is happening on the sides, 50px of the top of the image will be outside of its container.
You can manipulate the wanted behavour by setting overflow:hidden on the parent, set a negative margin to the top of the child, and setting the height of the child to 100% + [margin-top value] using calc.
example code on code pen here
.menu-item
min-width: 30%;
height: 240px;
flex: 1 1 auto;
display: flex;
align-items: center;
justify-content: center;
border: 1px solid black;
margin: 0 7.5px 10px;
border-radius: 10px;
overflow: hidden;
}
.img {
margin-top: -50px;
width: 100%;
height: calc(100% + 50px);
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
background-image: url(https://image.cnbcfm.com/api/v1/image/106069136-1565284193572gettyimages-1142580869.jpeg?v=1576531407&w=1400&h=950);
}
Hello I have a daughter div that is passing the full width of the parent div for some reason I still can't find the solution:
like this:
for some reason instead of skipping paragraph it is always horizontal I've tried everything and found no solution.
code:
<Styled.ChatBox>
<Styled.ChatLog>
<Styled.MessageWrapper user={true}>
<Styled.ChatMessage user={true}>{props.children}</Styled.ChatMessage>
</Styled.MessageWrapper>
</Styled.ChatLog>
</Styled.ChatBox>
css:
const messageBot = css`
align-self: flex-start;
background-color: #e0e0e0;
color: black;
border-radius: 8px;
padding: 10px 10px 10px 15px;
font-size: 15px;
font-family: sans-serif;
`;
const messageClient = css`
align-self: flex-end;
background-color: #1a6fe8;
color: white;
border-radius: 8px;
padding: 10px 10px 10px 15px;
font-size: 15px;
font-family: sans-serif;
`;
const ChatBox = styled.div`
display: ${props => (props.widget ? 'none' : 'flex')};
position: absolute;
position: fixed;
right: 20px;
bottom: 20px;
flex-direction: column;
max-width: 22em;
width: 100%;
height: 30em;
border-radius: 6px;
box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 10px 2px;
background: ${props => (props.widget ? 'red' : 'blue')};
`;
const ChatLog = styled.div`
display: flex;
flex-direction: column;
max-height: 400px;
width: 100%;
overflow-y: auto;
flex: 1 100%;
background: red;
padding: 10px 10px 0px 10px;
box-sizing: border-box;
`;
const MessageWrapper = styled.div`
background: yellow;
display: flex;
align-items: center;
flex-direction: row;
box-sizing: border-box;
width: 100%;
justify-content: ${props => (props.user ? 'flex-end' : 'flex-start')};
`;
const ChatMessage = styled.div`
position: relative;
margin: 1ex;
padding: 1ex;
border-radius: 2px;
:before {
content: '';
position: absolute;
top: 50%;
right: ${props => (props.user ? '-5px' : '')};
left: ${props => (props.user ? '' : '1px')};
height: 15px;
width: 15px;
background: ${props => (props.user ? '#1a6fe8' : '#e0e0e0')};
transform: rotate(45deg);
transform-origin: top right;
}
${props => (props.user ? messageClient : messageBot)}
`;
I know that my div that is passing the size is ChatMessage
I believe she is the problem
img:
example on:
https://codesandbox.io/s/cool-water-1dwqx
You need to handle the overflow of the element.
const ChatMessage = styled.div`
...
overflow: hidden;
word-break: break-all;
`;
I must be misunderstaning something in CSS as my dropdown box using a library (dat-gui) is doing this:
I have tried switching to position: absolute for the divs beneath the dat-gui container, which breaks the divs beneath it.
Funnily enough, when I use the SO embedded snippet, it actually works. So check out an actual deploy of the site at: https://stack-test.netlify.com/
function UI (parentDiv) {
// parentDiv.querySelector('#dataset_div').style.display = 'none'
// parentDiv.querySelector('#channel_div').style.display = 'none'
// parentDiv.querySelector('#OpenCORLinkButton').style.display = 'none'
// parentDiv.querySelector('#instructions_div').style.display = 'none'
var _this = this
_this.dataType = 'scatter'
const gui = new dat.GUI({autoPlace: false})
gui.domElement.id = 'gui'
gui.close()
document.getElementsByClassName('dat-gui-container')[0].appendChild(gui.domElement)
var folder = gui.addFolder('Channels')
var settings = {}
var checkboxes = []
var checkboxElements = []
this.createDatGuiDropdown = function (channels, onchangeFunc) {
_this.channels = [...channels]
if (channels[0].toLowerCase().includes('time')){
channels.shift()
}
checkboxes = []
for (let i in _this.channels) {
let name = _this.channels[i]
let checkbox = {}
checkbox[name] = false
checkboxes.push(checkbox)
var el = folder.add(checkboxes[i], name)
checkboxElements.push(el)
el.__checkbox.onclick = onchangeFunc
}
folder.open()
}
}
var ui = new UI('unused')
ui.createDatGuiDropdown(['one', 'two'], function(){console.log('clicked')})
/*//////////////////////////////////////////////////////////////////
[ dat-gui ]*/
.dat-gui-container{
position: absolute;
top: 0;
left: 0;
right: 0;
height: 95%;
z-index: 5;
}
/*//////////////////////////////////////////////////////////////////
[ login ]*/
.limiter {
width: 100%;
margin: 0 auto;
}
.container-login100 {
width: 100%;
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
padding: 10px;
position: relative;
background-position: center;
background-size: cover;
background-repeat: no-repeat;;
}
.wrap-login100 {
width: 390px;;
background: #fff;
border-radius: 10px;
position: relative;
}
.wrap-data100 {
width: 90%;
background: #fff;
border-radius: 10px;
position: relative;
}
/*==================================================================
[ Form ]*/
.login100-form {
width: 100%;
}
.login100-form-title {
font-family: Ubuntu-Bold;
font-size: 30px;
color: #403866;
line-height: 1.2;
text-transform: uppercase;
text-align: center;
width: 100%;
display: block;
}
/*==================================================================
[ Restyle Select2 ]*/
.select2-container {
display: block;
max-width: 100% !important;
width: auto !important;
}
.select2-container .select2-selection--single {
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
align-items: center;
background-color: rgba(171, 171, 189, 0.233);
border: none;
height: 40px;
outline: none;
position: relative;
left: -40px;
}
/*------------------------------------------------------------------
[ in select ]*/
.select2-container .select2-selection--single .select2-selection__rendered {
font-family: Ubuntu-Bold;
font-size: 18px;
color: #555555;
line-height: 1.2;
padding-left: 0px ;
background-color: transparent;
}
.select2-container--default .select2-selection--single .select2-selection__arrow {
height: 100%;
top: 50%;
transform: translateY(-50%);
right: 0px;
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
align-items: center;
justify-content: flex-end;
}
.select2-selection__arrow b {
display: none;
font-family: Material-Design-Iconic-Font !important;
font-size: 18px;
color: #555555;
}
.select2-selection__arrow {
content: '\f312';
font-family: Material-Design-Iconic-Font !important;
font-size: 18px;
color: #555555;
}
/*------------------------------------------------------------------
[ Dropdown option ]*/
.select2-container--open .select2-dropdown {
z-index: 1251;
width: calc(100% + 2px);
border: 0px solid transparent;
border-radius: 10px;
overflow: hidden;
background-color: rgba(171, 171, 189, 1);
left: -40px;
box-shadow: 0 3px 10px 0px rgba(0, 0, 0, 0.2);
-moz-box-shadow: 0 3px 10px 0px rgba(0, 0, 0, 0.2);
-webkit-box-shadow: 0 3px 10px 0px rgba(0, 0, 0, 0.2);
-o-box-shadow: 0 3px 10px 0px rgba(0, 0, 0, 0.2);
-ms-box-shadow: 0 3px 10px 0px rgba(0, 0, 0, 0.2);
}
#media (max-width: 576px) {
.select2-container--open .select2-dropdown {
left: -12px;
}
}
.select2-dropdown--above {top: -38px;}
.select2-dropdown--below {top: 10px;}
.select2-container .select2-results__option[aria-selected] {
padding-top: 10px;
padding-bottom: 10px;
padding-left: 24px;
}
#media (max-width: 576px) {
.select2-container .select2-results__option[aria-selected] {
padding-left: 12px;
}
}
.select2-container .select2-results__option[aria-selected="true"] {
background: #403866;
color: white;
}
.select2-container .select2-results__option--highlighted[aria-selected] {
background: #827ffe;
color: white;
}
.select2-results__options {
font-family: Ubuntu-Bold;
font-size: 14px;
color: #555555;
line-height: 1.2;
}
.select2-search--dropdown .select2-search__field {
border: 1px solid #aaa;
outline: none;
font-family: Ubuntu-Bold;
font-size: 15px;
color: #333333;
line-height: 1.2;
}
.wrap-input100 .dropDownSelect2 .select2-container--open {
width: 100% !important;
}
.wrap-input100 .dropDownSelect2 .select2-dropdown {
width: calc(100% + 2px) !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.6/dat.gui.js"></script>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Blackfynn Exporter</title>
<meta charset="UTF-8">
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
<div id='blackfynn-panel' style="position: relative;">
<div class="dat-gui-container"></div>
<div class="container-login100 datasetUI" id="dataset_div">
<div class="wrap-data100 p-t-5 p-b-5 datasetUI">
<form class="contact100-form validate-form">
<span class="login100-form-title">
Data Viewer
</span>
<div class=" input100 wrap-input100 input100-select bg1 datasetUI">
<span class="label-input100"></span>
<div id="channel_div">
<select class="js-select2" name="service" id="select_channel">
<option>Channel Selection</option>
</select>
<div class="dropDownSelect2"></div>
</div>
</div>
</form>
<br>
<div id="exportURL">
</div>
</div>
</div>
<div class="datasetUI" id="chart_div"></div>
</div>
</body>
</html>
If you have a look at the snippet you see that .dat-gui-container has position: absolute set. In your case you have to set position absolute to the element that gets animated, thus preventing the rest of the elements from moving around.