Header extends over scrollbar when width=100% - html

My problem is with the width of a sticky header. It is extending horizontally over the vertical scrollbar on the right. So if the thumb of the scrollbar is at the top, and under the header, then you can't grab and drag it. Curiously the thumb appears to be on top of the header but if you try to grab and drag it, you will be selecting text rather than moving the scroll position.
Is there a way to fix this header width so that it's wide enough to cover the scrolling text but not so wide that it covers the scrollbar, or a way to put the scrollbar on top of the header?
https://codesandbox.io/s/fragrant-cookies-g9w4c
.App {
font-family: sans-serif;
text-align: center;
}
::-webkit-scrollbar {
width: 40px;
position: fixed;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
/* Track */
::-webkit-scrollbar-track {
box-shadow: inset 0 0 5px grey;
border-radius: 18px;
}
/* Handle */
::-webkit-scrollbar-thumb {
background: red;
border-radius: 18px;
}
/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
background: #b30000;
}
.sticky-heading {
background-color: aqua;
font-weight: bold;
font-size: 22px;
padding-top: 10px;
width: 100%;
position: fixed;
}
.list {
overflow-y: scroll;
-webkit-overflow-scrolling: touch;
padding: 20px;
position: fixed;
background: #fff;
height: 100vh;
width: -webkit-fill-available;
overflow-x: hidden;
}
import React from "react";
import ReactDOM from "react-dom";
import "./styles.css";
function App() {
return (
<div className="App">
<div className="list">
<div>
<div>
<div className="sticky-heading">
This should not cover the scrollbar
</div>
<div>
{Array.from({ length: 300 }, () => {
return (
<div>
this must be covered by the heading when scrolling
<br />
</div>
);
})}
</div>
</div>
</div>
</div>
</div>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

::-webkit-scrollbar {
width: 40px;
}
Given width of scrollbar is 40px & scrollbar present at right side of page , so add right:40px in:
.sticky-heading {
right: 40px; //or 30px whatever you want but more than scrollbar width
}

You can try to use this position: absolute; instead of position: fixed;
.sticky-heading {
background-color: aqua;
font-weight: bold;
font-size: 22px;
padding-top: 10px;
width: 100%;
position: absolute;
}
Is this what you want?

Related

Text in a div crosses its boundaries and text padding not working

I am trying to create a part of my website,
Here is the code:
import React from 'react';
import './stylesheets/BeyondHelloWorld.css';
import BHW from './assets/bhw.png';
function BeyondHelloWorld() {
return (
<div className="mainDiv">
<div className="card">
<div className="cardContainer">
<div style={{height: "100%", display: "block"}}>
<img src={BHW} className="bhwImage"/>
</div>
<div class="bhwText">
<span className="bhwTitle">BeyondHelloWorld</span>
<span className="fadedTitle">Beyond</span>
<span className="bhwDescription">BeyondHelloWorld is a learning community for budding programmers. It is aimed at equipping amateurs with easy knowledge of the tech world through engaging content like New Tech information, tips & tricks & BTS of a developers life!</span>
<span className="bhwDescription">A lot of community problems can be solved using technology. BeyondHelloWorld aims to influence non-programmers into the world of programming.</span>
</div>
</div>
</div>
</div>
)
}
export default BeyondHelloWorld
If you see the span bhwDescription, it is inside bhwText div which is inside cardContainer.
Now I have a picture on the left with classname bhwImage
When the text exceeds the height of this image, the text starts from the left of the cardContainer, but I want it to start from the starting edge of the bhwText.
Example:
But with my code, What it looks like:
What am I doing wrong?
Also, if you notice, the fadedTitle and bhwTitle are not exactly aligned. I want them all to start where the picture starts. But something is going off. Even if I keep the padding/margin same, even then they have different starts.
Here is the css:
.mainDiv {
width: 100%;
padding: 50px;
background-color: #1e3512;
}
.card {
background-color: #1e3512;
box-shadow: 5px 5px 20px 0px rgba(0, 0, 0, 0.48);
padding: 0;
overflow: hidden;
}
.cardContainer {
margin: 0;
padding: 0 20px 0 0;
width: 100%;
}
.bhwImage {
height: 18vh;
object-fit: contain;
margin: 40px;
border: 5px solid #fff;
float: left;
}
.bhwText {
margin-top: 20px;
color: #ffffff;
}
.bhwTitle {
font-size: 3.5rem;
font-weight: 600;
display: block;
margin-bottom: 20px;
}
.fadedTitle {
position: absolute;
top: 25px;
font-size: 150px;
line-height: 75px;
opacity: 0.1;
font-weight: 900;
}
.bhwDescription {
display: block;
margin-bottom: 20px;
font-size: 1.8rem;
font-weight: 500;
word-wrap: break-word;
}
Add display:flex to your .cardContainer class
.cardContainer {
margin: 0;
padding: 0 20px 0 0;
width: 100%;
display: flex;
}
and remove width:100% from .mainDiv class
.mainDiv {
/* width: 100%; */ remove this
padding: 50px;
background-color: #1e3512;
display: flex;
}
Live Demo
The reason why the content runs underneath the image is because its style is float: left;, and your .bhwText class has a width of 100% because it's a block element. div elements are generally display: block; by default. This means .bhwText width is 100% of the parent container by default. The text will fill up space where available in it's container; including below the image.
To fix this issue, add left padding to the .bhwText class. Something like this example here.
.bhwText {
margin-top: 20px;
color: #ffffff;
padding: 0 0 0 200px;
}

How put a text at the center of a div without using "text-align:center"?

Here the demo: https://codesandbox.io/s/priceless-cloud-ommr5
I would my text to go to the center of the div preserving on the way its left alignment.
I have tried:
margin:auto,
flexbox with center justification,
x-centering on absolute positioning:
all theses methods fails.
How can I align my text and preserving the right justification of the text by the way, as in the following image?:
Here the ReactJS' snippet:
import React from "react";
import "./styles.css";
export default function App() {
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
<div className="align_text">
<h2>Start editing to see some magic happen!</h2>
</div>
</div>
);
}
Here the CSS' snippet:
.App {
font-family: sans-serif;
}
h2 {
width:100vw;
margin:auto;
position: absolute;
left: 50%;
transform: translate(-50%, 0);
display:flex;
justify-content: center;
align-items: center;
background:orange;
}
.align_text{
position:relative;
width:100vw;
display:flex;
justify-content: center;
align-items: center;
}
Flexbox is a good way to achieve this. You made the mistake to apply the flexbox to the text-elements itself instead of to the .App class and then wrap everything inside .App in another div.
For your sandbox this is the solution:
export default function App() {
return (
<div className="App">
<div>
<h1>Hello CodeSandbox</h1>
<div className="align_text">
<h2>Start editing to see some magic happen!</h2>
</div>
</div>
</div>
);
}
Styles
.App {
font-family: sans-serif;
display: flex;
width: 100%;
justify-content:center;
}
h2 {
background:orange;
}
Try this css,
.App {
font-family: sans-serif;
}
h2 {
width: 100vw;
margin: auto;
position: absolute;
left: 50%;
transform: translate(-50%, 0);
display: flex;
background: orange;
}
.align_text {
position: relative;
width: 100vw;
display: block;
}
h2 {
padding: 10px;
display: block;
width: 50%;
margin: auto;
}
In this situation it should be enough to give the child paragraph a margin.
In the example below, I have given the paragraph a faint dashed outline so you can see where it begins and ends.
I have given it a margin equal to 10% of the width of the parent <div>.
N.B. You can actively resize the <div> - by grabbing and moving the bottom right-hand corner - to see how the <p> moves around and changes dimensions inside it, as you do.
Working Example:
body {
background-color: rgb(255, 238, 244);
}
div {
width: 300px;
height: 180px;
border: 3px solid rgb(0, 0, 0);
resize: both;
overflow: hidden;
}
div p {
margin: 10%;
font-size: 24px;
border: 1px dashed rgba(255, 0, 0, 0.5);
}
<div>
<p>Here is a left-aligned text at the center of the div.</p>
</div>

unable to set the exact css for login page

i want to create a login page like this : https://i.stack.imgur.com/smEWd.jpg
but what i get is :
https://i.stack.imgur.com/DvpEL.jpg
import React, { useState } from "react";
import Header from "./Header";
// import { Button, FormGroup, input, label } from "react-bootstrap";
import "./Login.css";
export default function Login1(props) {
// const [email, setEmail] = useState("");
// const [password, setPassword] = useState("");
const [user, setUser] = useState({email : "", password : ""})
function validateForm() {
return user.email.length > 0 && user.password.length > 0;
}
function handleSubmit(event) {
event.preventDefault();
}
return (
<div className="Login">
<Header person = {user}/>
<form className="modal-content animate" onSubmit={handleSubmit}>
<div><h3 align='center'>Login</h3>
</div>
<div className="Container">
<input type="text"
autoFocus
placeholder="Username"
value={user.email}
onChange={e => setUser({...user,email : e.target.value})}
/>
{/* {console.log(user)} */}
<br/>
<input type="password" placeholder="Password"
value={user.password}
onChange={e => setUser({...user,password : e.target.value})}
/>
<br/><button disabled={!validateForm()}type="submit">
Login
</button>
</div>
<div id="footer">
<button className="submit1" disabled="true" type="submit">
Sign up
</button>
<br/><button className ="submit1" disabled="true" type="submit">
Forgot Password?
</button>
</div>
</form>
</div>
);
}
#media all and (min-width: 480px) {
.Login {
padding: 120px 0;
}
.Login form {
margin: 0 auto;
max-width: 480px;
}
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
left: 0;
top: 0;
width: 80%; /* Full width */
height: 80%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
padding-top: 100px;
}
/* Modal Content/Box */
.modal-content {
background-color: #fefefe;
margin: 10px auto; /* 15% from the top and centered */
border: 1px solid #888;
border-radius: 15px;
width: 120%; /* Could be more or less, depending on screen size */
}
.footer {
background-color: #9fa9a3;
margin: 10px auto; /* 15% from the top and centered */
border: 1px solid #888;
border-radius: 15px;
width: 80%; /* Could be more or less, depending on screen size */
}
input[type=text], input[type=password] {
width: 100%;
padding: 10px 10px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}
.container {
padding: 30px;
}
/* Set a style for all buttons */
button {
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 100%;
}
h3{
font-family:"Arial Black", Gadget, sans-serif;
font-size: 30px;
}
/* Add Zoom Animation */
.animate {
-webkit-animation: animatezoom 0.0s;
animation: animatezoom 0.0s
}
#-webkit-keyframes animatezoom {
from {-webkit-transform: scale(0)}
to {-webkit-transform: scale(1)}
}
#keyframes animatezoom {
from {transform: scale(0)}
to {transform: scale(1)}
} */
form {
border: 3px solid #f0f0f0;
}
}
I tried changing the width and CSS of the code. but still i couldn't get the exact login page design. could someone help me with this?
I have added the code snippet. I am doing this using react. I have done this html code in login.js and i have attached the CSS along with.
I added a className to Login button - submit0
<button className="submit0" disabled={!validateForm()} type="submit">
Login
</button>
You've given id footer but you were using .footer in .css file, instead you've to use #footer.
Added css for background-image
.Login {
background-image: url(https://i1.wp.com/512pixels.net/downloads/macos-wallpapers-thumbs/10-12--thumb.jpg?zoom=1.25&w=640);
background-repeat: no-repeat;
background-size: cover;
padding: 120px 0;
}
Opacity to Login Form
.Login form {
margin: 0 auto;
max-width: 480px;
opacity: 0.9;
}
Removed border from .modal-content
.modal-content {
background-color: #fefefe;
margin: 10px auto; /* 15% from the top and centered */
/* border: 1px solid #888; */
border-radius: 15px;
width: 120%; /* Could be more or less, depending on screen size */
}
Footer css -
#footer {
/*background-color: #9fa9a3;
margin: 10px auto; /* 15% from the top and centered */
/* border: 1px solid #888;
border-radius: 15px; */
/*width: 100%; Could be more or less, depending on screen size */
background-color: #666;
margin-top: 10px;
border-bottom-left-radius: 11px;
border-bottom-right-radius: 11px;
}
For input field and login button, added left, right margin, border-radius and changed the width to 90%
input[type="text"],
input[type="password"] {
width: 90%;
padding: 10px 10px;
margin: 8px 24px;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
border-radius: 11px;
}
Buttons css -
.submit0 {
width: 90%;
margin: 8px 24px;
border-radius: 11px;
}
.submit1 {
background-color: inherit;
}
CodeSandbox Link
for testing is css file classes read correctly try put some custom inline styling in page and see this is work correctly if this work ok then you should check css class in main file and with inspect element check is Login.css loading on page
for inline styling : https://codeburst.io/4-four-ways-to-style-react-components-ac6f323da822

How to make this image lightbox work for both horizontal and vertical images?

I need to create an image lightbox. I basically started from this example from w3school, https://www.w3schools.com/howto/howto_js_lightbox.asp
However, it doesn't work for portrait oriented images. Eg. a landscape image is 1200x800 and a portrait can be 800x1200.
I need the images to resize responsive and work for both horizontal and vertical images.
It needs to work for all modern browsers, ios, android and also IE11.
you'll see I've added "max-width: 1200px;" to lightbox-content, which does the trick for horizontal images... but since a vertical image is 800 wide, it enlarges and the height exceeds.
<div class="lightbox">
<span class="close" onclick="closeLightbox()">×</span>
<div class="lightboxTitle">My Title</div>
<div class="lightbox-content">
<div class="slide"><img src="img1.jpg"></div>
<div class="slide"><img src="img2.jpg"></div>
<div class="slide"><img src="img2.jpg"></div>
<!-- Next/previous controls -->
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
</div>
/* The Modal (background) */
.lightbox {
display: none;
position: fixed;
z-index: 99999999;
padding-top: 60px;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
}
/* Modal Content */
.lightbox-content {
position: relative;
margin: auto;
padding: 0;
width: 100%;
max-width: 1200px;
}
.lightboxTitle {
position: absolute;
top: 20px;
left: 25px;
font-size: 20px;
}
/* The Close Button */
.close {
color: white;
position: absolute;
top: 10px;
right: 25px;
font-size: 35px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #FF8511;
text-decoration: none;
cursor: pointer;
}
/* Hide the slides by default */
.slide {
display: none;
}
.slide img {
width: 100%;
}
/* Next & previous buttons */
.prev,
.next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
padding: 16px;
margin-top: -50px;
color: white;
font-weight: bold;
font-size: 20px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
-webkit-user-select: none;
}
/* Position the "next button" to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
.prev {
left: 0;
border-radius: 3px 0 0 3px;
}
/* On hover, add a black background color with a little bit see-through */
.prev:hover,
.next:hover {
background-color: rgba(0, 0, 0, 0.8);
color: #FF8511;
}
I had the same issue in one of my past projects. I solved it with this js library https://imagesloaded.desandro.com/,
It allows you to process the images after they are loaded, and you can then assign a css class to it according to the aspect ratio.
$('#container').imagesLoaded( function() {
// images have loaded
// check image height/width > 1, portrait
// check image heidht/width <= 1, square or landscape
// assign different classes for each case to handle
});
css:
.img-container {
//do whatever you need on the container
}
// keep the image classes like this
.img-container img.portrait {
height: 100%;
width: auto;
}
.img-container img.landscape {
width: 100%;
height: auto;
}

CSS modal backfall doesn't take up entire screen

I want the background of my modal in CSS to take up the entire screen (i.e. whole screen gets shadowed over except for the modal content itself). I think this may have to do with me giving other divs widths and heights based on vh and vw. Here's My Code:
#modal {
z-index: 1;
position: fixed;
left: 40%;
right: 30%;
top: 10%;
background-color: rgba(0, 0, 0, 0.4);
width: 100vw;
height: 100vh;
}
#modal button {
height: 40px;
font: Hind Siliguri;
font-weight: bold;
border: 2px solid white;
border-radius: 5px;
margin: 5px;
}
<span id="modal">
<h2>Choose a word: </h2>
<button id = "choice1">Word1</button><button id= "choice2">Word2</button><button id = "choice3">Word3</button>
</span>
Here are other elements I assigned dimensions based on vw/vh:
#verbal-hint-container{
margin-right: 50%;
height: 30vh;
width: 40vw;
background-color: #C3D898;
border: 5px solid #160F29;
border-radius: 2px;
}
verbal-hint-container is just a div that contains instantiated messages (from mustache library).
Is my hunch that assigning other elements dimensions based on vw/vh interferes with making an element span the entire screen right? Is there a workaround for this? If it matters, my css+html for my modal occurs later in those files than my css+html for all other elements.
On #modal the height and width are using = instead of : thats why its not working properly. Change your #modal CSS to this:
#modal {
z-index: 1;
position: fixed;
left: 40%;
right: 30%;
top: 10%;
display: none;
background-color: rgb(0, 0, 0);
background-color: rgba(0, 0, 0, 0.4);
width: 100vw;
height: 100vh;
}
left, right, and top on #modal are not necessary if your goal is to cover up the whole screen. This will only cause the modal to be placed at the wrong position.
Not really sure what you want to achieve here but I would suggest to remove / comment out the display: none first while debugging / creating new component / block
Using Inspect element provides us with a way to find the classes in use by bootstrap.
Try adding the following CSS to your page:
.reveal-modal-bg {
width: auto !important;
position: fixed;
background: rgba(0, 0, 0, 0.45);
display: none;
left: 0;
right: 0;
top: 0;
bottom:0;
z-index: 40;
}
Adding this code should ensure that the background is fully covering the entire page.
I don't know if I'm getting your question right.
But here's an example where the modal background occupies 100% of the screen.
I hope this will help you.
var modal = document.getElementById("myModal");
var btn = document.getElementById("myBtn");
var span = document.getElementsByClassName("close")[0];
btn.onclick = function() {
modal.style.display = "block";
}
span.onclick = function() {
modal.style.display = "none";
}
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
/* Modal Content */
.modal-content {
background-color: #fefefe;
margin: auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
}
/* The Close Button */
.close {
color: #aaaaaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h2>Modal Example</h2>
<button id="myBtn">Open Modal</button>
<div id="myModal" class="modal">
<div class="modal-content">
<span class="close">×</span>
<p>Some text in the Modal..</p>
</div>
</div>
</body>
</html>