.scss
div.playlist {
position: relative;
display: inline-block;
}
div.playlist {
span {
position: absolute;
text-align: center;
height: 100%;
width: 100%;
color: white;
font-size: 20px;
}
.span-icon {
padding-bottom: 50px !important;
}
}
div.playlist span:before {
display: inline-block;
vertical-align: middle;
height: 100%;
content: '';
}
.html
<div class="playlist">
<span class="span-icon"><ion-icon [name]="data.icon"></ion-icon></span>
<span>{{data.text}}</span>
<img [src]="data.imageUrl" [alt]="data.text" />
</div>
Out Put
Now I need as shown below.Please don't consider about the different icon type and the text.I just need this.I need a responsive top right and the bottom right appearance of the icon and text.I have tried with text-align: right and the margin properties.But you know that approach is not responsive on different view ports.So can you help me to solve this issue?
Position your both icons and span text as absolute and then if needed you could use CSS calc() function to align them at top-right and bottom-right above the image.
.playlist {
position: relative;
display: inline-block;
width: 240px;
height: 200px;
overflow: hidden;
}
.playlist img {
width: 100%;
height: 100%;
}
.playlist .span-icon {
position: absolute;
top: 5px;
right: calc(100% - 98%);
color: #fff;
}
.playlist .tm {
position: absolute;
bottom: 5px;
right: calc(100% - 98%);
color: #fff;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="playlist">
<span class="span-icon"><i class="fa fa-film"></i></span>
<span class="tm">2:10</span>
<img src="http://lorempixel.com/output/city-q-c-640-480-6.jpg">
</div>
<div class="playlist">
<span class="span-icon"><ion-icon [name]="data.icon"></ion-icon></span>
<span class="span-text">{{data.text}}</span>
<img [src]="data.imageUrl" [alt]="data.text" />
</div>
CSS
.span-icon {
position: absolute;
top: 0;
right: 0;
}
.span-icon {
position: absolute;
bottom: 0;
right: 0;
}
You simply set the icons absolute and position it with top, right. ...
Related
I'd like to have an image with a div that covers the image exactly. I can get the div to overlay the image by using position: relative in the parent and position: absolute for the div, but background-color fills out the padding in the parent so they aren't overlayed properly.
Here's a snippet that demonstrates the problem.
.parent {
position: relative;
padding: 10px;
width: 40%;
}
.image {
width: 100%;
height: 100%;
border-radius: 13px;
}
.overlay {
position: absolute;
background-color: red;
width: 100%;
height: 100%;
border-radius: 13px;
left: 0;
top: 0;
opacity: 0.2;
}
<div class="parent">
<img class="image" src="https://cards.scryfall.io/normal/front/4/f/4f3deefe-28bc-4e45-a0a0-ab03167e2e81.jpg?1561942156">
<div class="overlay"></div>
</div>
I'm able to get it pretty close with some calc()'s to subtract the padding. This almost works, but the div fills out a little too much at the bottom. I'd like to not have a bunch of hardcoded values for padding anyway, so I wouldn't really like this solution even if it did work entirely.
Here's a snippet that shows the calc() approach.
.parent {
position: relative;
padding: 10px;
width: 40%;
}
.image {
width: 100%;
height: 100%;
border-radius: 13px;
}
.overlay {
position: absolute;
background-color: red;
width: calc(100% - 2 * 10px);
height: calc(100% - 2 * 10px);
border-radius: 13px;
left: 10px;
top: 10px;
opacity: 0.2;
}
<div class="parent">
<img class="image" src="https://cards.scryfall.io/normal/front/4/f/4f3deefe-28bc-4e45-a0a0-ab03167e2e81.jpg?1561942156">
<div class="overlay"></div>
</div>
This snippet does things a slightly different way, putting the img inside the overlay div and putting the actual green, lower opacity overlay as the overlay div's after pseudo element.
This way you don't have to build in any knowledge of the parent's padding.
.parent {
position: relative;
padding: 10px;
width: 40%;
background: red;
height: fit-content;
}
.image {
width: 100%;
border-radius: 13px;
top: 0;
left: 0;
}
.overlay {
position: relative;
padding: 0;
width: fit-content;
height: fit-content;
}
.overlay::after {
content: '';
position: absolute;
background-color: green;
width: 100%;
height: 100%;
border-radius: 13px;
left: 0;
top: 0;
opacity: 0.2;
padding: 0px;
}
<div class="parent">
<div class="overlay"> <img class="image" src="https://cards.scryfall.io/normal/front/4/f/4f3deefe-28bc-4e45-a0a0-ab03167e2e81.jpg?1561942156"></div>
</div>
When using HTML5, browser adds some padding to the bottom of the img tag. This can be avoided by making the image a block element. So just adding display: block to class .image and then it good.
And btw, to define witdh/height of an absolute element, beside calc() you can also define 4 values top, right, bottom, left of it.
:root {
--custom-padding: 10px;
}
.parent {
position: relative;
padding: var(--custom-padding);
width: 40%;
}
.image {
width: 100%;
height: 100%;
border-radius: 13px;
display: block;
}
.overlay {
position: absolute;
background-color: red;
border-radius: 13px;
bottom: var(--custom-padding);
right: var(--custom-padding);
left: var(--custom-padding);
top: var(--custom-padding);
opacity: 0.2;
}
<div class="parent">
<img class="image" src="https://cards.scryfall.io/normal/front/4/f/4f3deefe-28bc-4e45-a0a0-ab03167e2e81.jpg?1561942156">
<div class="overlay"></div>
</div>
I have been working on to place an icon to the bottom right of an image having the property of border-radius: 50%.
Here's what I want to achieve(Icon to be on the circumference),
By absolute and relative positioning, I can place the icon as expected but on smaller screens, the icon goes out of place due to image resizing (with img-fluid class of bootstrap 4).
How can I make the icon to be at the same place across all screens even after image resizes?
.wrapper{
position: relative;
display: inline-block;
margin: 30px;
}
.image{
border-radius: 50%;
}
.icon{
height: 50px;
width: 50px;
background: #008080;
position: absolute;
border-radius: 50%;
right: 22px;
bottom: 42px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class='wrapper'>
<img src='https://via.placeholder.com/350x350' class='image img-fluid'/>
<span class='icon'></span>
</div>
In order to get the desired result you need to position the center of the small circle (with a dimension of 0px × 0px) at the desired height/width of the bigger one and draw the small circle around this center.
Do note that if you want your positioning done responsively you need to do it in percentage, not in px.
Since functionality required from the child is purely visual, you can safely use a pseudo element:
.icon {
width: 0px;
height: 0px;
position: absolute;
}
.icon:after {
width: 50px;
height: 50px;
}
In terms of centering, you have a couple of options:
a) transform:translate(-50%,-50%)
.wrapper {
position: relative;
display: inline-block;
margin: 30px;
}
.image {
border-radius: 50%;
}
.icon {
height: 0;
width: 0;
position: absolute;
right: 16%;
bottom: 13.5%;
overflow: visible;
}
.icon:before {
height: 50px;
width: 50px;
position: absolute;
border-radius: 50%;
content: '';
transform: translate(-50%, -50%);
background-color: #008080;
display: block;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<div class='wrapper'>
<img src='https://via.placeholder.com/350x350' class='image img-fluid' />
<span class='icon'></span>
</div>
b) flexbox on parent:
.wrapper {
position: relative;
display: inline-block;
margin: 30px;
}
.image {
border-radius: 50%;
}
.icon {
height: 0;
width: 0;
position: absolute;
right: 16%;
bottom: 13.5%;
display: flex;
overflow: visible;
align-items: center;
justify-content: center;
}
.icon:before {
height: 50px;
width: 50px;
border-radius: 50%;
position: absolute;
content: '';
background-color: #008080;
display: block;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<div class='wrapper'>
<img src='https://via.placeholder.com/350x350' class='image img-fluid' />
<span class='icon'></span>
</div>
To rotate the small circle on the bigger one you can do it mathematically or you could do as I did: I made the :after 3px × 3px, changed % of any combo of top|bottom + left|right to the desired location on the bigger center circumference and increase the size of the small center back to 50px * 50px.
Also, to size the smaller circle down responsively, you could express the width and height in vw under a particular viewport width, making sure at the point where it starts shrinking the size in px with the one in vw translate to the same actual size. Example:
.wrapper {
position: relative;
display: inline-block;
margin: 30px;
}
.image {
border-radius: 50%;
}
.icon {
height: 0;
width: 0;
position: absolute;
right: 16%;
bottom: 13.5%;
display: flex;
overflow: visible;
align-items: center;
justify-content: center;
}
.icon:before {
height: 35px;
width: 35px;
border-radius: 50%;
position: absolute;
content: '';
background-color: #008080;
display: block;
}
#media (max-width: 350px) {
.icon:before {
width: calc(10vw - 6px);
height: calc(10vw - 6px);
min-width: 5px;
min-height: 5px;
/* 60px making up for the padding on .wrapper */
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<div class='wrapper'>
<img src='https://via.placeholder.com/350x350' class='image img-fluid' />
<span class='icon'></span>
</div>
Define right and bottom as % not px
Do the same for height and width if you want size to adapt. See my snippet
.wrapper{
position: relative;
display: inline-block;
margin: 30px;
}
.image{
border-radius: 50%;
}
.icon{
height: 15%;
width: 15%;
background: #008080;
position: absolute;
border-radius: 50%;
right: 10%;
bottom: 5%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class='wrapper'>
<img src='https://via.placeholder.com/350x350' class='image img-fluid'/>
<span class='icon'></span>
</div>
I have a span tag. I'm loading an image inside this span tag using css. Now I wants to vertically centre this image inside the span tag. I can't vertically centre this image because I'm applying this image to span using CSS. Here I'm using an icon sprite and extracting only relevant part from the icon-sprite. Can anyone help?
HTML
<span class="icon"></span>
CSS
.icon{
background: url(../images/icon-sprite.png) no-repeat -328px 0;
width: 60px;
height: 40px;
position: absolute;
}
I tried adding line-height to .icon class. But no joy.
You will need to change the numbers in order for it to work for your icon, but this should do the trick.
.icon {
position: relative;
border:1px solid #FF0000;
white-space: nowrap;
}
.icon:before{
content: "";
position: relative;
width:15px;
display:inline-block;
}
.icon:after{
content: "";
position: absolute;
top: 50%;
left: 0;
margin-top: -8.5px;
width: 15px;
height: 18px;
background: url('https://www.google.com/images/nav_logo127.png') no-repeat -0px -327px;
}
<span class="icon" style="font-size:20px;">whatever</span>
<span class="icon" style="font-size:25px;">whatever</span>
<span class="icon" style="font-size:30px;">whatever</span>
<span class="icon" style="font-size:35px;">whatever</span>
<span class="icon" style="font-size:40px;">whatever</span>
<span class="icon" style="font-size:45px;">whatever</span>
The border and font size are just for the example.
Can use anyone:
.icon{
background: url(../images/icon-sprite.png) no-repeat;
background-position:left center;
width: 60px;
height: 40px;
position: absolute;
}
or
.icon{
background: url(../images/icon-sprite.png) no-repeat left center;
width: 60px;
height: 40px;
position: absolute;
}
Ideally here, you should have a parent class and try to vertically align .icon to the parent.
.parent {
position: relative;
width: 120px;
height: 80px;
}
.icon {
background: url(../images/icon-sprite.png) no-repeat -328px 0;
width: 60px;
height: 40px;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
text-align: center;
}
<div class="parent">
<span class="icon"></span>
</div>
Hey I can't figure out why my divs are overlapping and what i should do...
You can watch the site here: http://hersing.dk/job/
I would like for the div carrying the hr to appear underneed the header-info div
Heres is the code from the site:
#font-face {
font-family: hersing;
src: url(lmroman10-regular.otf);
}
html,
body {
font-family: hersing;
height: 100%;
margin: 0px;
}
.container {
width: 90%;
height: 90%;
left: 5%;
top: 5%;
background: green;
position: absolute;
display: block;
clear: both;
}
.info-name {
left: 5%;
top: 10%;
position: absolute;
display: block;
}
.info-picture {
min-width: 250px;
min-height: 250px;
padding: 4px;
position: absolute;
top: 10%;
right: 5%;
background: black;
display: block;
}
.info-picture img {
height: 100%;
width: 100%;
}
#info-header {
font-size: 400%;
}
#info-title {
font-size: 150%;
font-weight: bold;
}
.header-info {
display: block;
padding: 20px;
position: relative;
width: 100%;
}
.stang-1 {
display: block;
width: 100%;
color: blue;
position: relative;
}
#hr-1 {
display: block;
height: 1px;
border: 0;
border-top: 1px solid #ccc;
margin: 1em 0;
padding: 0;
background-color: #f1a857;
}
<div class="container">
<div class="header-info">
<div class="info-name" id="info-name">
...
</div>
<div class="info-picture" id="info-picture">
<img src="images/picture.png" />
</div>
</div>
<div class="stang-1" id="stang-1">
<hr id="hr-1">
</div>
</div>
I hope someome can figure this out, cause i'm pretty lost
Both .info-name and .info-picture are absolute positioned and .header-info has no height defined.
You'd rather use relative positioning + float + clear and/or display: inline-block for both .info-* rules and everything will be fine.
<div class="container">
<div class="header-info">
<div class="info-name" id="info-name">
.....
</div>
<div class="info-picture" id="info-picture">
<img src="images/picture.png" />
</div>
</div>
<div class="stang-1" id="stang-1">
<hr id="hr-1">
</div>
</div>
<style>
#font-face {
font-family: hersing;
src: url(lmroman10-regular.otf);
}
html,
body {
font-family: hersing;
height: 100%;
margin: 0px;
}
.container {
width: 90%;
height: 90%;
left: 5%;
top: 5%;
background: green;
position: absolute;
display: block;
clear: both;
}
.info-name {
left: 5%;
top: 10%;
position: absolute;
display: block;
}
.info-picture {
width: 250px;
height: 250px;
padding: 4px;
position: relative;
top: 10%;
left:70%;
background: black;
display: block;
}
.info-picture img {
height: 100%;
width: 100%;
}
#info-header {
font-size: 400%;
}
#info-title {
font-size: 150%;
font-weight: bold;
}
.header-info {
display: block;
padding: 20px;
position: relative;
width: 100%;
}
.stang-1 {
display: block;
width: 100%;
color: blue;
position: absolute;
}
#hr-1 {
display: block;
height: 1px;
border: 0;
border-top: 1px solid #ccc;
margin: 1em 0;
padding: 0;
background-color: #f1a857;
}
</style>
I think this will solve your problem...
In this case, although very impractical, the solution would be to add a line break <br> after the .header-info div.
I repeat, this solution is not the best one by far, and you should, as pointed out in the comments by Paulie_D, change your positioning layout method.
Everything inside the absolutely positioned .container would be better positioned relative. Use css float:left; or float:right; to position elements and clear:both; when you want the next element to start below all floated elements. Use padding on the container and margins on the floated elements for positioning.
Also give .container css class of overflow:auto; to wrap around all elements inside without having to set the height every time.
I have three DIV and inside the DIV, I would like to float the "Learn More" to bottom right so it will be on top of the grey background.
CSS
/* the div for LEARN MORE */
#trt {
z-index: 9999999999999;
position: relative;
float: right;
bottom: 0; // not working
top: 12; //not working
}
/* the entire div */
.main .cols { padding-left: 2px; padding-right: 0px; padding-top: 10px; }
.main .cols .col { width: 315px; height: 108px; float: left; background: url(images/tempf.png) no-repeat 0 0; }
.main .cols .col:after { content:''; width: 100%; clear: both; }
.main .cols .col + .col { padding-left: 20px; }
.main .cols .col img.hid { float: left; width: 129px; height: 108px; }
.main .cols .col-cnt { width: 183px; float: right; }
.main .cols .col .more { font-weight: bold; color: #0206AA; }
HTML
<div class="main">
<section class="cols">
<div class="col">
<a href="link.aspx">
<img class="hid" src="css/images/orgNews.png" alt="" />
</a>
<div class="col-cnt">
<h3 style="color: #FFFFFF;">Organization News</h3>
<p style="color: #FFFFFF;">Interfaith Medical Center related news and updates</p>
<div id="trt">
<img src="css/images/arrow.png" width=11 height=11 align=absmiddle />
Learn More
</div>
</div>
</div>
</section>
</div>
CSS - After Edit
.trt {
z-index: 9999999999999;
position: absolute;
bottom: 3px;
right: 3px;
}
...
.main .cols .col-cnt { width: 183px; float: right; position: relative; }
...
This CSS worked:
.trt {
z-index: 9999999999999;
position: absolute;
top: 85px;
right: 3px;
}
set col-cnt div to position: relative set trt to position: absolute; bottom:3px; right:3px; that should get you where you need to be.. also, trt should be a class if it is being reused
First at all, you must set parent of #trt to relative.
#parent-of-trt {
position: relative;
}
And set #trt to absolute
#trt {
position: absolute;
left: 4px;
bottom: 5px;
}
Your float: right isn't working because of a width issue on the #trt div. Basically it's extending 100% of the width and so it can't technically go left or right. Instead of floating, just use...
#trt { text-align: right; }
???
As for getting it pushed down onto that grey line, add some margin-top to #trt to do that...
Other solution would be to use position: absolute; but would be less preferable.
Maybe use position: absolute; instead of relative
change position as fixed like following:
position:fixed;
it should work.