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>
Related
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>
I'd like to add a dropdown menu to a fixed toolbar, but the .toolbar-dropdown-menu element is not displayed as shown in the screenshot below (tested with Google Chrome 80.0):
My first impression was that the behavior of .toolbar-dropdown-menu is as if its parent was set to overflow: hidden: If I make the parent .toolbar-btn wider, the .toolbar-dropdown-menu is shown within the boundaries of its parent:
However, even if I explicitly set all elements to overflow: visible, the .toolbar-dropdown-menu remains invisible, even if its display is set to block and its visibility to visible.
Question: Why is the .toolbar-dropdown-menu element invisible and how do I get it to show up?
Here's a code snippet:
(This is a reduced version of the toolbar. It can usually be assigned to varying positions and expanded to show labels, but I excluded those features to minimize the code you have to go through)
.floating-toolbar {
position: fixed;
z-index: 1031;
background: #333;
color: rgba(255, 255, 255, 0.5);
}
.floating-toolbar.left {
left: 0;
}
.floating-toolbar.left .toolbar-btn .toolbar-icon {
right: 0.5rem;
}
.floating-toolbar.left .toolbar-dropdown > .toolbar-dropdown-menu {
position: absolute;
left: 21rem;
top: 0;
}
.floating-toolbar.left.minimized {
left: -18.5rem;
}
.floating-toolbar .toolbar-btn {
position: relative;
border-bottom: 1px solid rgba(255, 255, 255, .5);
padding: 0.5rem;
font-size: 1rem;
width: 20rem;
cursor: pointer;
}
.floating-toolbar .toolbar-btn:last-child {
border-bottom: none;
}
.floating-toolbar .toolbar-btn.active {
color: #fff;
}
.floating-toolbar .toolbar-btn .toolbar-icon {
position: absolute;
text-align: center;
width: 1.5rem;
top: 0.5rem;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/js/all.min.js"></script>
<div id="studio-toolbar" class="floating-toolbar top left minimized">
<div class="toolbar-btn maximize-button">
<div class="toolbar-label"> </div>
<div class="toolbar-icon"><i class="fas fa-bars"></i></div>
</div>
<div class="toolbar-btn active">
<div class="toolbar-label">Edit Text</div>
<div class="toolbar-icon"><i class="fas fa-font"></i></div>
</div>
<div class="toolbar-btn">
<div class="toolbar-label">Element Properties</div>
<div class="toolbar-icon"><i class="fas fa-edit"></i></div>
</div>
<div class="toolbar-btn toolbar-dropdown">
<div class="toolbar-label">Layout Structure</div>
<div class="toolbar-icon"><i class="fas fa-grip-horizontal"></i></div>
<div class="toolbar-dropdown-menu">
<div class="toolbar-btn">
<div class="toolbar-label">Column Offset</div>
<div class="toolbar-icon"><i class="fas fa-long-arrow-alt-right"></i></div>
</div>
<div class="toolbar-btn">
<div class="toolbar-label">Column Width</div>
<div class="toolbar-icon"><i class="fas fa-arrows-alt-h"></i></div>
</div>
<div class="toolbar-btn">
<div class="toolbar-label">Add Row</div>
<div class="toolbar-icon"><i class="fas fa-plus-square"></i></div>
</div>
</div>
</div>
</div>
In your code example I see dropdown. Just background-color is white so it is not visible.
.floating-toolbar {
position: fixed;
z-index: 1031;
background: #333;
color: rgba(255, 255, 255, 0.5);
}
.floating-toolbar.left {
left: 0;
}
.floating-toolbar.left .toolbar-btn .toolbar-icon {
right: 0.5rem;
}
.floating-toolbar.left .toolbar-dropdown > .toolbar-dropdown-menu {
position: absolute;
left: 21rem;
top: 0;
background-color: #333;
}
.floating-toolbar.left.minimized {
left: -18.5rem;
}
.floating-toolbar .toolbar-btn {
position: relative;
border-bottom: 1px solid rgba(255, 255, 255, .5);
padding: 0.5rem;
font-size: 1rem;
width: 20rem;
cursor: pointer;
}
.floating-toolbar .toolbar-btn:last-child {
border-bottom: none;
}
.floating-toolbar .toolbar-btn.active {
color: #fff;
}
.floating-toolbar .toolbar-btn .toolbar-icon {
position: absolute;
text-align: center;
width: 1.5rem;
top: 0.5rem;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/js/all.min.js"></script>
<div id="studio-toolbar" class="floating-toolbar top left minimized">
<div class="toolbar-btn maximize-button">
<div class="toolbar-label"> </div>
<div class="toolbar-icon"><i class="fas fa-bars"></i></div>
</div>
<div class="toolbar-btn active">
<div class="toolbar-label">Edit Text</div>
<div class="toolbar-icon"><i class="fas fa-font"></i></div>
</div>
<div class="toolbar-btn">
<div class="toolbar-label">Element Properties</div>
<div class="toolbar-icon"><i class="fas fa-edit"></i></div>
</div>
<div class="toolbar-btn toolbar-dropdown">
<div class="toolbar-label">Layout Structure</div>
<div class="toolbar-icon"><i class="fas fa-grip-horizontal"></i></div>
<div class="toolbar-dropdown-menu">
<div class="toolbar-btn">
<div class="toolbar-label">Column Offset</div>
<div class="toolbar-icon"><i class="fas fa-long-arrow-alt-right"></i></div>
</div>
<div class="toolbar-btn">
<div class="toolbar-label">Column Width</div>
<div class="toolbar-icon"><i class="fas fa-arrows-alt-h"></i></div>
</div>
<div class="toolbar-btn">
<div class="toolbar-label">Add Row</div>
<div class="toolbar-icon"><i class="fas fa-plus-square"></i></div>
</div>
</div>
</div>
</div>
This is the portion of my HTML: I want to have to the text fixed to an image and not disappear when I stop hovering on the text.
.overlay1 {
position: relative;
bottom: 0;
background: rgb(0, 0, 0);
background: rgba(0, 0, 0, 0.5); /* Black see-through */
color: #f1f1f1;
width: 100%;
transition: .5s ease;
opacity:0;
color: white;
font-size: 20px;
padding: 20px;
text-align: center;
}
/*Test hover*/
.container1:hover .overlay1 {
opacity: 0.5;
}
<div class="container1">
<a href="/content/gallery">
<div class="columny">
<div class="row1">
<img src="sites/chau.ac.zm/themes/chau/images/AF.jpg" alt="Snow" class="image" style="width:100%">
<!-- <div class="overlay1"> -->
<div class="overlay1">Gallery</div>
<!-- </div> -->
</div>
</div>
</a>
</div>
If I get you right, you want div.overlay1 to
be invisible initially
be visible on hover over div.container1
stay visible even if you hover out of div.container1
You cannot achieve 3. without using JavaScript.
I suggest this code:
/* You need this container to limit the .overlay1 position */
.img-container {
position: relative;
}
.overlay1 {
position: absolute;
bottom: 0;
background: rgb(0, 0, 0);
background: rgba(0, 0, 0, 0.5); /* Black see-through */
color: #f1f1f1;
width: 100%;
transition: .5s ease;
opacity:0;
color: white;
font-size: 20px;
padding: 20px;
text-align: center;
}
/*Test hover - change :hover to class .visible */
.container1.visible .overlay1 {
opacity: 0.5;
}
<div id="container1" class="container1">
<a href="/content/gallery">
<div class="columny">
<div class="row1">
<div class="img-container">
<img src="https://images.unsplash.com/photo-1462899006636-339e08d1844e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=750&h=150&q=80" alt="Snow" class="image" style="width:100%">
<!-- <div class="overlay1"> -->
<div class="overlay1">Gallery</div>
<!-- </div> -->
</div>
</div>
</div>
</a>
</div>
<script>
// get element
var container1 = document.getElementById("container1");
// add hover event function
container1.addEventListener("mouseover", function() {
container1.className = "container1 visible";
});
</script>
See the solution if it works!
Just one question:
If you need a text to be fixed to an image, then why are you using hover?
.overlay1 {
position: absolute;
background: rgb(0, 0, 0);
background: rgba(0, 0, 0, 0.5); /* Black see-through */
color: #f1f1f1;
width: auto;
transition: .5s ease;
opacity:1;
color: white;
font-size: 20px;
padding: 20px;
text-align: center;
right:-20px;
top:50%;
}
.row1{
position:relative;
width:500px; margin:0 auto;
}
<div class="container1">
<a href="/content/gallery">
<div class="columny">
<div class="row1">
<img src="https://image.shutterstock.com/image-photo/field-spring-flowers-sunlight-450w-377208970.jpg" alt="" />
<!-- <div class="overlay1"> -->
<div class="overlay1">Gallery</div>
<!-- </div> -->
</div>
</div>
</a>
</div>
remove class from gallery div
<div class="overlay1">Gallery</div> remove the class and use without any "overlay1"class
I have two rows of 4-boxed divs. The goal is to have a header within each box, and then hovering over the box will present more detailed p text with a faded background. I'm close, I just can't figure out how to actually layer the span overlay on top of the div instead of it being padded out of the way. Any help would be hugely appreciated!
.box {
width: 200px;
float: left;
box-shadow: inset 1px 1px 40px 0 rgba(90, 90, 90, .25);
margin: 5% auto 0 auto;
background-color: #DE5D40;
background-size: cover;
border-radius: 5px;
overflow: hidden;
}
.overlay {
background: rgba(0, 0, 0, .75);
text-align: center;
padding: 45px 0 66px 0;
opacity: 0;
-webkit-transition: opacity .25s ease;
-moz-transition: opacity .25s ease;
z-index: 10;
}
.box:hover .overlay {
opacity: 1;
}
.overlayText {
font-family: Helvetica;
font-weight: 14;
color: rgba(255, 255, 255, .85);
font-size: 14px;
}
.one-fourth.box {
margin-bottom: 20px;
height: 130px;
}
/* Column Classes
Link: http://twitter.github.io/bootstrap/assets/css/bootstrap-responsive.css
--------------------------------------------- */
.five-sixths,
.four-sixths,
.one-fourth,
.one-half,
.one-sixth,
.one-third,
.three-fourths,
.three-sixths,
.two-fourths,
.two-sixths,
.two-thirds {
float: left;
margin-left: 2.564102564102564%;
}
.one-half,
.three-sixths,
.two-fourths {
width: 48.717948717948715%;
}
.one-third,
.two-sixths {
width: 31.623931623931625%;
}
.four-sixths,
.two-thirds {
width: 65.81196581196582%;
}
.one-fourth {
width: 23.076923076923077%;
}
.three-fourths {
width: 74.35897435897436%;
}
.one-sixth {
width: 14.52991452991453%;
}
.five-sixths {
width: 82.90598290598291%;
}
.first {
clear: both;
margin-left: 0;
}
<div class="one-fourth first box box1">
<h3>SEO</h3>
<div class="overlay">
<span class="overlayText">SEO</span>
</div>
</div>
<div class="one-fourth box box2">
<div class="overlay">
<span class="overlayText">SEO</span>
</div>
</div>
<div class="one-fourth box box3">
<div class="overlay">
<span class="overlayText">SEO</span>
</div>
</div>
<div class="one-fourth box box4">
<div class="overlay">
<span class="overlayText">SEO</span>
</div>
</div>
<div class="one-fourth first box box5">
<div class="overlay">
<span class="overlayText">SEO</span>
</div>
</div>
<div class="one-fourth box box6">
<div class="overlay">
<span class="overlayText">SEO</span>
</div>
</div>
<div class="one-fourth box box7">
<div class="overlay">
<span class="overlayText">SEO</span>
</div>
</div>
<div class="one-fourth box box8">
<div class="overlay">
<span class="overlayText">SEO</span>
</div>
</div>
Check the code below should be what your after.
They key here is positioning.
What you want is a box that overlays its container and has text in the dead center.
In these instances position:absolute & position:relative mean everything.
A small understanding of relativity would help in this situation but until you crack open a copy of the theory of relativity you can have this.
Your container will be relatively positioned. this means it is positioned relatively to the content surrounding it. But it also has a second cascaded function.
It tell's an absolutely positioned element to behave Absolutely relative to its container.
so when this happens we can use top,bottom,left & right to control where it should sit in the container absolutely.
so what we want to happen is for your text to sit dead center so in this case we tell it to have top,left,bottom & right 0px & margin:auto;
This will tell your element that it is not taking positioning rules from any one point of your container and it wants its marginalizing to be automatically thought out, but since you have defined all the axis that it can be positioned from it will margin it to the center.
Hope it help's you understand a little on why this happens.
.box {
position: relative;
width: 200px;
float: left;
box-shadow: inset 1px 1px 40px 0 rgba(90, 90, 90, .25);
margin: 5% auto 0 auto;
background-color: #DE5D40;
background-size: cover;
border-radius: 5px;
overflow: hidden;
}
.overlay {
top: 0px;
left: 0px;
position: absolute;
background: rgba(0, 0, 0, .75);
text-align: center;
opacity: 0;
-webkit-transition: opacity .25s ease;
-moz-transition: opacity .25s ease;
z-index: 10;
width:100%;
height:inherit;
}
.box:hover .overlay {
opacity: 1;
}
.overlayText {
position: absolute;
margin: auto;
left: 0px;
right: 0px;
top: 0px;
bottom: 0px;
font-family: Helvetica;
font-weight: 14;
color: rgba(255, 255, 255, .85);
font-size: 14px;
height:15px;
}
.one-fourth.box {
margin-bottom: 20px;
height: 130px;
}
/* Column Classes
Link: http://twitter.github.io/bootstrap/assets/css/bootstrap-responsive.css
--------------------------------------------- */
.five-sixths,
.four-sixths,
.one-fourth,
.one-half,
.one-sixth,
.one-third,
.three-fourths,
.three-sixths,
.two-fourths,
.two-sixths,
.two-thirds {
float: left;
margin-left: 2.564102564102564%;
}
.one-half,
.three-sixths,
.two-fourths {
width: 48.717948717948715%;
}
.one-third,
.two-sixths {
width: 31.623931623931625%;
}
.four-sixths,
.two-thirds {
width: 65.81196581196582%;
}
.one-fourth {
width: 23.076923076923077%;
}
.three-fourths {
width: 74.35897435897436%;
}
.one-sixth {
width: 14.52991452991453%;
}
.five-sixths {
width: 82.90598290598291%;
}
.first {
clear: both;
margin-left: 0;
}
<div class="one-fourth first box box1">
<h3>SEO</h3>
<div class="overlay">
<span class="overlayText">SEO</span>
</div>
</div>
<div class="one-fourth box box2">
<div class="overlay">
<span class="overlayText">SEO</span>
</div>
</div>
<div class="one-fourth box box3">
<div class="overlay">
<span class="overlayText">SEO</span>
</div>
</div>
<div class="one-fourth box box4">
<div class="overlay">
<span class="overlayText">SEO</span>
</div>
</div>
<div class="one-fourth first box box5">
<div class="overlay">
<span class="overlayText">SEO</span>
</div>
</div>
<div class="one-fourth box box6">
<div class="overlay">
<span class="overlayText">SEO</span>
</div>
</div>
<div class="one-fourth box box7">
<div class="overlay">
<span class="overlayText">SEO</span>
</div>
</div>
<div class="one-fourth box box8">
<div class="overlay">
<span class="overlayText">SEO</span>
</div>
</div>
If i understand your problem correctly you need to use position:absolute for your .overlay div to position it on top of your .box div.
You can try this:
.box { position: relative}
.overlay{position:absolute;
top:0px;
left:0px}
Do this:
.box {
position:relative;
}
.overlay {
position:absolute;
top:0;
right:0;
bottom:0;
left:0;
}
I'm trying to get a css only modal popup have 33% rows inside of one of it's containers, however it does not use the space it's allocated. Each row should have the same height (a third of the height left). I've included a fiddle.
.modalDialog {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(0, 0, 0, 0.4);
z-index: 99999;
opacity:0;
pointer-events: none;
}
.modalDialog:target {
opacity:1;
pointer-events: auto;
}
.table {
display: table;
}
.table_cell {
display: table-cell;
}
.full_width {
width: 100%;
}
.full_height {
height: 100%;
}
.third_width {
height: 33.3333%
}
.dark_grey {
background-color: rgb(60, 60, 60);
}
.light_grey {
background-color: rgb(220, 220, 220);
}
.modal_top {
padding: 33px;
}
.modal_close {
float: right;
}
The html:
<div id="open_modal" class="modalDialog full_width">
<div class="table full_width full_height">
<div class="modal_container table_cell full_width">
<div class="modal_content full_width full_height">
<div class="modal_top">
<span class="modal_title">This title throws off the height</span>
X
</div>
<div class="full_height">
<div class="modal_option third_width light_grey">Row 1</div>
<div class="modal_option third_width dark_grey">Row 2</div>
<div class="modal_option third_width light_grey">Row 3</div>
</div>
</div>
</div>
</div>
</div><a href="#open_modal" />Open Modal</a>
https://jsfiddle.net/r7v10kjo/
NEW ANSWER:
I think that all you needed was table rows added. So reworking your html like this:
<div id="open_modal" class="modalDialog">
<div class="modal_container">
<div class="modal_top">
<div class="table_cell title_cell">
<span class="modal_title">This title does not throw off the height</span>
X
</div>
</div>
<div class="modal_body">
<div class="table_cell">
<div class="modal_option light_grey">Row 1</div>
<div class="modal_option dark_grey">Row 2</div>
<div class="modal_option light_grey">Row 3</div>
</div>
</div>
</div>
</div>
<a href="#open_modal" />Open Modal</a>
and your css like this:
.modalDialog {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(0, 0, 0, 0.4);
z-index: 99999;
opacity:0;
pointer-events: none;
}
.modalDialog:target {
opacity:1;
pointer-events: auto;
}
.modal_container {display:table;width:100%; height:100%;}
.modal_top, .modal_body {display:table-row;}
.table_cell {display:table-cell;}
.title_cell {padding:30px;vertical-align:middle;}
.modal_close {float: right;}
.modal_body {height:100%;}
.modal_option {height:33.33333%;}
.dark_grey {background-color: rgb(60, 60, 60);}
.light_grey {background-color: rgb(220, 220, 220);}
gets you what you want, I think.
https://jsfiddle.net/maguijo/uvnm3enz/