I am struggling to make a polaroid image like. In which the image have a text in the bottom. I tried every instruction but failed to do so.
Here is my HTML code
<div id="Places" class="gallery">
<ul>
<li>
<a href="https://www.w3schools.com/css/css_image_gallery.asp" target="_blank">
<img src="images/babot1.jpg" alt="bobat1">
</a>
</li>
<li>
<a href="https://www.w3schools.com/css/css_image_gallery.asp" target="_blank">
<img src="images/lhouse1.jpg" alt="bobat1">
</a>
</li>
<li>
<a href="https://www.youtube.com/playlist?list=PL6n9fhu94yhVm6S8I2xd6nYz2ZORd7X2v" target="_blank">
<img src="images/babot1.jpg" alt="bobat1">
</a>
</li>
</ul>
</div>
and this is my css code that I use
div.gallery{
border:2px solid #ddd;
margin:0 auto;
margin-top:100px;
margin-bottom:30px;
border-radius:3px;
width:98%;
}
div.gallery::before{
content: "";
clear: both;
display: table;
}
div.gallery ul{
list-style-type:none;
overflow:hidden;
margin:0 auto;
}
div.gallery li a img {
margin: 20px 20px 21px 20px;
width: 28.50%;
float:left;
padding-bottom:50px;
}
EDIT 1:
Here is the sample photo of what I got.
<figure> + <figcaption> have been designed for this.
To make it Polaroid like, here's what I'd do:
figure {
border: 1px solid #f5f5f5;
border-radius: 5px;
padding: 10px;
display: inline-block;
box-shadow: 0 4px 5px -2px rgba(0,0,0,.2), 0 7px 10px 1px rgba(0,0,0,.14), 0 2px 16px 1px rgba(0,0,0,.12);
}
figure img {
display: block;
}
figcaption {
display: block;
padding: 1rem 0 .5rem;
color: #777;
}
<figure>
<img src="http://placehold.it/350x250" />
<figcaption>This would be a caption</figcaption>
</figure>
<figure>
<img src="http://placehold.it/250x350" />
<figcaption>This would be another caption</figcaption>
</figure>
Please note you're currently floating the <img> tags. If you want the above to work, you need to remove the following from your current CSS:
div.gallery li a img {
margin: 20px 20px 21px 20px;
width: 28.50%;
float:left;
padding-bottom:50px;
}
You can float your <figure>s instead.
there is an html tag to do what you want:
<figure>
<img src="myImage.jpg" alt="my image">
<figcaption>This is my image</figcaption>
</figure>
Put your text inside a div, position it absolute and give it a z-index of 90 or higher.
<div id="txt">This is a title</div>
<style>
position: absolute;
z-index: 99;
</style>
Related
I'm trying to figure out why my right sidebar only goes half-way up the screen and what I'm doing wrong.
I have the HTML and CSS at the bottom and a picture of the website at the bottom. I'm trying to get the text in the middle but when I do that the text blocks the right sidebar from going all the way up. I have a picture of what it's supposed to look like at the bottom also. I could really use some help with this.
/* right sidebar */
#right_sidenav {
width: 180px;
float: right;
background-color: #F5DEB3
padding: 0;
}
/* the styles for the section */
html {
background-image:url(../images/bats.gif);
background-repeat: repeat;
}
body {
font-family: Arial, Helvetica, sans-serif;
width: 800px;
background-color: white;
border: 5px solid black;
box-shadow: 5px 5px 5px 5px black;
margin: 0 auto;
}
section {
width: 600px;
float: right;
padding-right: 20px;
padding-left: 20px;
padding-bottom; 20px;
}
main {
clear: both;
}
aside {
width: 160px;
float: left;
}
section h2 {
margin-left: 0;
}
section figcaption {
float: right;
clear: right;
margin-left: 10em;
padding-right: 15em;
}
section img {
float: left;
margin: 0;
padding: 0;
}
<section>
<h2>20" Deranged Cat</h2>
<figure>
<picture>
<img src="images/cat1.jpg" alt="cat">
</picture>
<figcaption>This cat provides its own light and is perfect for a
backyard haunting.
Price 19.99</figcaption>
</figure>
</section>
<div id="right_sidenav">
<h5>Customers who bought this product also bought:</h5>
<ul>
<li>
<figure>
<picture>
<img src="images/flying_bats.jpg" alt="flying bat">
</picture>
<figcaption>
Flying bats
</figcaption>
</figure>
</li>
<li>
<figure>
<picture>
<img src="images/rat1.jpg" alt="rat">
</picture>
<figcaption>
16" Ugly rat
</figcaption>
</figure>
</li>
<li>
<figure>
<picture>
<img src="images/strobe1.jpg" alt="strobe light">
</picture>
<figcaption>
Mini strobe light
</figcaption>
</figure>
</li>
</ul>
</div>
'#' usually stops a sidebar when you go to it. Only classes will work with this.
You also need to define everything. Style is not defined. No content is the <style> tags are defined either.
When you have a tag in html and want to define it with CSS then you do not put a '.' in front of the class as it is a tag not a class
<section>
<h2>20" Deranged Cat</h2>
<figure>
<picture>
<img src="images/cat1.jpg" alt="cat">
</picture>
<figcaption>This cat provides its own light and is perfect for a
backyard haunting.
Price 19.99</figcaption>
</figure>
</section>
<div id="right_sidenav">
<h5>Customers who bought this product also bought:</h5>
<ul>
<li>
<figure>
<picture>
<img src="flying_bats.jpg" alt="flying bat">
</picture>
<figcaption>
Flying bats
</figcaption>
</figure>
</li>
<li>
<figure>
<picture>
<img src="images/rat1.jpg" alt="rat">
</picture>
<figcaption>
16" Ugly rat
</figcaption>
</figure>
</li>
<li>
<figure>
<picture>
<img src="images/strobe1.jpg" alt="strobe light">
</picture>
<figcaption>
Mini strobe light
</figcaption>
</figure>
</li>
</ul>
</div>
/* right sidebar */
#right_sidenav {
width: 180px;
float: right;
background-color: #F5DEB3
padding: 0;
/* the styles for the section */
html {
background-image:url(../images/bats.gif);
background-repeat: repeat;
}
li {
list-style: none;
}
body {
font-family: Arial, Helvetica, sans-serif;
width: 800px;
background-color: white;
border: 5px solid black;
box-shadow: 5px 5px 5px 5px black;
margin: 0 auto;
}
section {
width: 600px;
float: right;
padding-right: 20px;
padding-left: 20px;
padding-bottom; 20px;
}
.main {
clear: both;
}
.aside {
width: 160px;
float: left;
}
.section h2 {
margin-left: 0;
}
.section figcaption {
float: right;
clear: right;
margin-left: 10em;
padding-right: 15em;
}
.section img {
float: left;
margin: 0;
padding: 0;
}
I've tried everything, but it seems like this span just won't do anything I tell it to. No applied properties change its vertical position, but horizontal properties do.
I've followed all the recommendations from this guide: https://css-tricks.com/centering-css-complete-guide/
Code:
#header{
height: 50px;
width: 100% - 50px;
padding: 0px 25px 0px 25px;
background-color: #00A680;
}
#header-right-icon-div > img{
height: 20px;
display: inline;
padding: 15px 10px 15px 10px;
}
#menu-join-button{
}
<div id="header">
<div id="header-right" style="float: right;">
<div id="header-right-icon-div">
<img src="briefcase_icon.svg" alt="">
<img src="notification_icon.svg" alt="">
<img src="profile_icon.svg" alt="">
<img src="search_icon.svg" alt="">
<span id="menu-join-button">hello</span>
</div>
</div>
</div>
Even top or bottom margins and padding don't affect it at all... but side margins do...
What is the issue here, why does this menu-join-button have a mind of it's own? How do I center the span in that green header?
Verticle align middle Way:
* {
box-sizing: border-box;
}
#header{
width: 100%;
padding: 0px 25px 0px 25px;
background-color: #00A680;
}
#header:after {
content: '';
display: table;
clear: both;
}
#header-right{
float:right;
padding: 10px 25px 10px 25px;
background-color: #00A680;
}
#header-right-icon-div > img{
display:inline-block;
vertical-align: middle;
padding: 0px 10px 0px 10px;
}
#menu-join-button{
}
<div id="header">
<div id="header-right">
<div id="header-right-icon-div">
<img src="http://via.placeholder.com/30x30" alt="">
<img src="http://via.placeholder.com/30x30" alt="">
<img src="http://via.placeholder.com/30x30" alt="">
<img src="http://via.placeholder.com/30x30" alt="">
<span id="menu-join-button">hello</span>
</div>
</div>
</div>
Flex Way:
* {
box-sizing: border-box;
}
#header{
width: 100%;
padding: 0px 25px 0px 25px;
background-color: #00A680;
display: flex;
justify-content: flex-end;
align-items:center;
}
#header-right{
padding: 10px 25px 10px 25px;
background-color: #00A680;
}
#header-right-icon-div {
display: flex;
align-items:center;
}
#header-right-icon-div > img{
padding: 0px 10px 0px 10px;
}
<div id="header">
<div id="header-right">
<div id="header-right-icon-div">
<img src="http://via.placeholder.com/30x30" alt="">
<img src="http://via.placeholder.com/30x30" alt="">
<img src="http://via.placeholder.com/30x30" alt="">
<img src="http://via.placeholder.com/30x30" alt="">
<span id="menu-join-button">hello</span>
</div>
</div>
</div>
so my problem is, that I can't make href area image-sized. I still get white border up, left, right of my image, I tried display: inline-block, without any luck. This is my CSS (I know it looks pretty awful):
div.gallery {
margin: 1%;
-webkit-box-shadow: 10px 10px 25px #000;
-moz-box-shadow: 10px 10px 25px #000;
box-shadow: 10px 10px 25px #000;
float: left;
min-width: 180px;
width: 23%;
}
div.gallery a {
background-color: red;
display: inline-block !important;
}
div.gallery img {
display: block;
}
div.desc {
padding: 15px;
text-align: center;
}
<div class="gallery">
<a href="myphoto.jpg">
<img src="http://dummyimage.com/200x150&text=myphoto.jpg" alt="" />
</a>
<div class="desc">XXX</div>
</div>
<div class="gallery">
<a target="_blank" href="myphoto.jpg">
<img src="http://dummyimage.com/200x150&text=myphoto.jpg" alt="" />
</a>
<div class="desc">XXX</div>
</div>
EDIT: Thanks for answer, but I think I could be a little unclear:
I made a gallery, that displays 4 imgs in a row, no matter if the screen resolution is hd, or 1024x768. It's responsive. in div.gallery img I set width to be 100% (which I forgot to add here). My problem is, that I have something like this when setting on the images: white border caused by a href.
The a inline-block element will not expand if its contents have no dimension. Once I set a dimension to the img than it works.
img {
width:180px;
height:100px;
}
div.gallery {
margin: 1%;
-webkit-box-shadow: 10px 10px 25px #000;
-moz-box-shadow: 10px 10px 25px #000;
box-shadow: 10px 10px 25px #000;
float: left;
min-width: 180px;
width: 23%;
}
div.gallery a {
background-color: red;
display: inline-block;
}
div.gallery img {
display:inline-block;
}
div.desc {
padding: 15px;
text-align: center;
}
<div class="gallery">
<a href="myphoto.jpg">
<img src="myphoto.jpg" alt="" />
</a>
<div class="desc">XXX</div>
</div>
<div class="gallery">
<a target="_blank" href="myphoto.jpg">
<img src="myphoto.jpg" alt="" />
</a>
<div class="desc">XXX</div>
</div>
you can use below code for solve your problem.
div.gallery {
margin: 1%;
-webkit-box-shadow: 5px 5px 15px #000;
-moz-box-shadow: 5px 5px 15px #000;
box-shadow: 5px 5px 15px #000;
float: left;
min-width: 160px;
width: 25%;
}
div.gallery a{
width: 100%;
background-color: yellow;
display: inline-block !important;
}
div.gallery img {
display:block;
position: absolute;
}
div.desc {
padding: 20px;
text-align: center;
}
<div class="gallery">
<a href="myphoto.jpg">
<img src="myphoto.jpg" alt="" height="100px" width="100%" />
<div class="desc">AAA</div>
</a>
</div>
<div class="gallery">
<a target="_blank" href="myphoto.jpg">
<img src="myphoto.jpg" alt="" height="100px" width="100%" />
<div class="desc">BBB</div>
</a>
</div>
There's a really simple fix for this.
Simply wrap your a around the div too, then set, on your images: height="48px" width="100%" position: absolute;
Finally, set the width of your anchors to 100%;
Let me know if you have any questions. Thanks
https://jsfiddle.net/v45k8ojk/2/
Try changing
<img src="myphoto.jpg" alt="" />
to
<img src="myphoto.jpg" alt="image1">
Image tag does not require end of the tag.
I have a problem with image descriptions. I have HTML structure like this:
<div class="scrollable-content" data-mcs-theme="dark-thick" style="padding: 0px; overflow-x: auto;">
<ul style="list-style: none; white-space:nowrap; padding: 0px;">
#foreach($projects as $project)
<li style="display: inline; margin: 0px;">
<a href="{!! url($locale.'/projects/project/'.$project->id) !!}">
<img class="project-cover-image" src="/images/{!! $project->cover_image_name !!}" height="250px" width="auto">
</a>
</li>
#endforeach
</ul>
</div>
It creates a nice looking gallery with horizontal scrollbar. But I need to add descriptions to images that will be placed at the bottom of the pictures covering whole their widths and they should have to be transparent to some degree.
The problem is, whatever I do, I either get description that takes 100% width of the page, or it has width of the text inside it.
I have tried doing it with div, span, different combinations of position absolute/relative, everything and I couldn't manage to make it work.
It should look something like this:
How can I do that?
You have two options (wich produce the same result):
1- A div with a image as background, and a subtitle inside this div;
#image {
width:550px;
height:150px;
position:relative;
background: url('http://i.imgur.com/HNj6tRD.jpg');
background-repeat: no-repeat;
background-size:100% 100%;
}
.coverdown {
color: white;
width: 100%;
height: 30%;
position:absolute;
bottom:0%;
background: rgba(0,0,0,0.5);
text-align: center;
}
<div id="image">
<div class="coverdown">Subtitle here with a description.</div>
</div>
2- The image and a subtitle with position:absolute inside a position:relative container;
#container {
width:550px;
height:150px;
position:relative;
}
img {
width:550px;
height:150px;
position:absolute;
top:0px;
left:0px;
}
.subtitle {
color: white;
width: 100%;
height: 30%;
position:absolute;
bottom:0%;
background: rgba(0,0,0,0.5);
text-align: center;
}
<div id="container">
<img src="http://i.imgur.com/HNj6tRD.jpg" alt=img>
<div class="subtitle">Subtitle here with a description.</div>
</div>
use position:relative/absolute
body {
margin: 0
}
.scrollable-content {
padding: 0;
overflow-x: auto
}
ul {
list-style: none;
white-space: nowrap;
padding: 0;
margin:0
}
li {
position: relative;
display:inline-block
}
span {
background: rgba(0, 0, 0, .5);
display: inline-block;
height: 50px;
position: absolute;
bottom: 0;
left: 0;
width: 100%
}
img {
display: block
}
a {
color: #fff
}
<div class="scrollable-content" data-mcs-theme="dark-thick">
<ul>
<li>
<a href="">
<img class="project-cover-image" src="//lorempixel.com/250/250">
<span>description</span>
</a>
</li>
<li>
<a href="">
<img class="project-cover-image" src="//lorempixel.com/500/250">
<span>description</span>
</a>
</li>
<li>
<a href="">
<img class="project-cover-image" src="//lorempixel.com/400/250">
<span>description</span>
</a>
</li>
</ul>
</div>
basicly, you need relative/absolute as #dippas's answer.
as I advised, use inline-block, so it gets sized by content and will allow easily to position your description.
example below with figure and figcaption.
figure can be wrap in a <a>link displayed inline-block and figure as a block then to avoid a gap underneath.
figure {
display: inline-block;
position: relative;
margin: 0;
}
img {
display: block;
max-height:80vh;height:250px/*snippet demo purpose */
}
figcaption {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
/* makeup*/
background: rgba(0, 0, 0, 0.5);
color: white;
}
/* demo purpose */
div {
white-space: nowrap;
overflow:auto;
}
figure {
white-space: normal;
text-align: center;
}
<div>
<figure>
<img src="http://www.hyperkreeytiv.com/wp-content/uploads/2014/08/IMG_4973.jpg" alt="wolves" />
<figcaption>
<p>these are wolves</p>
</figcaption>
</figure>
<figure>
<img src="http://4.bp.blogspot.com/-oSEWgZNEopE/TtL8kfGuBzI/AAAAAAAAB6U/b8VSzZaoK3g/s400/action_wolf_1111_photo1.jpg" alt="wolves" />
<figcaption>
<p>these are wolves</p>
</figcaption>
</figure>
<figure>
<img src="http://1.bp.blogspot.com/-GfOyrk3kZ0w/TewM0BMvbNI/AAAAAAAABM0/KPm3li5Xwko/s1600/alpha+male+Wallpaper__yvt2.jpg" alt="wolves" />
<figcaption>
<p>these are wolves</p>
</figcaption>
</figure>
<figure>
<img src="http://www.ooyuz.com/images/2015/10/13/1447449028465.jpg" alt="wolves" />
<figcaption>
<p>these are wolves</p>
</figcaption>
</figure>
</div>
I have a content with Title, image and description. I have 3 differents contents, which i have to put side by side. What would be better do achive this ? I did with <ul>. But the image wasnts below title, and description below image, so i just but after <li></li> a break, and it worked. But in IE it doesnt.
Here is what i got - > http://jsfiddle.net/5xfR9/12/
<div id="content">
<ul>
<li>
<h3>Custom clearance</h3><br/>
<img src="..." style="width:360px; height: 160px;" alt="Custom clearance" /><br/>
<p style="width:360px;">...<br />Learn more <img src="images/arrow.png" alt="learn more" style="width:6px; height:9px; border: 0px;"/><br/>
</p>
</li>
<li>
<h3>Cargo Inspections</h3><br/>
<img src="..." style="width:360px; height: 160px;" alt="Custom clearance" /><br/>
<p style="width:360px; padding">...<br />Learn more <img src="images/arrow.png" alt="learn more" style="width:6px; height:9px; border: 0px;"/>
</p><br/>
</li>
<li>
<h3>Our Location</h3><br/>
<img src="..." style="width:360px; height: 160px;" alt="Custom clearance" /><br/>
<p style="width:360px;">....<br />Learn more <img src="images/arrow.png" alt="learn more" style="width:6px; height:9px; border: 0px;"/>
</p><br/>
</li>
</ul>
</div>
using this CSS
#content {
width: 100%;
min-height: 450px;
display: block;
padding-bottom:40px;
}
#content ul li {
display: inline;
list-style: none;
float: left;
min-width:32%;
}
#content ul li > h3 {
text-decoration: none;
display:block;
float:left;
font-size: 24px;
margin: 0 0 0 20px;
font-family: gothamlight;
padding: 10px 20px 10px 20px;
}
#content ul li > img {
display: block;
float:left;
margin: 0 0 0 10px;
padding: 0px 25px 0px 25px;
}
#content ul li > p {
text-decoration: none;
line-height: 1.3;
display:block;
color: #404041;
float:left;
font-size: 14px;
margin: 0 0 0 20px;
padding: 5px 20px 5px 20px;
display: block;
}
I guess I did it wrong, I put <br /> after a <li></li>, so that content would be vertical.
But of course IE is smart and it shows Content 1 for the whole width page, and other content is after the first one.