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>
Related
This is challenging for me to position the share div like in the picture above. well, I tried the position absolute with bottom and left it's so frustrating adjusting the px but the output is always either stacked on top or bottom. how can I achieve that similar output in the picture?
:root {
--VeryDarkGrayishBlue: hsl(217, 19%, 35%);
--DesaturatedDarkBlue: hsl(214, 17%, 51%);
--GrayishBlue: hsl(212, 23%, 69%);
--LightGrayishBlue: hsl(210, 46%, 95%);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Manrope", sans-serif;
}
body {
background-color: var(--GrayishBlue);
display: flex;
flex-direction: column;
min-height: 100vh;
padding: 20px;
}
.container {
display: grid;
grid-template-columns: 2fr 3fr;
max-width: 1150px;
max-height: 390px;
margin: auto;
background-color: white;
overflow: hidden;
border-radius: 0.8em;
}
.img-box {}
.img-box img {
width: 100%;
height: 100%;
object-fit: cover;
}
.text-box {
padding: 8%;
}
.text {
padding-bottom: 30px;
}
.title {
color: var(--VeryDarkGrayishBlue);
padding-bottom: 10px;
}
.subtitle {
color: var(--GrayishBlue);
font-size: 1.1em;
}
.writer img {
width: 50px;
height: 50px;
border-radius: 50%;
}
.footer {
display: flex;
flex-direction: row;
align-items: center;
}
.name {
margin-left: 12px;
}
.name h4 {
color: var(--VeryDarkGrayishBlue);
}
.name p {
color: var(--GrayishBlue);
}
.share {
margin-left: auto;
}
.share-icon button {
border: none;
width: 40px;
height: 40px;
border-radius: 50%;
background-color: var(--LightGrayishBlue);
cursor: pointer;
}
.share-option {
width: 250px;
height: 40px;
background: var(--VeryDarkGrayishBlue);
border-radius: 10px;
display: flex;
justify-content: center;
align-items: center;
color: white;
position: absolute;
bottom: ;
}
<main class="container">
<div class="img-box">
<img src="/images/drawers.jpg" alt="" />
</div>
<div class="text-box">
<div class="text">
<h1 class="title">
Shift the overall look and feel by adding these wonderful touches to furniture in your home
</h1>
<p class="subtitle">
Ever been in a room and felt like something was missing? Perhaps it felt slightly bare and uninviting. I’ve got some simple tips to help you make any room feel complete.
</p>
</div>
<div class="footer">
<div class="writer">
<img src="/images/avatar-michelle.jpg" alt="" />
</div>
<div class="name">
<h4>Michelle Appleton</h4>
<p>28 Jun 2020</p>
</div>
<div class="share">
<div class="share-icon">
<button><img src="/images/icon-share.svg" alt=""></button>
</div>
<div class="share-option hidden">
<span>Share</span>
<a href="#"> <img src="/images/icon-facebook.svg" alt=""> <a/>
<a href="#"> <img src="/images/icon-pinterest.svg" alt=""> <a/>
<a href="#"> <img src="/images/icon-twitter.svg" alt=""> <a/>
</div>
</div>
</div>
</div>
</main>
I have made some changes in the code and made the popup visible with absolute.
:root {
--VeryDarkGrayishBlue: hsl(217, 19%, 35%);
--DesaturatedDarkBlue: hsl(214, 17%, 51%);
--GrayishBlue: hsl(212, 23%, 69%);
--LightGrayishBlue: hsl(210, 46%, 95%);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Manrope", sans-serif;
}
body {
background-color: var(--GrayishBlue);
display: flex;
flex-direction: column;
min-height: 100vh;
padding: 20px;
}
.container {
display: grid;
grid-template-columns: 2fr 3fr;
max-width: 1150px;
max-height: 390px;
margin: auto;
background-color: white;
border-radius: 0.8em;
}
.container:after {
display: block;
content: '';
clear: both;
}
.img-box {}
.img-box img {
width: 100%;
height: 100%;
object-fit: cover;
}
.text-box {
padding: 8%;
}
.text {
padding-bottom: 30px;
}
.title {
color: var(--VeryDarkGrayishBlue);
padding-bottom: 10px;
}
.subtitle {
color: var(--GrayishBlue);
font-size: 1.1em;
}
.writer img {
width: 50px;
height: 50px;
border-radius: 50%;
}
.footer {
display: flex;
flex-direction: row;
align-items: center;
}
.name {
margin-left: 12px;
}
.name h4 {
color: var(--VeryDarkGrayishBlue);
}
.name p {
color: var(--GrayishBlue);
}
.share {
margin-left: auto;
position: relative;
padding: 20px 0 0;
}
.share-icon button {
border: none;
width: 40px;
height: 40px;
border-radius: 50%;
background-color: var(--LightGrayishBlue);
cursor: pointer;
}
.share-option {
width: 250px;
height: 40px;
background: var(--VeryDarkGrayishBlue);
border-radius: 10px;
color: white;
position: absolute;
bottom: 100%;
right: 50%;
transform: translatex(50%);
visibility: hidden;
opacity: 0;
transition: visibility 0s, opacity 0.5s linear;
}
.share-option:after {
top: 100%;
left: 50%;
border: solid transparent;
content: "";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
border-color: rgba(136, 183, 213, 0);
border-top-color: var(--VeryDarkGrayishBlue);
border-width: 10px;
margin-left: -10px;
}
.share:hover .share-option {
visibility: visible;
opacity: 1;
}
<main class="container">
<div class="img-box">
<img src="/images/drawers.jpg" alt="" />
</div>
<div class="text-box">
<div class="text">
<h1 class="title">
Shift the overall look and feel by adding these wonderful touches to furniture in your home
</h1>
<p class="subtitle">
Ever been in a room and felt like something was missing? Perhaps it felt slightly bare and uninviting. I’ve got some simple tips to help you make any room feel complete.
</p>
</div>
<div class="footer">
<div class="writer">
<img src="/images/avatar-michelle.jpg" alt="" />
</div>
<div class="name">
<h4>Michelle Appleton</h4>
<p>28 Jun 2020</p>
</div>
<div class="share">
<div class="share-icon">
<button><img src="/images/icon-share.svg" alt=""></button>
</div>
<div class="share-option hidden">
<span>Share</span>
<a href="#"> <img src="/images/icon-facebook.svg" alt=""> <a/>
<a href="#"> <img src="/images/icon-pinterest.svg" alt=""> <a/>
<a href="#"> <img src="/images/icon-twitter.svg" alt=""> <a/>
</div>
</div>
</div>
</div>
</main>
I think without javascript you won't be able to do it.
You could include your share-option (position absolute) inside share-icon (position relative). This way option would be positioned relative to the button.
<div class="share">
<div class="share-icon">
<button>
<img src="/images/icon-share.svg" alt="">
</button>
<div class="share-option hidden">
<span>Share</span>
<img src="/images/icon-facebook.svg" alt="">
<img src="/images/icon-pinterest.svg" alt="">
<img src="/images/icon-twitter.svg" alt="">
</div>
</div>
</div>
and css
.share-icon {
position: relative;
}
.share-icon button {
border: none;
width: 40px;
height: 40px;
border-radius: 50%;
background-color: var(--LightGrayishBlue);
cursor: pointer;
}
.share-option {
width: 250px;
height: 40px;
background: var(--VeryDarkGrayishBlue);
border-radius: 10px;
display: flex;
justify-content: center;
align-items: center;
color: white;
position: absolute;
top: -40px;
z-index: 100;
}
Now the problem is options are in the boundary of the relative, so it doesn't extend on the right!
I suppose this container is responsive, meaning size can change. So I think the only way would be to put the option in the body (display none), when a click (or hover) happens on the button, you take the position of the button and position options on top of it with display flex
I am using relative and absolute position but it doesn't work. what's my mistake?
My HTML code:
.slide-item {
text-align: center;
height: 400px;
position: relative;
}
.slide-item img {
display: block;
}
.slide-item .sale {
position: absolute;
top: -20px;
right: 20px;
display: block;
}
<div class="slide-item">
<div class="sale">
<img src="https://via.placeholder.com/50" alt="">
</div>
<img src="https://via.placeholder.com/150" class="arr-img" alt="">
</div>
Try this code...
<!DOCTYPE html>
<html>
<head>
<style>
.slide-item {
text-align: center;
height: 400px;
position: relative;
}
.slide-item img:nth-child(2){
position: relative;
width: 1150px;
height: 600px;
left: 65px;
top: 25px;
}
.slide-item img {
display: block;
}
.slide-item .sale img {
position: absolute;
top: 0px;
right: 150px;
z-index: 1;
}
</style>
</head>
<body>
<div class="slide-item">
<div class="sale">
<img src="img/icons8-round-128.png" alt="">
</div>
<img src="img/111713927-green-screen-green-background-green-screen-stock-footage-video.jpg" class="arr-img" alt="">
</div>
</body>
</html>
I need to position elements on a side like in the image above and have onclick function on them to show the corresponding text. Any info on how to best achieve this to be responsive?
By responseive i mean that the dots and text should always stay on the same position relative to the size of the bottle.
What I did was to put everything inside the container div and then positioned the elements relative to that div and the bottle image absolute to the container div.
It kinda works when container div has fixed dimensions, but I guess there are better ways to do it.
EDIT: Added code! I suck at formatting, sorry.
<div class="bottle-one">
<div class="bottle-one-content">
<div class="bottle-one-image">
<div class="message">
<div class="message-hidden">
<div>
text
</div>
<div>
<img src="assets/images/icons/line_blue.svg" alt="">
</div>
</div>
<a href="#msg1" class="droplet droplet1 js-drop">
<img src="assets/images/icons/droplet.svg">
</a>
</div>
<div class="message">
<div class="message-hidden">
<div>
text
</div>
<div>
<img src="assets/images/icons/line_blue.svg" alt="">
</div>
<a href="#msg2" class="droplet droplet2 js-drop">
<img src="assets/images/icons/droplet.svg">
</a>
</div>
</div>
<div class="message">
<div class="message-hidden">
<div>
text
</div>
<div>
<img src="assets/images/icons/line_blue.svg" alt="">
</div>
<a href="#msg3" class="droplet droplet3 js-drop">
<img src="assets/images/icons/droplet.svg">
</a>
</div>
</div>
<div class="message">
<div class="message-hidden">
<div>
text
</div>
<div>
<img src="assets/images/icons/line_blue.svg" alt="">
</div>
<a href="#msg4" class="droplet droplet4 js-drop">
<img src="assets/images/icons/droplet.svg">
</a>
</div>
</div>
<img src="assets/images/bottle1.png" alt="" class="bottle-one-bottle">
</div>
</div>
.bottle-one {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 30%;
}
.bottle-one-image {
height: 100%;
position: relative;
width: 251px;
}
.message {
left: -340px;
top: 180px;
position: relative;
display: flex;
align-items: center;
justify-content: flex-end;
text-transform: uppercase;
font-size: .7rem;
color: #004197;
height: 30px;
width: 400px;
margin-bottom: 1rem;
}
.message-hidden {
display: flex;
}
.message-hidden div:nth-of-type(1) {
text-align: right;
font-family: 'BrandonGrotesqueWeb-Black', sans-serif;
letter-spacing: 2px;
border-right: 1px solid #004197;
width: 70%;
}
.message-hidden div:nth-of-type(2) {
width: 30%;
display: flex;
overflow:hidden;
}
I came up with this to help you with aligning your element to the left of a div.
By using a mix of [psuedo-elements] and floats, I think this gives you the desired effect you are looking for. Post your code and I'll be more then happy to help you with the other part.
html {
width: 550px;
border: none;;
}
body {
font-family: sans-serif;
color: rgba(0,0,0,.15);
height:200px;
}
body:after {
content: '';
display: block;
clear: both;
}
div {
position: relative;
}
div:after {
font-size: 200%;
position: absolute;
left: 0;
right: 0;
top: 0;
text-align: center;
}
.sibling {
border: 3px solid red;
height:200px;
}
.sibling.root:after {
content: 'Sibling';
color: green;
}
.float {
float: left;
border: 3px solid blue;
height: 90px;
width: 150px;
z-index: 1;
}
.float:after {
content: 'floated Element';
color: red;
}
.root {
overflow: hidden;
}
<div class="float">
</div>
<div class="sibling root">
</div>
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>
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