I'm using position:absolute; now i want to make width auto (as per contents) but because of position:absolute; i'm not able to width:auto;
$('.wishlistMessage').text('Your product added to wishlist')
$('.wishlistMessage').show();
.wishlistMessage{position: fixed;
bottom: 25px;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
background: rgba(0, 0, 0, 0.8);
color: #fff;
padding: 12px 25px;
display: inline;
width: auto;
text-align: center;
border-radius: 5px;
z-index: 10000;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wishlistMessage">Your product added to wishlist</div>
An element with position: absolute will fit it's size to the contents. Since you use left: 0 and right: 0 the element is stretched to both sides. Removing one of them (I've removed the right), would fix the problem:
$('.wishlistMessage').text('Your product added to wishlist')
$('.wishlistMessage').show();
.wishlistMessage {
position: fixed;
bottom: 25px;
left: 50%;
transform: translateX(-50%);
background: rgba(0, 0, 0, 0.8);
color: #fff;
padding: 12px 25px;
text-align: center;
border-radius: 5px;
z-index: 10000;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wishlistMessage">Your product added to wishlist</div>
Related
I'm trying to build a "block" on a website that contains a background image with lowered opacity, some text with regular opacity and a button with regular opacity
Currently, I'm getting the background image and text to work, but the button is stuck on the image's opacity (blends in with the background).
Here is the html:
h1,p {
text-align: center;
position:relative;
top:-70px;
position: relative;
color: navy;
}
.box1 {
width: 97.5%;
background-color: white;
position: relative;
padding-top: 200px;
padding-bottom: 200px;
padding-left: 30px;
padding-right: 30px;
margin-top: 20px;
margin-bottom: 10px;
margin-right: 1.25%;
margin-left: 1.25%;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
.box1::before {
content: "";
background-image: url(/static/background.jpeg);
background-size: contain;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
position: absolute;
opacity: 0.5;
}
.click {
color:rgba(0, 0, 0, 0.19)
}
<div class="box1">
<h1>Our Mission</h1>
<p>THe organization plans to complete tasks x, y, z</p>
<button class="click">Learn More</button>
</div>
Add position: relative to your .click class.
Side note: You have a duplicate position: relative in your h1, p selector.
.main-page {
width: 90%;
height: 100%;
z-index: 999;
position: relative;
}
.menu {
width: 350px;
margin: 32px 852px 171px 0;
padding: 21px 21px 0px 40px;
box-shadow: 0 3px 18px 0 rgba(35, 41, 62, 0.13);
background-color: #ffffff;
position: absolute;
float: right;
top: -50px;
left: 105px;
border-radius: 8px;
z-index: 9999;
}
{{start component}}
<div class="menu"> </div>
{{end component}}
<div class="main-page">
</div>
We want to display the menu on top of the main page but it is appearing behind parts of the main page when scrolling. How do we put the menu on top of the main page using css?
We have tried using the z-index but that did not work. We also tried adding an opacity to change the stacking context but that did not work either.
Just on top or always pinned to the top when scrolling?
I've just disabled few lines of your css and menu is on top:
.main-page {
width: 90%;
height: 100%;
/* z-index: 999; */
/* position: relative; */
}
.menu {
width: 350px;
margin: 32px 852px 171px 0;
padding: 21px 21px 0px 40px;
box-shadow: 0 3px 18px 0 rgba(35, 41, 62, 0.13);
background-color: #ffffff;
/* position: absolute; */
/* float: right; */
top: -50px;
left: 105px;
border-radius: 8px;
/* z-index: 9999; */
}
https://jsfiddle.net/k25cuax4/
Those two elements are siblings in your HTML code. However, a typical relative/absolute position pair where the absolutely positioned element is on top of the other one has position: relative for the parent element and position: absolute for the child.
So you eiter should change the HTML structure accordingly (i.e. move .menu into .main-page), or you can try to apply a negative z-index to .main-page to move it to the background. (i.e. z-index: -1).
First of all excuse me for explanation if I am not up to the mark, as this is my first post in this platform, Well, I am working on overlay where it has to be shown in right side of the page with given width of say 416px and 100vh of height, but things are getting cut if I do decrease the browser window and as I am decreasing the size of the browser window the button at bottom start appearing on content of overlay which has to remain at bottom even the height is getting decreased, here is the my code as below:
.advanced-overlay {
width: 100%;
min-height: 100vh;
background-color: rgba(35, 0, 18, 0.5);
position: fixed;
z-index: 100002;
top: -41px;
left: 0;
bottom: 0;
.advance-overlay-footer {
display:flex;
justify-content: space-between;
align-items:center;
position: fixed;
right: 24px;
width:156px;
bottom: 24px;
height:6%;
}
.advanced-overlay-content {
position: relative;
// min-height: 83vh;
width: 416px;
margin-top: 108px;
margin-left: auto;
margin-right: 6px;
opacity: 1;
z-index: 100004;
border-radius: 16px 16px 16px 16px;
background-color: #f5f4f6;
box-shadow: 0 2px 30px 0 rgba(0, 0, 0, 0.07),
0 19px 18px 0 rgba(0, 0, 0, 0.05), 0 8px 12px 0 rgba(0, 0, 0, 0.05),
0 1px 5px 0 rgba(0, 0, 0, 0.04), 0 0 2px 0 rgba(0, 0, 0, 0.03);
.close-advance-overlay {
position: absolute;
background-color: #fff;
width: 110px;
height: 40px;
display: flex;
border-radius: 20px;
padding: 5px 22px;
top: -18px;
right: 155px;
opacity: 1;
cursor: pointer;
img {
height: 20px;
width: 20px;
align-self: center;
}
.button-text {
align-self: center;
margin-left: 5px;
font-weight: 600;
font-size: 16px;
color: #000000;
}
}
.advnaced-overlay-content-secion {
//min-height:89vh;
width: 100%;
bottom:10%;
// height:100vh;
.select-box {
margin-top: 40px;
margin-bottom: 40px;
}
.accordinan-filter {
margin-bottom: 24px;
}
.accordian-title {
font-weight: 900;
}
.accordian-content {
margin: 0;
font-size: 16px;
}
}
}
}
.is-maximum {
height: 73vh;
overflow-y: auto;
overflow-x: hidden;
&::-webkit-scrollbar {
width: 4px;
background-color: #fff;
}
&::-webkit-scrollbar-thumb {
border-radius: 3px;
background-color: #d3d3d3;
}
}
<div class="advanced-overlay" v-if="toggleFilter">
<div class="advanced-overlay-content">
<div class="close-advance-overlay" #click="toggleAdvanceFilterOverlay">
<img class src="../assets/icons/close.svg" />
<span class="button-text">Close</span>
</div>
<div class="advnaced-overlay-content-secion is-maximum">
<div class="select-box"></div>
<div class="accordinan-filter"></div>
</div>
<div class="advance-overlay-footer">...two buttons</div>
</div>
</div>
So, I what I would like to achieve eventually is that, I want respsonsive overlay at right side of the browser window, provided if I am decreasing height of the browser the buttons at bottom should stay there (fixed position) and content should be within limit of .advnaced-overlay-content-secion
for a responsive design I recommend you to read into the use of grid and espacially for mobile designs also the use of #media breakpoints.
for having some thing to stick at the bottom simply use:
position: fixed;
bottom: 0;
I'm quite new at front-end development. I was just experimenting with HTML/CSS. After making a simple poster, I was trying to make simple freestyle(not specific to any kind of website) page layout.
Here is what I did.
https://github.com/imdpm/CodoSapiens/tree/master/LayAtt
I'm trying to add a "content" type division. I've created a style for it in style.css and invoked it in index.html without any content. Just the division.
But output does not have any "content" division. I can't seem to understand where I have made a mistake.
Could anyone help?
body{
background-image: url("BackIm.jpg");
background-repeat: no-repeat;
background-attachment: fixed;
background-size: 100% 100%;
}
#icon{
position: absolute;
left: 5px;
height:40px;
width:40px;
}
.topmenu{
background-color: #001a00;
position: absolute;
top: 0;
right: 0;
left: 0;
display: flex;
justify-content: center;
padding: 0;
border-bottom: 1px solid red;
}
.sidemenu{
background-color: darkgrey;
color: black;
position: left fixed relative;
margin: 190px 80px 0 40px;
padding: 8px 6px 0 8px;
border: 1px solid black;
border-radius: 8px;
max-width: 155px;
font-size: 30px;
font-family: sans-serif;
}
.banner{
background-color: #FFA500;
position: absolute;
top:44px;
left: 0;
right: 0;
height: 125px;
border-bottom: 1px solid #228B22;
}
.content{
background-color: #5651F3;
position: relative;
top: 60px;
right: 30px;
left: 25px;
}
#link{
color: black;
text-decoration: none;
padding: 2px 0 1px 0;
color:grey;
font-size:35px;
font-family:"Times New Roman";
font-weight:bold
}
a{
text-decoration: none;
color: black;
padding: 0;
}
hr{
border: 0;
height: 1px;
background-image: linear-gradient(to right, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0));
}
<html>
<head>
<title>LayoutAtt</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="topmenu">
<img id="icon" src="https://github.com/imdpm/CodoSapiens/blob/master/LayAtt/BackIm.jpg?raw=true" alt="Icon">
<a id="link" href="index.html">BackToBeg</a>
</div>
<div class="banner">
</div>
<div class="sidemenu">
BackToBeg<hr>
BackToBeg<hr>
BackToBeg<hr>
BackToBeg<hr>
BackToBeg<hr>
</div>
<div class="content">
</div>
</body>
</html>
You need to add a width and a height to your content div.
Try this
.content{
background-color: #5651F3;
position: relative;
top: 60px;
right: 30px;
left: 25px;
width:100px;
height:100px;
}
Use the inspector in the browser to look at the html and css being rendered. You can see what styles are being applied to which elements.
I have two DIVs inside each other. The inner DIV contains an image. I'm trying to add a floating text over that image in the top right corner. I can't figure out how to make that text to use inner DIV's positions instead of the outer one.
Here is what I got so far
CSS:
html {
background: #EEF0F3;
}
.outer {
background: #FFFFFF;
border-radius: 4px 4px 4px 4px;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
margin: 0 auto;
padding:20px 0px;
position: relative;
width: 680px;
text-align: center;
margin-bottom: 20px;
}
.inner {
position: relative;
}
h2 {
position: absolute;
top: 0px;
right: 0px;
}
h2 span {
color: white;
font: bold 24px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: rgba(255, 0, 0, 0.5);
padding: 0px 10px;
}
HTML:
<div class="outer">
<div class="inner">
<h2><span>Title 1</span></h2>
<img src="1.jpg">
</div>
</div>
And here is the code in JSFiddle
http://jsfiddle.net/UM8ea/
If I set positioning to:
h2 {
position: absolute;
top: 20px;
right: -20px;
}
I get the desired result, but that feels like workaround rather than a solution.
Its very simple.
Check this fiddle
.outer {
background: #FFFFFF;
border-radius: 4px 4px 4px 4px;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
margin: 0 auto;
padding:20px 0px;
position: relative;
width: 680px;
text-align: center;
margin-bottom: 20px;
}
for h2
h2
{
position: absolute;
top: 5px;
right: 20px;
margin:0;
}
You have this behaviour because .outer is wider than the image, and then, .inner too. The h2 is positioned related to .inner, and go to right.
If you set .outer to have 640px width (as the image) you get the desired result.
Other solution is to set margin: 0 20px; on .inner
If you want the text positioned all top the image you can set h2 {margin:0;} in both cases.