Put image in the center of bottom border with CSS - html

Everything is explained in the title of this post. I'm trying to put an PNG image in the center bottom border of a div element.
.content_block {
border: ridge;
border-width: 1px;
border-color: #969696;
height: 200px;
width: 200px;
}
.content_block.orange {
background-image: linear-gradient(#FBB03B, #FF9933);
}
<div class="content_block orange"></div>
Here's an image of what I'm trying to do:
I searched the net for a way to that with CSS, and border-image and stuff, but nothing worked.

To achieve the effect of it being exactly in the middle of the border, you will have to include the border with the image by inheriting it, and making it invisible. Like this, you can 'calculate' with it.
See this Fiddle for the effect. In this Fiddle, I've created a pseudo element that has a background-image of a play button.
The CSS that does the trick is this:
div::after{
content: '';
position: absolute;
top: 100%;
left: 50%;
width: 30px;
height: 30px;
background-image: url('http://www.iconsdb.com/icons/preview/gray/video-play-3-xxl.png');
background-size: cover;
background-repeat: no-repeat;
transform: translate(-50%, -50%);
border-top: inherit;
border-top-color: transparent;
}
I've placed it to the absolute bottom and 50% from the left. Then with the transform property, I shifted it to be centered around these points (50% from the left, and 100% from the top);
Then to make it move along with the border, I inherited only at the top, and made it invisible.

.content-block {
position: relative;
width: 200px; height: 100px;
border: 1px solid #f0f;
}
.content-block img{
position: absolute;
left: 50%; bottom: 0;
width: 50px; height: 50px; margin: -25px;
}
<div class="content-block">
<img src="http://placehold.it/50x50" alt="">
</div>
If you have a relative positioned parent, you can manipulate the position of an inner child using position:absolute;

Add an img in html
<div class="content_block orange">
<img class='element' src='https://cdn0.iconfinder.com/data/icons/form-elements-kit/100/checked-green-rounded-01-128.png'/>
</div>
Add this to your css.
.element { width:32px;
height:33px;
display:block;
background-color:grey;
margin-left:auto;
margin-right:auto;
margin-top:185px;
border-radius:100%;
}
Hope that helps!

Put an image inside the orange div and add text-align:center to the div
<div class="content_block orange">
<img src="" height="30" width="30">
</div>
and then set margin-top to the img. Check this Fiddle

Related

Wouldn't work to overlay two images in Mail HTML

I'm trying to put two images on top of each other in the HTML of an email, but it fails. It displays fine in normal HTML, but when it comes to the email layout, it collapses.
code
<td className="icon">
<img class="block" src='./img/b.png' />
<img src='./img/a.png' />
</td>
<style>
.block {
margin-bottom: -15px;
margin-left: -40px;
}
</style>
margin isn't working totally.
Do you have any ideas in MAIL HTML?
ideal:
issue:
I am not sure, but I think your "td" with the icon class should have a bigger width in your layout. So the margin of -40px does not work right. I guess you can try hardcode the icon width, increase the negative margin value or position your images as absolute within your container.
I also leave this "logo" draw with CSS below. I hope it can help you a little. (You can change the width and height of the container for your needs).
HTML
<div class="circles-container">
<div class="circle circle1"></div>
<div class="circle circle2"></div>
</div>
CSS
.circles-container{
position: relative;
display: flex;
width: 200px;
height: 100px;
background-color: transparent;
}
.circle{
position: absolute;
top:0;
width: 50%;
height: 100%;
border-radius: 50%;
transform: translateX(-50%);
}
.circle1{
left: 33%;
background-color: #3484b9;
}
.circle2{
left: 66%;
background-color: #ffd61e;
}

CSS element not showing over image

I bet this is probably something stupid, I am trying put an absolute element over an image, but its not appearing.
<div class="circle" style="position: absolute; top: 200px; left: 100px;"></div>
<img src="images/madison-siteplan.png" class="siteplan" />
here is the attentional css for the circle:
.circle {
border-radius: 50%;
width: 100px;
height: 100px;
color: red;
}
It has no border or outline, so the edge won't show up.
It has no background colour, so it is transparent.
It has no content inside it, so the foreground colour has no practical effect.
Change any one of the above.
Move the absolutely positioned element to be after the image. Give that element some visual properties so you can see it... (border, background-color, text...)
#bla {
width:350px;
height:350px;
border-radius: 50%;
background-color: rgba(255,0,0,0.5);
position:absolute;
top: 0;
}
<img src="http://placehold.it/500">
<div id="bla"></div>
#Quentin is right, I just read his answer, but since I already made a snippet, I add it here. (I only added a background-color to the original code, apart from moving the inline CSS to the external CSS rule):
.circle {
position: absolute;
top: 200px;
left: 100px;
border-radius: 50%;
width: 100px;
height: 100px;
color: red;
background: green;
}
<div class="circle"> </div>
<img src="http://placehold.it/400x400" class="siteplan" />

Insert image between two divs

I need to insert photo in between divs (blue and light-blue) as in the following example.
I did it with absolute positioning:
HTML:
#*Blue and light-blue sections with photo*#
<div style="width: 100%; height: 120px; background-color: #0052a4"></div>
<div style="width: 100%; height: 120px; background-color: #c2dffd">
<div class="image">
<img src="/Content/pictures/MainPhoto.png" />
</div>
</div>
CSS:
.image {
position: absolute;
bottom: -100px; /* bottom space */
right: 100px; /* right space */
}
.image img {
display: block;
}
But this way doesn't work correctly when you change the screen resolution of the device.
I create JSFiddle with this example.
Could you please to suggest another way to resolve this problem?
I need to create responsive design without hardcoded values.
Thanks! :)
you could just use a background and a padding to keep image from sides : DEMO
HTML
<div class="imaged">
<img src="http://lorempixel.com/800/180/food/7"/>
</div>
CSS
.imaged {
padding:20px;
text-align:center;
background:url(my-blue-light-blue-bg.jpg)repeat-x center ;
}
img {
border:solid white 4px;
vertical-align:top;/* or display:block; + margin:auto;*/
}
from your fiddle: inset box-shadow in a single div works too : DEMO 2 / DEMO 3
<div style="
padding:0 20px;
display:table;
min-width: 100%;
box-shadow:
inset 0 120px 0 #0052a4,
inset 0 -120px 0 #c2dffd;
height:244px;
line-height:244px;
text-align:center;
">
<img src="http://lorempixel.com/842/176/city" style="border:solid white 4px;"/>
</div>
HTML
<div class="container-box">
<div style="width: 100%; height: 120px; background-color: #0052a4"></div>
<div style="width: 100%; height: 120px; background-color: #c2dffd"></div>
<div class="image">
<img src="http://media1.santabanta.com/full1/Outdoors/Landscapes/landscapes-267a.jpg" />
</div>
</div>
CSS
.container-box {
position:relative;
}
.container-box img {
height:200px;
width:90%;
position:absolute;
top:20px;
left:5%;
border:3px solid #fff
}
Of course I'd never use inline CSS, but there you go. See fiddle here
I think this is what you are trying to do:
http://jsfiddle.net/dc6r1bny/
.image {
position: absolute;
bottom: 30px; /* bottom height */
left: 50%; /* position element 50% from left side */
margin-left: -421px; /* bring it back left half the image size */
}
Then for mobile, you will just need to use media queries to adjust the image size to be 100%, remove the margin, etc. when you hit roughly 842px.
add this css code to the image. it should work.
margin-right:auto;
margin-left:auto;

Semi-Transparent div background on top of img tag

How do I get a div background image to show above a img html tag. The reason for wanting to do this is for a semitransparent texture that overlays rotating images in a banner. I don't want to have to cut the texture with the image each time. That way adding/updating images in the future would be faster. I have tried the advice given in this post, but did not seem to work: CSS show div background image on top of other contained elements. Thanks for any help.
html:
<div id="sliderFrame">
<div id="slider">
<span id="slider-background">
<img src="/_images/rotating-banner/001.jpg" />
</span>
</div>
</div>
CSS:
#sliderFrame {position:relative;width:850px;margin: 0 auto;}
#slider {
width:850px;height:470px;/* Make it the same size as your images */
background:#fff url(/_images/marqueeLayout/loading.gif) no-repeat 50% 50%;
position:relative;
margin:0 auto;/*make the image slider center-aligned */
box-shadow: 0px 1px 5px #999999;
}
#slider-background{
position:absolute;
background: url(/_images/marqueeLayout/MarqueeTexture.png) no-repeat;
width: 850px;
height: 470px;
z-index: 100;
}
link to live site: http://lltc.designangler.com/
try:
HTML:
<div id="wrapper">
<div id="img"></div>
<div id="overlay"></div>
</div>
CSS:
#wrappaer{display:inline-block; position:relative; width:100px; height:100px;
box-shadow: 0px 1px 5px #999999;}
#img{display:block; position:absolute; z-index:1}
#overlay{display:block; position:absolute; z-index:2
opacity:0.3;
filter:alpha(opacity=30); /* For IE8 and earlier */}
make sure to adjust wrapper,img and overlay sizes, add your images etc'.
have you tried setting the opacity of the div element?
Edit:
After rereading your question, I believe this may not be what you're looking for. Have you tried explicitly setting the z-index of the slider element in the CSS as well?
I finally solved the issue by using an img of the background inside a div instead of making it a background image. My updated code is below:
<div id="sliderFrame">
<div id="overlay"><img src="/_images/marqueeLayout/MarqueeTexture.png" /></div>
<div id="slider">
<img src="/_images/rotating-banner/001.jpg" />
</div>
</div>
CSS:
#overlay{
display:block;
position:absolute;
width: 850px;
height: 470px;
z-index: 2;
}
The background image, as its name suggest, can never be in front of the child elements. Therefore, you will need to rely on absolute positioning to overlay that background image over the slideshow:
#sliderFrame {
position: relative;
width: 850px;
margin: 0 auto;
}
#slider {
width:850px;
height:470px;
background:#fff url(/_images/marqueeLayout/loading.gif) no-repeat 50% 50%;
position:relative;
margin:0 auto;
box-shadow: 0px 1px 5px #999999;
}
#slider-background {
display: block;
position: relative;
width: 850px;
height: 470px;
z-index: 100;
}
#slider-background:before {
background: url(/_images/marqueeLayout/MarqueeTexture.png) no-repeat;
content:"";
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
z-index: 100;
}
#slider-background img {
display: block;
}
I have chosen to use a pseudo element that is positioned absolutely over the #slider-background element itself, and it is stretch to the element's dimension by setting all four offsets to 0. Remember that you will also need to declare the #slider-background and its child <img> element as block-level elements.
http://jsfiddle.net/teddyrised/XJFqc/

Stretch div according to another one

I have the following code:
#left {
width:383px;
margin:0px;
float: left;
position:relative;
}
.bg_top{
background: transparent url(../bg_top.png) no-repeat;
width: 383px;
height: 140px;
}
.bg_middle{
background: transparent url(../bg_middle.png) no-repeat;
width: 383px;
height: 100%;
}
.bg_bottom{
background: transparent url(../bg_bottom.png) no-repeat;
width: 383px;
height: 131px;
}
#left_inner{
width:375px;
border:2px solid #98b73f;
position: absolute;
top: 5px;
}
<div id='wrap'>
<div id='left'>
<div class='bg_top'>
bg_top
</div>
<div class='bg_middle'>
bg_middle
</div>
<div class='bg_bottom'>
bg_bottom
</div>
<div id='left_inner'>
<p>long text</p></div</div</div>
I want the bg_middle class to stretch to the height of the left_inner div. I have tried with height 100% and searched the net for answers. I'm new in the world of css. I think I have to connect the 3 divs that are the background to the inner div somehow...
With the HTML as is it you can't do it without Javascript. Block elements adjust in height to their container. Si if the goal is to use a background-image just apply it to the left-inner. Don't use position absolute 'cause that block would postion itself indepent from the content flow.
Given that you have fixed heights you can use min-height in case there's not enough content.
I'm not sure this is what you're looking for.
I would strongly recommend to do something different here..
However this is the solution I suggest with the original approach:
#left {
width:383px;
margin:0px;
position: relative;
}
.bg_bottom{
background: transparent url(../bg_bottom.png) no-repeat;
height: 131px;
position: absolute;
bottom: 0;
z-index: -1
}
.bg_top{
background: transparent url(../bg_top.png) no-repeat;
height: 140px;
position: absolute;
top: 0;
z-index: -1
}
.bg_middle{
height: 100%; /* it does work*/
background: transparent url(../bg_middle.png) repeat top left;
position: absolute;
z-index: -2;
}
height= 100% works if the parents (or at least one) have a height (100% of 0 is 0).
You can cascade starting with the html
html, body{height: 100%;}
Or you can just give the #left a height or min-height
This should work
Thanks to all,
Last night I found a way around this. This is my final approach, it still needs some small adjustments, but it works (for now).
<div id="wrap">
<div id="header"></div>
<div id="main">
<div class='bg_top'></div>
<div class='bg_middle'>
<div>LONG LONG TEXT</div>
</div>
<div class='bg_bottom'></div>
</div>
#wrap{
width: 800px;
margin: 0px auto;
border: 1px solid black;
}
.bg_top{
background: transparent url(../bg_top.png) no-repeat;
height: 140px;
}
.bg_middle{
background: transparent url(../bg_middle.png) repeat;
}
.bg_middle div{
margin:-130px 10px -100px 10px;
border:1.5px solid #98b73f;
}
.bg_bottom{
background: transparent url(../bg_bottom.png) no-repeat;
height: 131px;
}
#main {
float:left;
width:500px;
margin-left:0px;
padding:10px;
}
Thanks #Maroshii for the reply. I will also try your approach, but for now I'll stick to this. Hope I will not have to change a lot for browser compatibility :)