How to make a text stay inside a div? - html

The problem occurs when I resize the window into a smaller one. When the window is small it becomes like this.
But when the window size is maximized it appears like I intended it to be like this
Here is my html and css:
.highlight {
display: flex;
flex-direction: row;
justify-content: center;
}
.highlight-item {
padding: 0px;
font-family: Candara;
}
.highlight-item:hover {
opacity: 0.85;
}
.highlight-item img {
width: 100%;
float: left;
position: relative;
z-index: -5;
}
.highlight-des {
background: linear-gradient(0deg, rgba(2, 0, 36, 0.75) 0%, rgba(255, 255, 255, 0) 100%);
height: 200px;
position: relative;
margin-top: 180px;
}
.highlight-des h1 {
position: absolute;
margin-top: 0%;
font-size: 2em;
font-weight: 300;
}
.highlight-des p {
position: absolute;
margin-top: 20%;
}
<div class="highlight">
<div class="highlight-item col-4">
<img src="images/highlight-mockup.jpg" alt="">
<div class="highlight-des">
<h1>Title</h1>
<p>By: Author</p>
</div>
</div>
<div class="highlight-item col-4">
<img src="images/highlight-mockup.jpg" alt="">
<div class="highlight-des">
<h1>Title</h1>
<p>By: Author</p>
</div>
</div>
<div class="highlight-item col-4">
<img src="images/highlight-mockup.jpg" alt="">
<div class="highlight-des">
<h1>Title</h1>
<p>By: Author</p>
</div>
</div>
</div>
Last but not least, since this is a school project nothing but HTML and pure CSS is allowed, thanks, everyone!

Here you go exactly you wanted. I have fixed you CSS a bit.
There was a problem with position and margins
Working JSFiddle
Run snippet to see it action.
.highlight {
display: flex;
flex-direction: row;
position: relative;
}
.highlight-item {
padding: 0px;
font-family: Candara;
width: 100%;
}
.highlight-item:hover {
opacity: 0.85;
}
.highlight-item img {
width: 100%;
float: left;
position: relative;
z-index: -5;
}
.highlight-des {
background: linear-gradient(0deg, rgba(2, 0, 36, 0.75) 0%, rgba(255, 255, 255, 0) 100%);
height: 100%;
position: relative;
margin-top: 180px;
}
.highlight-des h1 {
font-size: 2em;
font-weight: 300;
}
<div class="highlight">
<div class="highlight-item col-4">
<img src="images/highlight-mockup.jpg" alt="">
<div class="highlight-des">
<h1>Title</h1>
<p>By: Author</p>
</div>
</div>
<div class="highlight-item col-4">
<img src="images/highlight-mockup.jpg" alt="">
<div class="highlight-des">
<h1>Title</h1>
<p>By: Author</p>
</div>
</div>
<div class="highlight-item col-4">
<img src="images/highlight-mockup.jpg" alt="">
<div class="highlight-des">
<h1>Title</h1>
<p>By: Author</p>
</div>
</div>
</div>

Related

Element with position absolute and bottom: 0px; doesnt stich to the bottom

Im new to code,
I gave the image element(the bee), position: absolute and bottom: 0px, in order to make the element stick to the bottom of the body i.e. the bottom of the page. However, if I dont give the body position: relative, it doesnt work! Based on what I learnt, if there is no any parent that has position that is not static it automatically set itself in relation to the body, so it doesnt work in that case?
HTML
<body>
<img src="https://media.npr.org/assets/img/2018/06/07/gettyimages-200415242-001_slide-d26f3af782b697f15ceebe2f7c380c0e545dd47b.jpg" alt="" class="test-bee">
<div class="container">
<div class="main">
<div class="info">
<h1>10,000+ of our users love our products.</h1>
<p>We only provide great products combined with excellent customer service.
See what our satisfied customers are saying about our services.</p>
</div>
<div class="rates">
<div class="rate-container">
<div class="star-container">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
</div>
<p class="review">Rated 5 Stars in Reviews</p>
</div>
<div class="rate-container">
<div class="star-container">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
</div>
<p class="review">Rated 5 Stars in Report Guru</p>
</div>
<div class="rate-container">
<div class="star-container">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
</div>
<p class="review">Rated 5 Stars in BestTech</p>
</div>
</div>
</div>
<section class="testemonies">
<div class="testemony-card">
<div class="user-info">
<div class="img-container">
<img src="./images/image-colton.jpg" alt="">
</div>
<div class="user-name-status">
<p class="user-name">colton smith </p>
<p class="status"><span>verified buyer</span></p>
</div>
</div>
<p class="testimony">"We needed the same printed design as the one we had ordered a week prior.
Not only did they find the original order, but we also received it in time.
Excellent!"</p>
</div>
<div class="testemony-card">
<div class="user-info">
<div class="img-container">
<img src="./images/image-irene.jpg" alt="">
</div>
<div class="user-name-status">
<p class="user-name">irene roberts </p>
<p class="status"><span>verified buyer</span></p>
</div>
</div>
<p class="testimony">
"Customer service is always excellent and very quick turn around. Completely
delighted with the simplicity of the purchase and the speed of delivery."</p>
</div>
<div class="testemony-card">
<div class="user-info">
<div class="img-container">
<img src="./images/image-anne.jpg" alt="">
</div>
<div class="user-name-status">
<p class="user-name">anne wallace </p>
<p class="status"><span>verified buyer</span></p>
</div>
</div>
<p class="testimony">
"Put an order with this company and can only praise them for the very high
standard. Will definitely use them again and recommend them to everyone!"</p>
</div>
</section>
</div>
</body>
CSS
* {
padding: 0px;
margin: 0px;
box-sizing: border-box;
}
:root {
--Very-Dark-Magenta: hsl(300, 43%, 22%);
--Soft-Pink: hsl(333, 80%, 67%);
--Dark-Grayish-Magenta: hsl(303, 10%, 53%);
--Light-Grayish-Magenta: hsl(300, 24%, 96%);
--White: hsl(0, 0%, 100%);
}
body {
width: 100%;
min-height: 100vh;
font-family: 'League Spartan', sans-serif;
font-size: 15px;
display: flex;
align-items: center;
justify-content: center;
/* border: 5px solid red; */
padding: 1em;
position: relative; /*why do i need this relative? the bottom image should stick to the bottom by default cause the body is the first one that had position relative, but without it it doesnt stick*/
}
.pattern {
display: none;
}
.test-bee {
width: 200px;
position: absolute;
bottom: 0px;
}
.bottom-mobile, .top-mobile {
display: block;
position: absolute;
}
.top-mobile {
top:0px;
}
.bottom-mobile {
bottom: 0px;
}
.container {
height: 100%;
/* border: 5px solid green; */
margin: 3em 0px;
}
.main {
text-align: center;
margin-bottom: 3em;
}
.info h1 {
margin: 0px auto;
line-height: 0.8em;
margin-bottom: 1em;
margin: 1em 2em;
color: var(--Very-Dark-Magenta)
}
.info {
line-height: 1.3em;
margin-bottom: 2.5em;
}
.rate-container {
background-color: var(--Light-Grayish-Magenta);
padding: 1em 2em;
margin-bottom: 1em;
border-radius: 0.4em;
display: flex;
flex-direction: column;
gap: 0.5em;
color: var(--Very-Dark-Magenta);
font-weight: bold;
}
.testemonies {
display: flex;
flex-direction: column;
gap: 1em;
}
.testemony-card {
background-color: var(--Very-Dark-Magenta);
border-radius: 0.4em;
color: white;
padding: 2em;
line-height: 1.2em;
}
.img-container {
width: 30px;
height: 30px;
border-radius: 50px;
overflow: hidden;
}
.img-container img {
height: 100%;
width: 100%;
}
.user-info {
display: flex;
align-items: center;
gap: 1em;
text-transform: capitalize;
margin-bottom: 1em;
}
.user-name-status p span{
color:var(--Soft-Pink)
}
I fix it by adding the body position: relative, but it should go like that

Display button in the same position of the image on click

Wanted to know if a button can be displayed in the same position as the image.
.column {
float: left;
width: 33.33%;
padding: 5px;
}
<div class="column">
<img src="img_snow.jpg" alt="Snow" style="width:100%">
</div>
<div class="column">
<img src="img_forest.jpg" alt="Forest" style="width:100%">
</div>
<div class="column">
<img src="img_mountains.jpg" alt="Mountains" style="width:100%">
</div>
How can Image and text be displayed ina table format
I didn't really understand what you wanted, but I did it from the picture.
The code is wrong in my opinion you can read about gridd css so that in the future you can do it correctly css grid.
Or the cssportal website can help css-flexbox-generator/
.grid-container {
display: grid;
grid-template-columns: auto auto auto;
}
img {
width: 100%;
height: 19rem;
}
button {
width: fit-content;
margin: 4rem auto 0rem auto;
background-color: #447bad;
border-style: none;
color: #fff;
cursor: pointer;
display: flex;
font-size: 100%;
padding: 10px 21px;
}
<div class="grid-container">
<div class="grid-item">
<img src="https://www.w3schools.com/howto/img_snow.jpg" alt="">
</div>
<div class="grid-item">
<img src="https://www.w3schools.com/howto/img_forest.jpg" alt="">
</div>
<div class="grid-item">
<img src="https://www.w3schools.com/howto/img_snow.jpg" alt="">
</div>
<div class="grid-item">
<button style="background: #4CAF4F;">Green</button>
<button>Blue</button>
</div>
<div class="grid-item"><img src="https://www.w3schools.com/howto/img_forest.jpg" alt=""></div>
<div class="grid-item">
<img src="https://www.w3schools.com/howto/img_snow.jpg" alt="">
</div>
</div>
The second method, click the image disappears, the buttons appear.
let child1 = document.querySelector("#child1");
child1.onclick = function () {
document.querySelector("#child1 > img").style.display = "none";
document.querySelector("#child1 > .btn-click").style.display = "block";
};
.grid-container {
display: flex;
grid-template-columns: auto auto auto;
}
.btn-click{
display:none;
}
img {
width: 100%;
height: 19rem;
}
button {
width: fit-content;
margin: 4rem auto 0rem auto;
background-color: #447bad;
border-style: none;
color: #fff;
cursor: pointer;
display: flex;
font-size: 100%;
padding: 10px 21px;
}
.grid-item{
width: 33%;
}
<div class="grid-container">
<div class="grid-item" id="child1">
<img src="https://www.w3schools.com/howto/img_snow.jpg" alt="">
<div class="btn-click">
<button style="background: #4CAF4F;">Green</button>
<button>Blue </button>
</div>
</div>
<div class="grid-item">
<img src="https://www.w3schools.com/howto/img_forest.jpg" alt="">
</div>
<div class="grid-item">
<img src="https://www.w3schools.com/howto/img_snow.jpg" alt="">
</div>
</div>
The code is not responsive.
if you mean you want the button be inside the picture here what it is
img {
position : relitive ;
}
button {
position : absolute ;
top : 0;
left : 0;
}
I dont know where is your button tag if it is inside your div class:"colume" get it out of there
I would go about it with flexbox usage rather than float. Check out the Codepen I setup with an example in it ->
https://codepen.io/martin_f/pen/vYdYPNp
-EDIT to include relevant code here-
With flexbox usage you can go about making use of flex-direction / justify-content / align-items CSS rules to get the effect you want here ->
.row {
display: inline-flex;
width: 100%;
}
.column,
.column-btn {
display: flex;
margin-right: 1rem;
width: 300px;
}
.column img {
max-width: 300px;
}
.column-btn {
flex-direction: column;
justify-content: center;
align-items: center;
}
.column-btn button {
margin-bottom: 2rem;
width: 10rem;
padding: 1rem;
border: none;
border-radius: 8px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
transition: all 0.3s cubic-bezier(.25, .8, .25, 1);
}
.column-btn button:hover {
cursor: pointer;
box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
}
.column-btn button.blue-btn {
background-color: #008cba;
}
.column-btn button.green-btn {
background-color: #4caf50;
}
<div class="row">
<div class="column">
<img src="https://images.unsplash.com/photo-1483921020237-2ff51e8e4b22?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2070&q=80" alt="Snow" style="width:100%">
</div>
<div class="column">
<img src="https://images.unsplash.com/photo-1448375240586-882707db888b?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1770&q=80" alt="Forest" style="width:100%">
</div>
<div class="column">
<img src="https://images.unsplash.com/photo-1506905925346-21bda4d32df4?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1770&q=80" alt="Mountains" style="width:100%">
</div>
</div>
<div class="row">
<div class="column-btn">
<button class="green-btn">Green</button>
<button class="blue-btn">Blue</button>
</div>
<div class="column">
<img src="https://images.unsplash.com/photo-1448375240586-882707db888b?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1770&q=80" alt="Forest" style="width:100%">
</div>
<div class="column">
<img src="https://images.unsplash.com/photo-1506905925346-21bda4d32df4?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1770&q=80" alt="Mountains" style="width:100%">
</div>
</div>
And you end up with something like ->

How can i make hover effect on image with caption

so im having little bit of strugle making this work.
So basicly what i am trying to make is image with caption under it and when you hover over image it gets greenish color with transparency and a plus sign on it.
What ive tried so far is to make <div class=parent> and inside of <div class=parent> i would have <img> and another <div class="overlay">
HTML
<section class="gallery">
<div class="container">
<div class="row">
<div class="parent">
<img src="img/showcase.jpg">
<div class="overlay">
<i class="fas fa-plus"></i>
</div>
</div>
</div>
</div>
</section>
CSS
.gallery .overlay {
background: rgba(0, 188, 156, 0);
display: block;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
} /* this div overlay will be greenish transparent color over an image when image is hovered */
.gallery .parent {
margin-top: 40px;
} /* this is just some spacing when images go one under another */
.gallery .parent:hover .overlay {
background: rgba(0, 188, 156, 0.8);
}
.gallery .parent:hover .fa-plus {
color: white;
}
.gallery .fa-plus {
position: absolute;
top: 50%;
left: 50%;
color: rgba(255, 255, 255, 0);
font-size: 1.75em;
}
so this works perfectly fine.
But when i put caption in my HTML.
<section class="gallery">
<div class="container">
<div class="row">
<div class="parent">
<img src="img/showcase.jpg">
<div class="overlay">
<i class="fas fa-plus"></i>
</div>
<div class="caption">
<h5>Lorem ipsum dolor.</h5>
<h6>lorem</h6>
</div>
</div>
</div>
<div class="overlay"> stretches all the way down
im running out of ideas how to make this possible especially because i need it to be responsive, images are changing widths and heights based on the resolution so i can put <div class="overlay> height on 80% or 90%
EG on medium devices.
Put the image inside its own container where you can add the overlay:
.img-container {
display:inline-block;
position:relative;
}
.img-container img {
display:block;
}
.overlay {
background: rgba(0, 188, 156, 0);
display: block;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
.gallery .parent {
margin-top: 40px;
}
.gallery .img-container:hover .overlay {
background: rgba(0, 188, 156, 0.8);
}
.gallery .img-container:hover .fa-plus {
color: white;
}
.gallery .fa-plus {
position: absolute;
top: 50%;
left: 50%;
color: rgba(255, 255, 255, 0);
font-size: 1.75em;
}
<section class="gallery">
<div class="container">
<div class="row">
<div class="parent">
<div class="img-container">
<img src="https://lorempixel.com/400/200/ ">
<div class="overlay ">
<i class="fas fa-plus ">+</i>
</div>
</div>
<div class="caption ">
<h5>Lorem ipsum dolor.</h5>
<h6>lorem</h6>
</div>
</div>
</div>

changing the filling of the block when hovering

I want to make smt like this
img
Make background opacity and make visible two lines text and little picture (arrow) when hovering.
I know, i can make it just using other picture for background (make opacity in Photoshop), but i want to know how to make it with CSS
.futured {
padding: var(--product-padding);
display: grid;
grid-template-columns: repeat(4, 270px);
grid-template-rows: 1fr;
grid-gap: 30px;
}
.lamp{
background-image: url(http://anti-naruto.ru/img/product-1.jpg);
align-content: center;
padding: 30% 15px 30%;
}
.lamp p:first-child{
font-family: Montserrat;
color: #212121;
font-size: 1.369em;
font-weight: 700;
line-height: 1.369;
text-align: center;
opacity: 0;
}
.lamp p:first-child:hover{
opacity: 1;
}
.lamp p:last-child{
font-family: Montserrat;
color: #6c6c6c;
font-size: 0.871em;
font-weight: 300;
line-height: 1.578;
text-align: center;
opacity: 0;
}
.lamp p:last-child:hover{
opacity: 1;
}
.lamp:hover{
}
<div class="futured">
<div class="lamp">
<a href="#">
<p>Fishnet Chair</p>
<p>Seat and back with upholstery made of cold cure foam</p>
</a>
</div>
<img src="http://anti-naruto.ru/img/product-2.jpg" alt="">
<img src="http://anti-naruto.ru/img/product-3.jpg" alt="">
<a href="#"><img src="http://anti-naruto.ru/img/product-4.jpg" alt=""></ahttps://stackoverflow.com/questions/ask#>
</div>
You need to use absolute positioning to achieve this. Please see my snippet:
.item {
position: relative;
}
.item .overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
background: rgba(255, 255, 255, 0.8);
}
.item:hover .overlay {
opacity: 1;
}
<div class="item">
<img src="http://anti-naruto.ru/img/product-1.jpg" alt="">
<div class="overlay">
<h2>Test</h2>
<p>Description</p>
</div>
</div>
<div class="item">
<img src="http://anti-naruto.ru/img/product-1.jpg" alt="">
<div class="overlay">
<h2>Test</h2>
<p>Description</p>
</div>
</div>
<div class="item">
<img src="http://anti-naruto.ru/img/product-1.jpg" alt="">
<div class="overlay">
<h2>Test</h2>
<p>Description</p>
</div>
</div>
<div class="item">
<img src="http://anti-naruto.ru/img/product-1.jpg" alt="">
<div class="overlay">
<h2>Test</h2>
<p>Description</p>
</div>
</div>

CSS nth-child(odd) not working

I need to alternate the background color of the class jl-member-info but this doesn’t work. I have this code:
.uk-grid .jl-member-item .jl-member-info:nth-child(odd) {
position: relative;
padding: 0 0.9rem;
background-color: rgba(0, 198, 197, 0.89);
width: 100%;
margin-top: -95px;
}
.uk-grid .jl-member-item .jl-member-info:nth-child(even) {
position: relative;
padding: 0 0.9rem;
background-color: #090963;
width: 100%;
margin-top: -95px;
}
<div class="jl-member ">
<div class=" uk-grid-large uk-grid uk-grid-width-small-1-2 uk-grid-width-medium-1-2 uk-grid-width-large-1-4" data-uk-grid-margin="">
<div class="jl-member-item default uk-row-first">
<div class="jl-member-item-img">
<img class="uk-overlay-spin" src="/templates/g5_helium/custom/images/Alain.jpg?595f26c4">
</div>
<div class="jl-member-info">
<div class="jl-member-name">Alain</div>
<div class="jl-member-role">Maire</div>
<div class="jl-member-desc"><span class="cloaked_email">mail#test.fr</span>
</div>
</div>
</div>
<div class="jl-member-item default">
<div class="jl-member-item-img">
<img class="uk-overlay-spin" src="/templates/g5_helium/custom/images/Alain.jpg?595f26c4">
</div>
<div class="jl-member-info">
<div class="jl-member-name">Alain</div>
<div class="jl-member-role">Maire</div>
<div class="jl-member-desc"><span class="cloaked_email">mail#test.fr</span>
</div>
</div>
</div>
<div class="jl-member-item default">
<div class="jl-member-item-img">
<img class="uk-overlay-spin" src="/templates/g5_helium/custom/images/Alain.jpg?595f26c4">
</div>
<div class="jl-member-info">
<div class="jl-member-name">Alain</div>
<div class="jl-member-role">Maire</div>
<div class="jl-member-desc"><span class="cloaked_email">mail#test.fr</span>
</div>
</div>
</div>
</div>
</div>
You need to recode like this, because you have only one .jl-member-info in .jl-member-item it will always be odd!
.uk-grid .jl-member-item .jl-member-info {
position: relative;
padding: 0 0.9rem;
width: 100%;
margin-top: -95px;
background-color: #090963;
}
.uk-grid .jl-member-item:nth-child(odd) .jl-member-info {
background-color: rgba(0, 198, 197, 0.89);
}