I'm trying to create this.
Unfortunately, I'm having trouble putting the image on top of the div like this.
How can I achieve this (CSS or JS)?
My current HTML:
<div className="account-container">
<img src="" alt="Avatar" id="userAvatar"/>
<div className="accountStats">
...Other Stuff
</div>
</div>
My current CSS:
#userAvatar{
border-radius: 50%;
height: 312px;
width: 312px;
object-fit: cover;
object-position: center;
}
.accountStats {
width: 760px;
height:980px;
background: #E0E0E0;
box-shadow: 9px 9px 10px rgba(0, 0, 0, 0.25);
border-radius: 18px;
}
.account-container {
top: 30%;
transform:translate(0, 30%);
}
You can give a minus value for the margin-bottom so that the image drops to the bottom. Set the margin-bottom value to half of the image's height (in this case 156px) so that only half of the image lies above the div. Check this out:
#userAvatar{
margin-bottom:-156px; /* 156px is half of #userAvatar's height */
margin-left:calc(380px - 156px); /* half of .accountStats's width - half of #userAvatar's height */
border-radius: 50%;
height: 312px;
width: 312px;
object-fit: cover;
object-position: center;
}
.accountStats {
text-align:center; /* additional */
padding-top:156px; /* half of #userAvatar's height */
width: 760px;
height:980px;
background: #E0E0E0;
box-shadow: 9px 9px 10px rgba(0, 0, 0, 0.25);
border-radius: 18px;
}
.account-container {
top: 30%;
transform:translate(0, 30%);
}
<div className="account-container">
<img src="https://w7.pngwing.com/pngs/7/618/png-transparent-man-illustration-avatar-icon-fashion-men-avatar-face-fashion-girl-heroes-thumbnail.png" alt="Avatar" id="userAvatar"/>
<div class="accountStats">
Other Stuff
</div>
</div>
Please test this:
margin-top: -156px;
Instead of manually calculating left margin to set image in center, we can use flexbox.
.user {
display: flex;
align-items: center;
justify-content: center;
}
body {
background: #efefef;
}
.account-container {
display: flex;
height: 100vh;
align-items: center;
flex-direction: column;
padding-top: 50px;
}
.card {
width: 350px;
border-radius: 5px;
box-shadow: 2px 5px 10px #ccc;
background: white;
}
.user {
display: flex;
align-items: center;
justify-content: center;
}
#userAvatar {
border-radius: 50%;
border: 3px solid #fff;
position: relative;
bottom: -50px;
object-fit: cover;
}
.accountStats {
height: 100px;
background-color: pink;
border-radius: 0px 0px 5px 5px;
}
<div class="account-container">
<div class="card">
<div class="user">
<img id="userAvatar" src="https://images.pexels.com/photos/4587979/pexels-photo-4587979.jpeg" width="100px" height="100px" />
</div>
<div class="accountStats"></div>
</div>
</div>
use the "position" atrribute
#useravatar{
position:absolute;
top:0%;
left:0%;
}
Related
I have a div like this:
Now I need to remove a part of the circle from this shape which is shown as below:
Therefore the final shape would be looked like this:
So I decided to put the image as the background of my div.
<div class="col-4 customBack">
<div class="mainInfo">
<div class="circle2">
<img src="https://sitename.com/images/image.png">
</div>
<div class="paraDivRight2">
<h6 style="margin-top:5px;"><strong>Lorem Ipsum Dolor Simit</strong></h6>
<hr style="margin-top:-5px;">
<p style="margin-top:-10px;">012-3456789</p>
<p style="padding-top:5px;">ifno#sitename.com</p>
</div>
</div>
</div>
And here are the styles:
.mainInfo{
background-color: #fff;
border: .01rem round #e0e1ed;
border-radius: 20px;
color: #585CA1;
width:100%;
height:5em;
box-shadow: 0px 0px 17px -5px rgba(0,0,0,0.75);
margin-top: 3em;
display: flex;
align-items: center;
justify-content: center;
}
.customBack{
background-image: url("/img/shadow3.png") !important;
}
.circle2 {
position: relative;
left:-60%;
width: 9em;
height: 9em;
background: #fff;
border-radius: 50%;
box-shadow: 0px 0px 17px -5px rgba(0,0,0,0.65);
}
.circle2 img {
position: absolute;
max-width: 85%;
border-radius: 50%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 100;
}
.paraDivRight2 {
position: absolute;
display: inline-block;
padding: 10px;
color:black;
top:0px !important;
padding-top:50px !important;
right: 20px;
text-align: right;
padding-right:50px !important;
}
.paraDivRight2 p {
line-height: 1em;
font-size: 10pt;
margin: 0;
letter-spacing: 1px;
}
As you can see I have put the background in .customBack class But the result is now looks like this:
So the question is, how can I properly place this background image which is (shadow3.png) as background image of this mainInfo div so the side of circle shape that needs to be removed, does not appear...
I'm really stuck with this, so please help me out...
Use CSS filter: drop-shadow() MDN Docs on a wrapper element.
Fix your class naming to use a friendlier convention
Use CSS flex for a simpler alignment of your elements
Stop using inline HTML style attributes
/* Quick Reset */
* {
margin: 0;
box-sizing: border-box;
}
.custom {
filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.4));
display: flex;
flex-wrap: nowrap;
align-items: center;
}
.custom-image {
width: 9em;
height: 9em;
background: #fff;
border-radius: 50%;
padding: 1em;
}
.custom-image img {
width: 100%;
height: 100%;
object-fit: cover;
border-radius: 50%;
}
.custom-content {
position: relative;
background: #fff;
padding: 1em;
text-align: right;
border-radius: 0 1em 1em 0;
padding-left: 2em;
left: -1em;
}
.custom-content h4 {
border-bottom: 1px solid #ddd;
}
<div class="custom">
<div class="custom-image">
<img src="https://i.stack.imgur.com/qCWYU.jpg?s=256&g=1">
</div>
<div class="custom-content">
<h4>Lorem Ipsum Dolor Simit</h4>
<p>012-3456789</p>
<p>ifno#sitename.com</p>
</div>
</div>
I'm not 100% sure about this but it has worked for me in the past,try making the position attribute of the div relative and make it absolute for the image,then size it properly.
I want to have three images side by side with one condition I'm unable to reach without a little bit help:
.picture-container {
position: absolute;
top: 10%;
width: 90%;
height: 70%;
left: 5%;
border-style: dotted;
}
.picture-container .img-container.three-image {
justify-items: center;
height: 100%;
gap: 20px;
display: grid;
grid-template-columns: auto auto auto;
}
.picture-container .img-container.three-image * {
height: 298px;
}
.picture-container .img-container.three-image .img-frame {
width: 100%;
height: 42%;
object-fit: cover;
}
.img-frame {
display: flex;
border: 5px solid #e8e8e8;
box-shadow: 1px 7px 20px 9px rgb(0 0 0 / 75%);
margin: 3rem auto 3rem;
flex: 1 0 45%;
border-radius: 5px;
cursor: pointer;
margin: 0.4rem;
background: #dfe4ea;
user-select: none;
transition: 0.5s;
height: 100%;
object-fit: contain;
}
<div class="picture-container">
<div class="img-container three-image ">
<img class="img-frame" src="https://images.pexels.com/photos/4876243/pexels-photo-4876243.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500">
<img class="img-frame" src="https://images.pexels.com/photos/1386454/pexels-photo-1386454.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500">
<img class="img-frame" src="https://images.pexels.com/photos/9646282/pexels-photo-9646282.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500">
</div>
</div>
I want these images to :
fill the whole area of the picture-container parent. they should fill the width and the height of the picture-container.
All the images should have the same dimensions. I don't want to have different sizes of them.
Note that source of the each image has its own dimensions.
The images should not be Cropped and they can be stretched...
The frame should be intact...
How can I do this?
I couldn't get it to work without wrapping the images in a DIV and setting a width and height on the images themselves.
.img-container{display:flex;max-height:100vh}
.img-container div{flex-grow:1}
.img-frame{width:calc(100% - 29px - 0.4rem);height:calc(100% - 29px - 0.4rem)}
Example:
https://jsfiddle.net/540scey8/1/
I have a WebView that displays a html layout. But the problem is the html layout isn't coming out how I expected it. I created a Android layout using xml but I want the layout in html. this is what i am trying trying achieve
The grey part represents a background image.
The purple part a image(Logo).
Then I have a white box with round corners and TextView and Button inside. this is done in android xml but i want something similar in html
This is how it looks in html
But as you can see the logo is behind the white box and the TextView is next to the button instead of the top.
here is my html code
<style>
div {
padding: 10px 10px;
background: #fff;
width: 300px;
border-radius: 10px;
margin : 0 auto;
}
body {
background-image: url("url to background image");
//background-size: cover;
}
.logo {
background-image: url("url to logo");
background-size: cover;
height: 70px;
width: 200px;
margin-bottom 40;
background-color: rgba(0, 0, 0, 0);
}
.container {
display: table;
height: 100%;
position: absolute;
overflow: hidden;
width: 100%;
background-color: rgba(0, 0, 0, 0);
}
.helper {
#position: absolute;
#top: 50%;
display: table-cell;
vertical-align: middle;
background-color: rgba(0, 0, 0, 0);
}
.content {
#position: relative;
#top: -50%;
margin: 0 auto;
width: 200px;
}
.button {
-moz-border-radius:15px;
-webkit-border-radius:15px;
border-radius:15px;
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
</style>
<div class="container">
<div class="helper">
<div class="logo"/>
<div class="content">
<p1>Text </p1>
<input type="submit" class="button" value="Button">
</div>
</div>
</div>
Can someone please help me fix my html code to look like the android xml version
Change <p1>Text </p1> to <p>Text </p>.
A p element has the style display:block; by default and will push the button down.
I'm trying to create a div that stays under the bottom of the page and is invisible there. I mean, you can't scroll to it. I tried to google it, but I just can't make it, neither negative bottom-margin, nor negative bottom, nor relative/absolute positioning couldn't make it...
Could anyone of you help me, please?
Here's a snippet of my site - I wanna "Menu" image to be invisible on the bottom (outside the display area), so it can then slide up when needed.
body {
overflow-x: hidden;
margin: 0;
padding: 0;
}
.main-container {
width: 100vw;
height: 100vh;
background-color: #780d0d;
position: absolute;
}
.mainmenu {
width: 70vw;
height: 82vh;
position: relative;
top: 8vh;
left: 15vw;
-webkit-box-shadow: 0px 0px 66px 10px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 0px 0px 66px 10px rgba(0, 0, 0, 0.75);
box-shadow: 0px 0px 66px 10px rgba(0, 0, 0, 0.75);
}
.menu-bottom {
height: 20%;
width: 33.2%;
background-color: red;
border: 1px solid;
display: inline-block;
margin: 0 -5px 0 0;
}
.menu-side-holder {
height: 80%;
width: 30%;
display: inline-block;
}
.menu-side {
height: 50%;
background-color: red;
border: 1px solid;
display: block;
margin: 0;
vertical-align: top;
}
#menu-img {
height: 80%;
width: 40%;
display: inline-block;
margin: 0 -4px;
vertical-align: top;
clear: none;
}
.menu-bottom-slider {
display: inline-block;
width: 100%;
background-color: green;
}
#slider {
position: absolute;
padding-left: 43.5%;
bottom: 0;
margin-bottom: -30vh;
}
<div class="main-container">
<div class="mainmenu">
<div class="menu-side-holder">
<div class="menu-side" id="ogloszenia">
1
</div>
<div class="menu-side">
3
</div>
</div>
<img id="menu-img" src="img/main4.jpg">
<div class="menu-side-holder">
<div class="menu-side">
3
</div>
<div class="menu-side">
4
</div>
</div>
<div class="menu-bottom">
5
</div>
<div class="menu-bottom">
6
</div>
<div class="menu-bottom">
7
</div>
<div class="menu-bottom-slider">
<img id="slider" src="http://s32.postimg.org/xrrmzmohx/slider.png">
</div>
</div>
</div>
place your target div as direct child of body (not nested inside other divs) and use this style:
position:absolute;
bottom:-100% // or fixed size if height is known
One way you might be able to do this is by making it absolute and give it a negative bottom equal to the height of the element like so
.menu-bottom-slider{
position: absolute;
bottom: -(height of element goes here)px
}
Why don't you put
opacity: 0
on the element and position it where you need it ON the page. Then when you want to use it, use jQuery to change the opacity and animate it.
This would be the css of your div section.
#divname {
position:fixed;
height:50px;
background-color:red;
bottom:0px;
left:0px;
right:0px;
margin-bottom:0px;
}
Your body would look like this.
**body{
margin-bottom:50px;
}**
Your code is nearly working, but you are using overflow-x, and you need overflow-y.
EDIT:
Another way is to set the position of the slider to fixed. This means that the position does not depend on the scroll position, so you can't scroll to it:
body {
overflow-x: hidden; /* you could also change this to overflow-y */
margin: 0;
padding: 0;
}
.main-container {
width: 100vw;
height: 100vh;
background-color: #780d0d;
position: absolute;
}
.mainmenu {
width: 70vw;
height: 82vh;
position: relative;
top: 8vh;
left: 15vw;
-webkit-box-shadow: 0px 0px 66px 10px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 0px 0px 66px 10px rgba(0, 0, 0, 0.75);
box-shadow: 0px 0px 66px 10px rgba(0, 0, 0, 0.75);
}
.menu-bottom {
height: 20%;
width: 33.2%;
background-color: red;
border: 1px solid;
display: inline-block;
margin: 0 -5px 0 0;
}
.menu-side-holder {
height: 80%;
width: 30%;
display: inline-block;
}
.menu-side {
height: 50%;
background-color: red;
border: 1px solid;
display: block;
margin: 0;
vertical-align: top;
}
#menu-img {
height: 80%;
width: 40%;
display: inline-block;
margin: 0 -4px;
vertical-align: top;
clear: none;
}
.menu-bottom-slider {
display: inline-block;
width: 100%;
background-color: green;
}
#slider {
position: fixed; /* This fixes the slider, you can't scroll to it! */
padding-left: 43.5%;
bottom: 0;
margin-bottom: -30vh;
}
<div class="main-container">
<div class="mainmenu">
<div class="menu-side-holder">
<div class="menu-side" id="ogloszenia">
1
</div>
<div class="menu-side">
3
</div>
</div>
<img id="menu-img" src="img/main4.jpg">
<div class="menu-side-holder">
<div class="menu-side">
3
</div>
<div class="menu-side">
4
</div>
</div>
<div class="menu-bottom">
5
</div>
<div class="menu-bottom">
6
</div>
<div class="menu-bottom">
7
</div>
<div class="menu-bottom-slider">
<img id="slider" src="http://s32.postimg.org/xrrmzmohx/slider.png">
</div>
</div>
</div>
When using absolute positioning on an element within a div with a relative position rule, the element is slightly lower than the bottom of the parent div. Why does this happen? How would I solve this? I realize I can just mod the bottom value on .hoverAction, but that seems more like a workaround than an actual fix.
function showFileUploadDialog() {
//do stuff
}
#avatarContainer {
display: inline-block;
position: relative;
}
.hoverAction {
position: absolute;
bottom: 0;
background: rgba(0, 0, 0, 0.65);
color: white;
display: block;
width: calc(100% - 12px);
padding: 6px;
}
#avatar {
width: 200px;
height: 180px;
background-size: cover;
background-position: center;
border-radius: 1px;
background-color: #eeeeee;
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.46);
display: inline-block;
}
<div id="avatarContainer">
<a class="popup-link" href="{{ anime.poster }}"><img id="avatar" style="background-image: url('http://www.herdofsquirrels.com/wp-content/uploads/2014/08/squirrel-nut-cute-animal-nature-grass-1920x1280.jpg');" /></a>
<a class="hoverAction" href="#" onclick="showFileUploadDialog(); return false;">Update Avatar</a>
</div>
http://jsfiddle.net/pcwhmft6/1/
Add vertical-align: top; top your img
#avatar {
vertical-align: top;
}
http://jsfiddle.net/pcwhmft6/2/
or set your image to display: block (Thanks #Justin Breiland for noticing)