I'm trying to add different texts on the center of images. Seems like I'm unable to do this and will need some help with the task.
So, I have 4 images on the page. Now I want to put text on the images. What I have so far are 4 images on page but the text is not appear properly. Here is the part of the html
.images {
text-align: center;
padding: 15px 15px;
position: relative;
vertical-align: middle;
display: inline;
width: 430px;
margin: 10px 0;
}
#img-row {
display: block;
margin-top: -15px;
position: relative;
height: auto;
max-width: auto;
overflow-y: hidden;
overflow-x: auto;
word-wrap: normal;
white-space: nowrap;
text-align: center;
}
#img-row:after {
content: "";
position: absolute;
display: block;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 1;
}
.class {
position: relative;
}
.button {
display: block;
background-color: #bbb;
margin: 10px;
padding: 10px;
}
button.button {
width: 570px;
margin-left: 182px;
height: 40px;
font-size: 30px;
}
.caption-text {
display: block;
position: absolute;
width: 100%;
color: green;
left: 0;
bottom: 50%;
padding: 1em;
font-weight: 700;
z-index: 2;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
<div id="img-row">
<a href="">
<button class="button">
Button
</button>
</a>
</div>
<div id="img-row">
<a href="">
<img src="https://s3-us-west-1.amazonaws.com/powr/defaults/image-slider2.jpg" class="images" />
<figcaption class="caption-text">This is a caption text</figcaption>
</a>
<a href="">
<img src="https://s3-us-west-1.amazonaws.com/powr/defaults/image-slider2.jpg" class="images" />
<figcaption class="caption-text">This is a caption text</figcaption>
</a>
</div>
<div id="img-row">
<a href="">
<img src="https://s3-us-west-1.amazonaws.com/powr/defaults/image-slider2.jpg" class="images" />
<figcaption class="caption-text">This is a caption text</figcaption>
</a>
<a href="">
<img src="https://s3-us-west-1.amazonaws.com/powr/defaults/image-slider2.jpg" class="images" />
<figcaption class="caption-text">This is a caption text</figcaption>
</a>
</div>
This is how it looks like so far: JSFIDDLE. Text appears only two times.
Because you have nested your images within an a tag, then the text was aligning left:0 of img-row. Now it correctly aligns with the image because I added:
#img-row > a {
position: relative;
}
Consider the following example:
#a2{
position: relative;
display: block;
}
p{
position: absolute;
top: 0px;
margin: 0;
}
<a id="a1"><p>hello1</p></a>
<a id="a2"><p>hello2</p></a>
absolute behaves like fixed except relative to the nearest positioned ancestor instead of relative to the viewport. If an absolutely-positioned element has no positioned ancestors, it uses the document body... http://learnlayout.com/position.html
Your working example:
.images {
text-align: center;
padding: 15px 15px;
position: relative;
vertical-align: middle;
display: inline;
width: 430px;
margin: 10px 0;
}
#img-row {
display: block;
margin-top: -15px;
position: relative;
height: auto;
max-width: auto;
overflow-y: hidden;
overflow-x: auto;
word-wrap: normal;
white-space: nowrap;
text-align: center;
}
#img-row > a {
position: relative;
}
#img-row:after {
content: "";
position: absolute;
display: block;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 1;
}
.class {
position: relative;
}
.button {
display: block;
background-color: #bbb;
margin: 10px;
padding: 10px;
}
button.button {
width: 570px;
margin-left: 182px;
height: 40px;
font-size: 30px;
}
.caption-text {
display: block;
position: absolute;
width: 100%;
color: green;
left: 0;
bottom: 50%;
padding: 1em;
font-weight: 700;
z-index: 2;
-webkit-box-sizing: border-box;
box-sizing: border-box;
background-color: #fff;
}
<div id="img-row">
<a href="">
<button class="button">
Button
</button>
</a>
</div>
<div id="img-row">
<a href="">
<img src="https://s3-us-west-1.amazonaws.com/powr/defaults/image-slider2.jpg" class="images" />
<figcaption class="caption-text">This is a caption text</figcaption>
</a>
<a href="">
<img src="https://s3-us-west-1.amazonaws.com/powr/defaults/image-slider2.jpg" class="images" />
<figcaption class="caption-text">This is a caption text</figcaption>
</a>
</div>
<div id="img-row">
<a href="">
<img src="https://s3-us-west-1.amazonaws.com/powr/defaults/image-slider2.jpg" class="images" />
<figcaption class="caption-text">This is a caption text</figcaption>
</a>
<a href="">
<img src="https://s3-us-west-1.amazonaws.com/powr/defaults/image-slider2.jpg" class="images" />
<figcaption class="caption-text">This is a caption text</figcaption>
</a>
</div>
Related
sorry for my naivety I'm very new to web development and have to create this for a uni project. The problem I'm having is that I have a grid of image thumbnails that link to full res versions on a separate page, the last image in the grid has a link that shows up and pushes content out the footer and inspect element on the page says the link it within the footer div but in the code it's not there. Any help would be appreciated.
.grid {
margin-left: 15%;
margin-right: 15%;
margin-top: 10px;
margin-bottom: 10px;
overflow: hidden;
}
.square {
display: inline-block;
float: left;
position: relative;
width: 30%;
padding-bottom: 30%;
/* = width for a 1:1 aspect ratio */
margin: 1.66%;
overflow: hidden;
}
.content {
position: absolute;
height: 100%;
width: 100%;
padding: 0%;
}
/* For responsive images */
.content .rs {
width: auto;
height: auto;
max-height: 100%;
max-width: 100%;
}
.footer {
height: 45px;
width: 100%;
background-color: white;
overflow: auto;
position: -webkit-sticky;
position: sticky;
z-index: 1;
bottom: 0;
list-style-type: none;
overflow: hidden;
padding-bottom: 5px;
padding-top: 5px;
overflow: hidden;
}
.footer a {
display: inline;
color: black;
text-align: center;
padding-top: 5px;
padding-bottom: 10px;
text-decoration: none;
font-family: 'myntieregular';
src: url('myntie-regular-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
font-size: 45px;
float: left;
text-decoration: none;
width: 33%;
text-align: center;
border-top-style: solid;
border-color: #c7c7c7;
border-width: 2px 0px;
}
<div class="grid">
<div class="square">
<div class="content">
<a href="Gallery\DSCF1629.html"><img class="rs" src="Images\Thumbnails\DSCF1629_Thumbnail.png" />
</div>
</div>
<div class="square">
<div class="content">
<a href="Gallery\DSCF1425.html"><img class="rs" src="Images\Thumbnails\DSCF1425_Thumbnail.png" />
</div>
</div>
<div class="square">
<div class="content">
<a href="Gallery\DSCF1723.html"><img class="rs" src="Images\Thumbnails\DSCF1723_Thumbnail.png" />
</div>
</div>
</div>
<div class="footer">
<img src="Image" alt="Instagram" style="width:30px;height:30px;">
<img src="Image" alt="Email" style="width:30px;height:30px;">
<img src="Image" alt="linkedin" style="width:30px;height:30px;">
</div>
Forgot to close the <a> tags within the "grid" divs.
It is hard to see since it is so off to the right.
Want to add horizontal line after image and it should be responsive.Right now it has 5 images in future i can add 6th image dynamically.So lines should be responsive to take 6th image.
Sample Of Image:
a {
display: block;
text-align: center;
position: relative;
}
a:after {
content: "";
width: 80%;
position: absolute;
left: 0;
top: 50%;
height: 1px;
background: green;
}
img{
width: 50px;
height: 50px;
border-radius: 50%
}
<a href="">
<img src="https://www.w3schools.com/w3images/bandmember.jpg" alt="error">
</a>
a {
display: block;
text-align: center;
position: relative;
}
hr {
border: 1px solid green;
width: 100%;
}
<a href="">
<img src="https://www.w3schools.com/w3images/bandmember.jpg" alt="error">
</a>
<hr>
<a href="">
<img src="https://www.w3schools.com/w3images/bandmember.jpg" alt="error">
</a>
<hr>
Your code doesn't work because you've set the <a> tag to display: block; which means that it occupies the entire line. This means that the line you've added will be 80% of the available space for the <a> tag.
If possible, consider adding an inline wrapper <div> and attach your line to that instead.
.link-wrapper {
position: relative;
display: inline-flex;
align-items: center;
}
.link-wrapper:after {
content: "";
position: absolute;
top: 50%;
z-index: -1;
left: 0;
height: 1px;
width: 100%;
background: green;
}
.link-wrapper a:not(:last-child) {
margin-right: 2em;
}
.link-wrapper img {
display: block
}
<div class="link-wrapper">
<a href="">
<img src="https://i.stack.imgur.com/9mWMO.png?s=48">
</a>
<a href="">
<img src="https://i.stack.imgur.com/9mWMO.png?s=48">
</a>
<a href="">
<img src="https://i.stack.imgur.com/9mWMO.png?s=48">
</a>
<a href="">
<img src="https://i.stack.imgur.com/9mWMO.png?s=48">
</a>
</div>
Well it depends but something like this could do the job.
.bar {
position: relative;
height: 50px;
display: flex;
justify-content: space-between;
}
.bar:before {
content: "";
display: block;
position: absolute;
width: 100%;
top: 50%;
transform: translateY(-50%);
height: 1px;
background-color: green;
}
.image-wrapper {
position: relative;
}
.image-wrapper img {
width: 50px;
border-radius: 50%;
}
#media (max-width: 425px) {
.bar {
flex-direction: column;
height: auto;
align-items: center;
}
.bar:before {
width: 1px;
top: 0;
bottom: 0;
transform: none;
height: 90%;
}
.image-wrapper {
margin-bottom: 10px;
}
}
<div class="bar">
<div class="image-wrapper">
<a href="#">
<img src="https://www.w3schools.com/w3images/bandmember.jpg" alt="Alternative Text">
</a>
</div>
<div class="image-wrapper">
<a href="#">
<img src="https://www.w3schools.com/w3images/bandmember.jpg" alt="Alternative Text">
</a>
</div>
<div class="image-wrapper">
<a href="#">
<img src="https://www.w3schools.com/w3images/bandmember.jpg" alt="Alternative Text">
</a>
</div>
</div>
to add new line here :
add a new div
adjust the left property for the elements between start and end to fit all ... I give 2st 30% and 3rd 60% because I have 2 element ... so when you add new on decrease this.
finally I added background to all from .tline div for demo but you can specify a new background to each div
body {
padding-top: 100px;
}
.tline {
border-top: 2px solid gray;
position: relative;
}
.tline div {
display: inline-block;
width: 50px;
height: 50px;
border: px solid;
position: absolute;
border-radius: 35px;
text-align: center;
top: -25px;
background: url("https://www.w3schools.com/w3images/bandmember.jpg") center;
background-size: cover;
}
.tline div:nth-child(2) {
left: 30%;
}
.tline div:nth-child(3) {
left: 60%;
}
.tline div:last-child {
right: 0;
}
<div class="tline">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
I have 6 images inside a container with display: flex, so the width of the container is divided on the 6 images.
I want to show 2 images and part of the 3rd, while the 3 others are next to them at the right but not shown until the user scrolls to the right.
I hide the horizontal scrollbar, but I want to keep the scrolling functions, but as shown in this fiddle, the 6 images are displayed.
How to only show 2 images and part of the 3rd with the other 3 hidden at the right next to the first 3?
Here is the code:
.images {
margin-bottom: 20px;
border-bottom: 1px solid #dae2e4;
padding-bottom: 20px;
}
.images__gallery {
display: -webkit-box;
display: flex;
padding-right: 5px;
margin: -3px;
overflow-y: hidden;
overflow-x: scroll;
margin-bottom: -50px;
padding-bottom: 50px;
}
.images__gallery-item {
/*overflow: hidden;*/
position: relative;
padding: 1%;
flex-basis: 32%;
height: 25vw;
margin: 3px;
border: 1px solid #dae2e4;
}
.images__gallery-item img {
position: absolute;
left: -1000%;
right: -1000%;
top: -1000%;
bottom: -1000%;
margin: auto;
min-height: 100%;
min-width: 100%;
max-width: 100%;
}
.images__title {
line-height: 21px;
margin-bottom: 17px;
color: #707a81;
}
#media (min-width: 420px) {
.images__gallery-item {
flex-basis: 24%;
height: 20vw;
}
}
#media (min-width: 530px) {
.images__gallery-item {
flex-basis: 19%;
height: 16vw;
}
}
#media (min-width: 768px) {
.images__gallery-item {
flex-basis: 16%;
height: 12.5vw;
}
}
<aside class="sidebar sidebar__frame">
<div class="images sidebar__block">
<div class="images__title">Images:</div>
<div class="images__gallery">
<div class="images__gallery-item">
<a href="" target="_blank">
<img src="http://placehold.it/100/150" alt="Wikimedia">
</a>
</div>
<div class="images__gallery-item">
<a href="" target="_blank">
<img src="http://placehold.it/100/100" alt="Wikimedia">
</a>
</div>
<div class="images__gallery-item">
<a href="" target="_blank">
<img src="http://placehold.it/100/120" alt="Wikimedia">
</a>
</div>
<div class="images__gallery-item">
<a href="" target="_blank">
<img src="http://placehold.it/100/105" alt="Wikimedia">
</a>
</div>
<div class="images__gallery-item">
<a href="" target="_blank">
<img src="http://placehold.it/100/122" alt="Wikimedia">
</a>
</div>
<div class="images__gallery-item">
<a href="" target="_blank">
<img src="http://placehold.it/100/195" alt="Wikimedia">
</a>
</div>
</div>
</div>
<!-- .images-->
</aside>
How to hide the horizontal scrollbar in this case?
An initial setting of a flex container is flex-shrink: 1. This means that flex items can shrink in order to prevent overflow of the container. You can disable this feature with flex-shrink: 0.
Add this to your code:
.images__gallery-item {
flex-shrink: 0;
}
Your container element needs to have a maximum width of the size you want to show, and the scroll bar on the x axis. Your image container needs to be explicitly made wider than the containing element:
.sidebar__frame {
height: 100%;
max-width: 300px;
overflow-x: hidden;
}
.sidebar__block {
height: 100%;
width: 100%;
overflow-x: auto;
margin-bottom: -20px;
}
/* .images {
margin-bottom: 20px;
border-bottom: 1px solid #dae2e4;
padding-bottom: 20px;
}
*/
.images__gallery {
display: -webkit-box;
display: flex;
padding-right: 5px;
margin: -3px;
min-width: 700px;
overflow-y: hidden;
margin-bottom: -50px;
padding-bottom: 50px;
}
.images__gallery-item {
/*overflow: hidden;*/
position: relative;
padding: 1%;
flex-basis: 32%;
height: 25vw;
margin: 3px;
border: 1px solid #dae2e4;
}
.images__gallery-item img {
position: absolute;
left: -1000%;
right: -1000%;
top: -1000%;
bottom: -1000%;
margin: auto;
min-height: 100%;
min-width: 100%;
max-width: 100%;
}
.images__title {
line-height: 21px;
margin-bottom: 17px;
color: #707a81;
}
#media (min-width: 420px) {
.images__gallery-item {
flex-basis: 24%;
height: 20vw;
}
}
#media (min-width: 530px) {
.images__gallery-item {
flex-basis: 19%;
height: 16vw;
}
}
#media (min-width: 768px) {
.images__gallery-item {
flex-basis: 16%;
height: 12.5vw;
}
}
<aside class="sidebar sidebar__frame">
<div class="images sidebar__block">
<div class="images__title">Images:</div>
<div class="images__gallery">
<div class="images__gallery-item">
<a href="" target="_blank">
<img src="http://placehold.it/100/150" alt="Wikimedia">
</a>
</div>
<div class="images__gallery-item">
<a href="" target="_blank">
<img src="http://placehold.it/100/100" alt="Wikimedia">
</a>
</div>
<div class="images__gallery-item">
<a href="" target="_blank">
<img src="http://placehold.it/100/120" alt="Wikimedia">
</a>
</div>
<div class="images__gallery-item">
<a href="" target="_blank">
<img src="http://placehold.it/100/105" alt="Wikimedia">
</a>
</div>
<div class="images__gallery-item">
<a href="" target="_blank">
<img src="http://placehold.it/100/122" alt="Wikimedia">
</a>
</div>
<div class="images__gallery-item">
<a href="" target="_blank">
<img src="http://placehold.it/100/195" alt="Wikimedia">
</a>
</div>
</div>
</div>
<!-- .images-->
</aside>
I'm trying to write a homepage with this little effect on a hover.
It should look something like this:
How would you do this? My code does not work like it should.
.stage_wrapper {
margin: 0 auto;
width: 1100px;
height: auto;
}
.work {
margin-left: 8px;
margin-right: 5px;
margin-bottom: 15px;
display: inline-block;
height: 350px;
width: 350px;
}
.work img {
width: 350px;
height: auto;
}
<div class="stage_wrapper">
<div class="stage">
<div class="work">
<a href="#" target="_blank">
<img src="//dummyimage.com/350" class="media" alt="#" />
<div class="caption">
<div class="work_title">
<h1>Something in 3 rows</h1>
</div>
</div>
</a>
</div>
</div>
</div>
Something like this?
.work {
width: 300px;
height: 300px;
line-height:300px;
text-align: center;
background-color: #2d3e50;
border: 10px solid #2a81b9;
color: white;
display: inline-block;
}
.work span {
display: none;
vertical-align: middle;
}
.work:hover span {
display: inline-block;
}
.work:hover img {
display: none;
}
<div class="work">
<span>Some text</span>
<img class="portfolio-image" src="http://dummyimage.com/300.png/09f/fff" width="300" height="300" />
</div>
Demo: http://codepen.io/malte/pen/kDlbt
I am using an absolute positioned wrapper to center an image in a thumbnail frame. (Only) On mobile safari, the image won't be displayed. if you inspect the .image-pos container you'll see that the height is properly set to its parent's size. applying a fixed px height to it will make the image show up... Does anyone know how to fix that?
It's working on any Desktop browser...
HTML:
<div class="wrapper">
<div class="thumb-grid">
<div class="thumb">
<a href="#" class="image">
<div class="image-pos">
<img src="http://images.weserv.nl/?url=static.living.is/gallery/original/5184f3631034bcdf16bd4d37c341928e.jpg&il&w=600" />
</div>
</a>
<div class="details">
<h5>Image Title</h5>
</div>
</div>
<div class="thumb">
<a href="#" class="image">
<div class="image-pos">
<img src="http://images.weserv.nl/?url=static.living.is/gallery/original/5184f3631034bcdf16bd4d37c341928e.jpg&il&w=600" />
</div>
</a>
<div class="details">
<h5>Image Title</h5>
</div>
</div>
<div class="thumb">
<a href="#" class="image">
<div class="image-pos">
<img src="http://images.weserv.nl/?url=static.living.is/gallery/original/016e551de2f53d58e7f4acd68279e6a1.JPG&il&w=600" />
</div>
</a>
<div class="details">
<h5>Image Title</h5>
</div>
</div>
</div>
</div>
CSS:
.wrapper {
width: 600px;
margin: 30px auto 0
}
.thumb-grid {
text-align: justify;
}
.thumb-grid:after {
content: '';
display: inline-block;
width: 100%;
}
.thumb {
position: relative;
display: inline-block;
width: 31.5%;
height: 0;
padding-top: 29%;
margin-bottom: 6%;
}
.image {
height: 73%;
overflow: hidden;
position: absolute;
text-align: center;
top: 0;
width: 100%;
vertical-align: top;
display: block;
border: 1px solid #eee;
}
.image-pos {
height: 100%;
left: 50%;
margin-left: -300px;
position: absolute;
text-align: center;
width: 600px;
}
.image-pos img {
height: 100%;
max-height: 100%;
min-height: 100%;
max-width: none;
width: auto;
display: inline;
border: 0;
}
.details {
height: 27%;
position: absolute;
top: 73%;
}
.details h5 {
margin: 0;
padding-top: 5px;
}
Demo: http://codepen.io/malte/pen/kDlbt