size of div in absolute with some content [duplicate] - html

This question already has answers here:
How to turn off word wrapping in HTML?
(6 answers)
Closed 2 years ago.
I am a bit stuck with my code
I did a custom drop down menu and my problem is my div with my content don't take 100% of the content
my div is blocked at 160px here is the css code
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 160px; // I wanted 100% of the content
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 3;
right:0;
}
and the full code in jsfiddle
https://jsfiddle.net/kg0tjLr9/1/

I think you want max-content instead of specifying px like:
$(document).ready(function() {
$('.dropbtn').click(function() {
//$('.dropdown-content').css('display','block');
$('.dropdown-content').toggle();
$('#overlay').toggle();
})
$('#overlay').click(function(){
$('#overlay').css('display','none');
$('.dropdown-content').toggle();
});
});
#main_content{
z-index:-1;
}
.dropbtn {
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
}
.dropdown {
position: relative;
display: inline-block;
float:right;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: max-content;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 3;
right:0;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
#overlay {
position: fixed;
display: none;
width: 100%;
height: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0,0,0,0.5);
z-index: 2;
cursor: pointer;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id='main_content'>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eaque veritatis blanditiis porro asperiores quas quasi minima. Laudantium consequatur obcaecati dignissimos ducimus aliquam culpa, libero animi odit! Laboriosam ipsam rem, quas.
</div>
<div class="dropdown">
<div id="overlay"></div>
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
Lorem ipsum dolor sit amet, consectetur
Link 2
Link 3
</div>
</div>
max-content is not supported by internet explorer ( https://developer.mozilla.org/en-US/docs/Web/CSS/max-content)
If you want IE compatibility (add width: auto; white-space: nowrap; instead of max-content):
$(document).ready(function() {
$('.dropbtn').click(function() {
//$('.dropdown-content').css('display','block');
$('.dropdown-content').toggle();
$('#overlay').toggle();
})
$('#overlay').click(function(){
$('#overlay').css('display','none');
$('.dropdown-content').toggle();
});
});
#main_content{
z-index:-1;
}
.dropbtn {
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
}
.dropdown {
position: relative;
display: inline-block;
float:right;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
width: auto;
white-space: nowrap;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 3;
right:0;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
#overlay {
position: fixed;
display: none;
width: 100%;
height: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0,0,0,0.5);
z-index: 2;
cursor: pointer;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id='main_content'>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eaque veritatis blanditiis porro asperiores quas quasi minima. Laudantium consequatur obcaecati dignissimos ducimus aliquam culpa, libero animi odit! Laboriosam ipsam rem, quas.
</div>
<div class="dropdown">
<div id="overlay"></div>
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
Lorem ipsum dolor sit amet, consectetur
Link 2
Link 3
</div>
</div>

Related

Why a particular section is not visible after hover? [duplicate]

This question already has answers here:
How to affect other elements when one element is hovered
(9 answers)
Closed 1 year ago.
I made a design where I want to show text section after hover on info icon. But It is not working after hover on info icon. Please help me. I could not able to find my problem in this code. But most probably I think the problem is in the hover section. But I could not able to fix it. Please help me to fix this problem.
*{
margin: 0;
padding: 0;
}
.hover1 {
height: 500px;
width: 700px;
background: #00a8ff;
margin: 10px auto;
position: relative;
}
.icon-info{
position: absolute;
top: 150px;
left: 500px;
background: white;
padding: 5px 11px;
border-radius: 50%;
}
.text{
height: 200px;
width: 360px;
background: white;
position: relative;
top: 150px;
left: 130px;
padding: 20px;
border-radius: 13px;
display: inline-block;
visibility: hidden;
opacity: 0;
}
.text h3{
font-size: 30px;
margin: 20px 5px;
}
.text p{
font-size: 18px;
}
/* hover */
.icon-info:hover .text{
visibility: visible;
opacity: 1;
transition: .5s;
cursor: pointer;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hover effect</title>
<link rel="stylesheet" href="./hover.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css">
</head>
<body>
<div class="hover1">
<i class="fas fa-info icon-info"></i>
<div class="text">
<h3>This is Tittle</h3>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Consectetur dolores quis enim facilis doloribus iste hic dolore cumque rerum, in earum omnis obcaecati blanditiis nostrum ab. Tempora officia voluptatibus ex!</p>
</div>
</div>
</body>
</html>
Just add a + in hover style as follow:
*{
margin: 0;
padding: 0;
}
.hover1 {
height: 500px;
width: 700px;
background: #00a8ff;
margin: 10px auto;
position: relative;
}
.icon-info{
position: absolute;
top: 150px;
left: 500px;
background: white;
padding: 5px 11px;
border-radius: 50%;
z-index:1;
}
.text{
height: 200px;
width: 360px;
background: white;
position: relative;
top: 150px;
left: 130px;
padding: 20px;
border-radius: 13px;
display: inline-block;
visibility: hidden;
opacity: 0;
}
.text h3{
font-size: 30px;
margin: 20px 5px;
}
.text p{
font-size: 18px;
}
/* hover */
.icon-info:hover + .text{
visibility: visible;
opacity: 1;
transition: .5s;
cursor: pointer;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hover effect</title>
<link rel="stylesheet" href="./hover.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css">
</head>
<body>
<div class="hover1">
<i class="fas fa-info icon-info"></i>
<div class="text">
<h3>This is Tittle</h3>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Consectetur dolores quis enim facilis doloribus iste hic dolore cumque rerum, in earum omnis obcaecati blanditiis nostrum ab. Tempora officia voluptatibus ex!</p>
</div>
</div>
</body>
</html>

CSS - Unable to align image and text together inside div

I'm trying to show message within a div with icon on the left.
Expected result is icon should always adjacent to text and together they need to be aligned at bottom-center of div.
I'm using :after pseudo element. Keeping position: absolute of icon didn't help since that needs manually adjusting the icon position relative to text.
Here is the CSS.
.parent{
font-weight: 500;
height: 65px;
text-align: center;
padding: 15px 0 10px;
margin: auto;
display: block;
width: 80%;
font-size: 12px;
overflow: hidden;
position: relative;
}
.parent > div {
float: none;
/* display: table-cell; */
vertical-align: middle;
position: absolute;
bottom: 0;
width: 100%;
}
.msg:after {
content: '';
background: url(data:image/...);
height: 16px;
width: 16px;
display: block;
position: absolute;
top: 0;
padding-right: 5px;
left: 108px;
}
And markup:
<div class="parent">
<div class="msg">text goes here</div>
</div>
Flexbox can do that:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
::before,
::after {
box-sizing: inherit;
}
.parent {
font-weight: 500;
margin: auto;
padding: 1em;
width: 80%;
font-size: 12px;
overflow: hidden;
position: relative;
border: 1px solid red;
}
.msg {
display: flex;
}
.msg p {
padding-left: 1em;
}
.msg:before {
content: "";
height: 16px;
flex: 0 0 16px;
background: red;
border-radius: 100%;
}
<div class="parent">
<div class="msg">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Beatae numquam unde, eum sequi expedita fugiat ipsa exercitationem nesciunt libero repellendus aperiam excepturi, dolorem repudiandae eveniet alias perspiciatis, vero veniam tempora natus magnam
itaque quos. Nemo sit nisi, veniam mollitia fugit eaque reiciendis ex doloribus rem et suscipit debitis commodi sapiente.</p>
</div>
</div>

box-shadow doesn't display on top of a background image

So I'm creating a nav-bar on a parallax-style website and I want a shadow to display on top of the image below the nav bar, but the shadow isn't visible on top of the image but below it.
I'll show you what I mean with the images below:
https://i.stack.imgur.com/GL10W.png
Here you see the shadow and there's no background image...
https://i.stack.imgur.com/QW6kk.png
... but here you can't, because of the image below the nav bar.
I've already tried z-index, but it isn't working.
Is there a way to make that you can see the shadow?
jsfiddle in the comments
EDIT: Thank you very much to all! You really helped me :)
Setting the z-index on .section-nav does nothing, because it is not positioned.
So possible solutions are (apart from Jeremy's, which also works):
Set the .nav-section to position: relative like the pimg's, which makes its own z-index work.
Or set the z-index of .pimg1 and .pimg2 to -1 to make them go behind the nav section.
#import url('https://fonts.googleapis.com/css?family=Libre+Franklin:300,400,600,900');
/* ---------- GLOBAL STYLES ---------- */
* {margin: 0; padding: 0; box-sizing: border-box;}
body {
height: 100%;
font-family: 'Libre Franklin', 'Helvetica Neue', helvetica, arial, sans-serif;
font-size: 16px;
font-weight: 400;
line-height: 21px;
color: #222;
}
.wrapper {
width: 72%;
max-width: 1000px;
margin: auto;
}
.section {
padding: 30px 50px;
}
.section-light {
background-color: #fff;
}
.section-dark {
background-color: #222;
color: #fff;
}
/* ---------- NAVIGATION STYLES ---------- */
.section-nav {
z-index: 99;
padding: 0;
border-bottom: 1px solid #767676;
box-shadow: 0px -20px 300px rgba(0, 0, 0, 1);
}
.section-nav ul {
display: block;
height: 72px;
display: flex;
align-items: center;
}
.section-nav ul li {
text-align: left;
display: inline-block;
margin-right: 37px;
}
.section-nav ul li a {
text-decoration: none;
font-size: 14px;
font-weight: 600;
color: #222;
}
.section-nav ul li a.active {
color: #767676;
}
.pimg1, .pimg2 {
position: relative;
background-position: center;
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;
z-index: -1; /* changed */
}
.pimg1 {
background-image: url('https://i.ibb.co/D9D8mZq/img1.jpg');
min-height: 100vh;
}
.pimg2 {
background-image: url('https://i.ibb.co/n6J2pTs/img2.jpg');
min-height: 100vh;
}
<!DOCTYPE html>
<body>
<div class="pimg1"></div>
<section class="section section-light section-nav">
<div class="wrapper">
<ul>
<li>Home</li>
<li>Blog</li>
<li>Das Projekt</li>
<li>Kontakt</li>
</ul>
</div>
</section>
<div class="pimg2"></div>
<section class="section section-light">
<h2>Section 2</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Vitae culpa aliquid natus, consequuntur quasi dolorum, mollitia corrupti reprehenderit molestiae sequi ipsa quod minima, ullam saepe recusandae commodi nostrum obcaecati adipisci rerum atque omnis labore. Voluptatum quasi laborum ut cupiditate est ea, sequi tempora mollitia repudiandae autem nulla neque tenetur voluptate ducimus laudantium.
</p>
</section>
</body>
It looks like position: relative; is what's breaking it. Removing that from .pimg1, .pimg2 makes the box shadow show again.
You should add this style to .section-nav
position: relative;
Here's the updated style:
.section-nav {
z-index: 99;
padding: 0;
border-bottom: 1px solid #767676;
box-shadow: 0 0 0.3em #333;
position: relative;
}
I changed a box-shadow property too so I could see the shadow. Yours one I wasn't able to see well.
and link to fiddle

Positioning a absolute div at the edges of an inline span

I am building functionality to select text with "handles". These handles need to be positioned on either the left or right side of the inline span. An image:
As you can see I've come a long way in styling this in CSS. The one problem I have is that I can't seem to position the right handle on the text itself.
The following code is being used:
.text {
display: inline;
background-color: #4d82f2;
color: white;
padding: 1px;
border-radius: 2px;
margin: 0;
position: relative;
}
.text>.handle-left {
position: absolute;
background-color: #757575;
height: 25px;
width: 30px;
left: -30px;
top: -25px;
font-size: 10px;
border-radius: 15px;
border-bottom-right-radius: 4px;
}
.text>.handle-right {
position: absolute;
background-color: #757575;
height: 25px;
width: 30px;
right: -30px;
top: -25px;
font-size: 10px;
border-radius: 15px;
border-bottom-left-radius: 4px;
}
<div>All the other text
<div class="text">
<span>blue text</span>
<div class="handle-left">plus icon</div>
<div class="handle-right">plus icon</div>
</div>
Maybe some more text, who knows?
</div>
This JSFiddle displays my problem well:
JSFiddle
I would probably transform the element to inline and make one at the beginning and the other one at the end then I will use pseudo element. Doing this I will be sure they will be in the right place:
.all-text {
width: 400px;
margin: 40px;
}
.text {
display: inline;
background-color: #4d82f2;
color: white;
padding: 1px;
border-radius: 2px;
margin: 0;
position: relative;
}
.text>.handle-left,
.text>.handle-right {
position: relative;
}
.text>.handle-left:before {
content: "+";
position: absolute;
background-color: #757575;
height: 25px;
width: 30px;
left: -30px;
top: -25px;
display: inline-flex;
justify-content: center;
font-size: 24px;
border-radius: 15px;
border-bottom-right-radius: 4px;
}
.text>.handle-right:before {
content: "+";
position: absolute;
background-color: #757575;
height: 25px;
width: 30px;
right: -30px;
bottom: 18px;
display: inline-flex;
justify-content: center;
font-size: 24px;
border-radius: 15px;
border-bottom-left-radius: 4px;
}
<div class="all-text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laborum corporis enim doloremque perspiciatis, doloribus nemo commodi, consectetur
<div class="text">
<span class="handle-left"></span>
<span> quaerat verit</span>
<span class="handle-right"></span>
</div>
autem laboriosam est alias aspernatur deserunt quae, fugit eos? Lorem ipsum dolor sit amet,
<div class="text">
<span class="handle-left"></span>
<span> quaerat verit consectetur adipisicing elit. Laborum corporis enim </span>
<span class="handle-right"></span>
</div>
consectetur adipisicing elit. Laborum corporis enim doloremque perspiciatis, doloribus nemo commodi, consectetur
<div class="text">
<span class="handle-left"></span>
<span> quaerat veritatis at unde</span>
<span class="handle-right"></span>
</div>
autem laboriosam est alias aspernatur deserunt quae, fugit eos?</div>

Links aren't clickable after using parallax scrolling

I've been making this website for school and I thought i'd figure out how parallax scrolling works. So i've started with the simpelest tutorial to be precise this one. After doing this I placed my navigation bar in. I remember this worked fine at the time but after working allot on the responsiveness I didn't check back and now I can't click on the links anymore.
This is my html:
<div id="group2" class="parallax_group">
<!-- <div class="parallax_layer parallax_layer-back">
background
</div> -->
<div class="parallax_layer parallax_layer-base">
<div id="nav" class="nav">
<ul>
<li><a class="active" href="#">Home</a></li>
<li>Over ons</li>
<li>Wat leveren wij?</li>
<li>Contact</li>
<li>Demo</li>
</ul>
</div>
<div class="section group">
<div class="col span_1_of_3">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam id nam, necessitatibus at odit nobis vitae, dolor sequi sunt doloremque minima, debitis. Sed debitis possimus esse soluta mollitia est culpa.</p>
</div>
<div id="middle" class="col span_1_of_3">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui autem impedit, a, error accusantium soluta molestias quidem quo totam beatae eligendi sint, modi voluptatem nemo fugiat recusandae ullam consequatur nihil?</p>
</div>
<div class="col span_1_of_3">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Provident voluptatibus, quaerat nostrum ullam distinctio praesentium! Nemo eveniet provident id, tenetur cumque natus, quas porro possimus maiores, minus amet laboriosam ea?</p>
</div>
</div>
</div>
</div>
And this is my css:
* {
padding: 0;
margin: 0;
}
body {
text-align: center;
}
h1{
display: inline-block;
font-family: 'Raleway', sans-serif;
color: white;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
}
p{
display: inline-block;
font-family: 'Raleway', sans-serif;
color: black;
}
header {
z-index: 5;
line-height: 100vh;
}
header .parallax_layer-back {
background: url(sample.jpg);
background-size: contain;
background-repeat: no-repeat;
}
#group2 {
z-index: 3;
}
#group2 .parallax_layer-base {
background-color: #dbdbdb;
}
.parallax {
perspective: 300px;
height: 100vh;
overflow-x: hidden;
overflow-y: auto;
}
.parallax_layer {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
.parallax_layer-base {
transform: translateZ(0px);
z-index: 4;
}
.parallax_layer-back {
transform: translateZ(-300px) scale(2);
z-index: 3;
height: 150vh;
}
.parallax_layer-deep{
transform: translateZ(-600px) scale(3);
z-index: 2;
background-color: #dbdbdb;
}
.parallax_group {
position: relative;
height: 100vh;
transform-style: preserve-3d;
/*transform: translate3d(700px, 0, -800px) rotateY(30deg);*/
}
/*Columns*/
/* SECTIONS */
.section {
clear: both;
padding: 0px;
margin: 0px;
}
/* COLUMN SETUP */
.col {
display: block;
float:left;
margin: 1% 0 1% 1.6%;
}
.col:first-child { margin-left: 0; }
/* GROUPING */
.group:before,
.group:after {
content:"";
display:table;
}
.group:after {
clear:both;
}
.group {
zoom:1; /* For IE 6/7 */
}
/* GRID OF THREE */
.span_3_of_3 {
width: 100%;
}
.span_2_of_3 {
width: 66.1%;
}
.span_1_of_3 {
width: 32.2%;
}
#middle{
border-top: 0px;
border-bottom: 0px;
border-right: 1px;
border-left: 1px;
border-style: solid;
}
/*navigation*/
.nav {
position: sticky;
top: 0px;
height: 100px;
width: 100%;
z-index: 30;
font-family: 'Raleway', sans-serif;
font-size: 20px;
background-color: #dbdbdb;
}
.nav ul {
list-style-type: none;
margin-left: 0;
padding-top: 40px;
font-size: 25px;
font-family: 'Raleway', sans-serif;
line-height: 0;
z-index: 30;
}
.nav li {
display: inline-block;
margin-left: 15px;
padding-bottom: 25px;
z-index: 30;
}
a:link {
color: #2F649B;
font-family: inherit;
}
a:visited {
color: #2F649B;
}
a:hover {
color: #6D92B9;
text-decoration: none;
}
a:active {
color: #26507C;
text-decoration: none;
}
footer {
position: sticky;
bottom: 0px;
height: 100px !important;
line-height: 100px;
width: 100%;
}
I know it's allot of code but I have no idea what it could be so i went and gone ahead and gave you everything.
edit: The other html parallax group:
<!DOCTYPE html>
<html>
<head>
<title>Squirel WebDesign</title>
<link rel="stylesheet" type="text/css" href="main.css">
<link rel="stylesheet" type="text/css" href="handheld.css" media="screen and (max-device-width: 480px), screen and (max-width: 480px)">
</head>
<body>
<div class="parallax">
<header class="parallax_group">
<div class="parallax_layer parallax_layer-base">
<h1>i'm a bloody big header preferably with a squirel</h1>
</div>
<div class="parallax_layer parallax_layer-back">
</div>
<div class="parallax_layer parallax_layer-deep">
</div>
</header>

Categories