Working with hover background Change on a DIV - css

I've been trying to achieve the effect of mouse over on a picture which dims its background and brings over a text on top.
Then I wanted a nice centralized text when I moused over.
These both things were achieved, but then I ran into two small problems.
How can I not dim the text on top when I dim the background of the picture
How can I centralized the text without specifying width and height of the picture (to enable responsive design)
HTML
<div id="bottomWide">
<ul>
<li class="first">
<img src="http://127.0.0.1/www/media/wysiwyg/sub-head1.jpg" alt="">
<div class="all-canvas">
<div class="all-text">
<span class="title">A Heading</span><br>
<span class="text">Couples of Lines of Text will come here</span><br>
<span class="shop">See Details.</span>
</div>
</div>
</li>
<li class="second">
<img src="http://127.0.0.1/www/media/wysiwyg/sub-head1.jpg" alt="">
<div class="all-canvas">
<div class="all-text">
Some text here, style as needed
</div>
</div>
</li>
</ul>
</div>
CSS
#bottomWide{
width:100%;
margin:0 auto;
}
#bottomWide ul{
margin:0;
padding:0;
}
#bottomWide li{
list-style-type: none;
display: inline-block;
width:50%;
text-align:justify;
float: left;
/* For Mouse Over*/
position: relative;
display: inline-block;
}
#bottomWide li:last-child img {
border-left: 4px solid #fff;
}
#bottomWide img{
width:100%;
}
#bottomWide li div.all-canvas{
position: absolute;
top: 0;
left: 0;
/* 100% will equal the dimensions of the image, as nothing else will be inside the .container */
width: 100%;
height: 100%;
color: #fff;
background-color: #000;
opacity: 0;
/* This will create the fade effect */
transition: opacity 0.3s;
-webkit-transition: opacity 0.3s;
/* Include all required vendor prefixes for opacity and transition */
margin: 0 auto;
}
#bottomWide li:last-child div.all-canvas {
margin-left: 4px;
}
#bottomWide li div.all-canvas:hover {
opacity: 0.7;
}
#bottomWide li:last-child div.all-canvas:hover {
opacity: 0.7;
margin-left: 4px;
}
div.all-text {
height:358px; /* This is what I want to change to %*/
width: 623px; /* This is what I want to change to %*/
text-align:center;
border:1px solid silver;
display: table-cell;
vertical-align:middle;
margin: 0 auto;
}
div.all-text span.title { padding: 3px; font: 18px/1.35 "Open Sans", Helvetica, sans-serif; text-transform: uppercase;}
The Output looks something like this:-
(Notice the dim text on top of the picture; hoping to make it solid)
Thanks.

If you set opacity to an element, all children (including the text) will have the opacity as well. You could try changing the background color using rgba:
#bottomWide li div.all-canvas:hover {
background-color: rgba(0,0,0, 0.7);
}
You'll still need to toggle opacity 0 to 1 so it can become visible, but the background-color should be transparent.
Centering the text will be a lot more tricky because you're trying to make it responsive. Since the text won't have a fixed height, you will probably have to use Javascript to calculate it. You could start with this CSS:
.theText {
position: absolute;
top: 50%;
margin-top: -20px; // Should be half of the element height
}
You'll have to use javascript to measure the height of .theText and set a negative margin-top accordingly...

Related

Is there a way to create a header that overlaps on the top of the border of a box using CSS? [duplicate]

I'd like to have a div that looks like this:
Is this possible to do with HTML + CSS? I will also be animating this div with jQuery. When the div is hidden I would like the title and the top line to show.
Yes, but it's not a div, it's a fieldset
fieldset {
border: 1px solid #000;
}
<fieldset>
<legend>AAA</legend>
</fieldset>
You can do something like this, where you set a negative margin on the h1 (or whatever header you are using)
div{
height:100px;
width:100px;
border:2px solid black;
}
h1{
width:30px;
margin-top:-10px;
margin-left:5px;
background:white;
}
Note: you need to set a background as well as a width on the h1
Example: http://jsfiddle.net/ZgEMM/
EDIT
To make it work with hiding the div, you could use some jQuery like this
$('a').click(function(){
var a = $('h1').detach();
$('div').hide();
$(a).prependTo('body');
});
(You will need to modify...)
Example #2: http://jsfiddle.net/ZgEMM/4/
I know a bit late to the party, however I feel the answers could do with some more investigation/input.
I have managed to create the situation without using the fieldset tag - that is wrong anyway as if I'm not in a form then that isn't really what I should be doing.
/* Styles go here */
#info-block section {
border: 2px solid black;
}
.file-marker > div {
padding: 0 3px;
height: 100px;
margin-top: -0.8em;
}
.box-title {
background: white none repeat scroll 0 0;
display: inline-block;
padding: 0 2px;
margin-left: 8em;
}
<aside id="info-block">
<section class="file-marker">
<div>
<div class="box-title">
Audit Trail
</div>
<div class="box-contents">
<div id="audit-trail">
</div>
</div>
</div>
</section>
</aside>
This can be viewed in this plunk:
Outline box with title
What this achieves is the following:
no use of fieldsets.
minimal use of CSS to create effect with just some paddings.
Use of "em" margin top to create font relative title.
use of display inline-block to achieve natural width around the text.
Anyway I hope that helps future stylers, you never know.
Text in Border with transparent text background
.box{
background-image: url("https://i.stack.imgur.com/N39wV.jpg");
width: 350px;
padding: 10px;
}
/*begin first box*/
.first{
width: 300px;
height: 100px;
margin: 10px;
border-width: 0 2px 0 2px;
border-color: #333;
border-style: solid;
position: relative;
}
.first span {
position: absolute;
display: flex;
right: 0;
left: 0;
align-items: center;
}
.first .foo{
top: -8px;
}
.first .bar{
bottom: -8.5px;
}
.first span:before{
margin-right: 15px;
}
.first span:after {
margin-left: 15px;
}
.first span:before , .first span:after {
content: ' ';
height: 2px;
background: #333;
display: block;
width: 50%;
}
/*begin second box*/
.second{
width: 300px;
height: 100px;
margin: 10px;
border-width: 2px 0 2px 0;
border-color: #333;
border-style: solid;
position: relative;
}
.second span {
position: absolute;
top: 0;
bottom: 0;
display: flex;
flex-direction: column;
align-items: center;
}
.second .foo{
left: -15px;
}
.second .bar{
right: -15.5px;
}
.second span:before{
margin-bottom: 15px;
}
.second span:after {
margin-top: 15px;
}
.second span:before , .second span:after {
content: ' ';
width: 2px;
background: #333;
display: block;
height: 50%;
}
<div class="box">
<div class="first">
<span class="foo">FOO</span>
<span class="bar">BAR</span>
</div>
<br>
<div class="second">
<span class="foo">FOO</span>
<span class="bar">BAR</span>
</div>
</div>
<fieldset>
<legend> YOUR TITLE </legend>
<p>
Lorem ipsum dolor sit amet, est et illum reformidans, at lorem propriae mei. Qui legere commodo mediocritatem no. Diam consetetur.
</p>
</fieldset>
You can use a fieldset tag.
<!DOCTYPE html>
<html>
<body>
<form>
<fieldset>
<legend>Personalia:</legend>
Name: <input type="text"><br>
Email: <input type="text"><br>
Date of birth: <input type="text">
</fieldset>
</form>
</body>
</html>
Check this link: HTML Tag
For a duplicate, here another option with transform, no fieldset ( and rounded border required in the duplicates) :
Question
Help. I am not great at UX. I am creating an app in React and using Material UI for the look. I really want to create something like this
Where the "Some Title" is a dynamic field from my database as well as the contents. The thing I cannot figure out is what is the best (non skanky) way to add the title into the outline? Thoughts?
Answer position or transform can help you too :
* {
margin: 0;
padding:0;
box-sizing:border-box;
}
.fieldset {
border: solid;
color: #353fff;
border-radius: 1em;
margin: 2em 1em 1em;
padding:0 1em 1em;
}
.legend {
transform: translatey(-50%);
width: max-content;
background: white;
padding: 0 0.15em;
}
.fieldset li {
list-style-type: " - ";
}
<div class="fieldset">
<h1 class="legend">Some Title</h1>
<ul>
<li>Item</li>
<li>Item</li>
<li>Item</li>
<li>Item</li>
</ul>
</div>
If you are not in a position to add a field set, you can add a background to the element. In my situation, I had different colors in the input element and outside the input element, and also we have a hover color for the input element. So this is a fix I added linear-gradient background with outside color in the top half and transparent color in the bottom half.
I added the transparent color to the bottom half inorder to see the hover color when hovered.
.class-name {
background: linear-gradient(to bottom, #2a2b2d 50%, transparent 50%);
}
From a practical perspective, I think PeterS has the best answer. It's also presented in a very clear, didactical style.
Just to save others a few minutes converting it into more production-style code, I've done the following. Basically, it's what you would think you need: One div box inside another, with the outer div box providing the border, the inner providing the title contents with a negative margin shifting it up. A third div then contains the actual content.
This is the CSS:
.outer-border-box {
border: 2px solid black; border-top:3px solid black;}
.label-source-box {
padding: 0 3px; height: 100px; margin-top: -0.8em; }
.box-title {
background: white none repeat scroll 0 0;
padding: 0 2px;
margin-left: 4em;
font-weight:700; font-size:18px;
font-family: 'Avenir Next',Helvetica, sans-serif; }
This is the html:
<div class="outer-border-box">
<div class="label-source-box">
<span class="box-title">Promotional </span>
<div class="box-contents">
<h2>this is the contents</h2>
</div> </div> </div>
It is possible by using the legend tag.
Refer to http://www.w3schools.com/html5/tag_legend.asp

Angular *ngFor li - how to set item width of two items width?

i have a *ngFor that fill my page with items.
within the ngFor i have banners that i want to display.
but the banners width is different from the other items.
so the banner is clickable only within the width of the original li width.
a half of the banner is just displayed but i can not click on it.
i think the problem is because the other items height is get bigger if banner is showed.
the li original sizes is 200X250 px
and when a banner is showed up the li sizes changed to 200X400.
(the banner height is added to the other items height)
blue = banner
red = clickable
green = unclickable
<ul class="row">
<li
*ngFor="let fav of favoriteLessons2; let i = index"
class="col-12 col-sm-6 col-md-4 col-xl-4">
<div class="item pointer">
<jt-lesson-item
[lesson]="fav"
[userLessonId]="fav.id"
[lessonType]="true">
</jt-lesson-item>
<p-progressBar
class="customProgress"
[value]="func(favoriteLessons[i]) | number:'1.0-0'">
</p-progressBar>
</div>
<div
class="banner pointer"
*ngIf="i > 0 && i%counter==0">
<jt-ngui-in-view
[once]="true"
(inView)="updateBannerWatched(bannersArray[bannerIndex(i)])">
<ng-template>
<img
(click)="updateBannerClicked(bannersArray[bannerIndex(i)])"
[src]="bannersArray[bannerIndex(i)].imageUrl"
(click)="bennerPressed(bannersArray[bannerIndex(i)].id)">
</ng-template>
</jt-ngui-in-view>
</div>
</li>
</ul>
how can i handle this issue ?
thank you !
Edited:
css code :
ul{
text-align: center;
direction: rtl;
height:100%;
padding-top: 40px;
padding-right: 90px;
}
li{
width:100%;
max-width: 200px;
list-style: none;
direction: rtl;
text-align: right;
// display: inline-block;
margin:10px;
padding:10px;
&.banner {
width:100%;
display: block;
padding: 10px;
margin-top:10px;
}
}
img{
display: block;
margin: 10px;
padding-top: 23px;
}
.item{
background-color: #FFF;
border-radius: 4px;
width:200px;
&:hover{
background: rgba(23, 23, 23, 0.8);
border-radius: 4px;
bottom: -4px;
color: #000;
left: -4px;
right: -4px;
top: -4px;
display: block;
opacity: 20;
z-index: 1;
transition-property: all;
transition-duration: 0.2s;
transition-timing-function: ease;
transition-delay: 0s;
padding:1px;
border-radius: 4px;
background-color: rgb(243, 243, 243);
}
}

CSS Can't float left

Hi i have tried allot ways how to fix this, but i cant float div to left side. When i create div its automatically stacks in right top corner and i cant move it only with padding and margin.
My index.php example need to float:left div with class language:
<body class="menu">
<div class="wrapper">
<div class="menu-toggle">
Show menu
</div>
<div class="language">
Select lang
</div>
<header>
<nav class="menu-side">
<ul>
<li>Home</li>
<li>Login</li>
<li>Contact</li>
</ul>
</nav>
</header>
<form action="upload.php" method="POST" enctype="multipart/form-data" id="upload" class="upload">
<fieldset>
<legend>Upload files</legend>
<input type="file" id="file" name="file[]" required multiple>
<input type="submit" id="submit" name="submit" value="Upload">
</fieldset>
<div class="bar">
<span class="bar-fill" id="pb"><span class="bar-fill-text" id="pt"></span></span>
</div>
<div id="uploads" class="uploads">
Uploaded links will apear here.
</div>
</form>
</div>
<footer>
Created by Revix © 2014
</footer>
</body>
And my css is:
html, body { height: 100%; margin-top: 0; }
body { font-family: "Georgia", serif; }
.upload { width:500px; background: #f0f0f0; border: 1px solid #ddd; padding: 20px; vertical-align: center; margin-left: auto; margin-right: auto; }
.upload fieldset { border: 0; padding: 0; margin-bottom: 10px; }
.upload fieldset legend { font-size: 1.2em; margin-bottom: 10px; }
footer { background-color: cornflowerblue; text-align: center; vertical-align: middle; min-width: 542px; }
.wrapper { min-height: 100%; margin-bottom: -100px; clear: both; }
.wrapper:after { content: ""; display: block; }
.wrapper:after, footer { height: 100px; }
header { position: fixed; margin-left: auto; margin-right: auto; }
.uploads a, .uploads span { display: block; }
.bar { width: 100%; background: #eee; padding: 3px; margin-bottom: 10px; box-shadow: inset 0 1px 3px rgba(0,0,0,.2); border-radius: 3px; box-sizing:border-box; }
.bar-fill { height: 20px; display: block; background: cornflowerblue; width: 0; border-radius: 3px;
-webkit-transition:width 0.8s ease; -moz-transition:width 0.8s ease; -o-transition:width 0.8s ease; transition:width 0.8s ease; }
.bar-fill-text { color:#fff; padding: 3px; }
.language { float: left; position: absolute; width: 80px; padding: 3px; }
If you wanna to see my web site: Here
Can you suggest me what to do?
Do you mean this effect? Please see my demo.
Please paste your code to jsbin.com next time. Otherwise it's not convenient for us to resolve your problem.
http://jsbin.com/yivat/1
float:left and position:absolute doesn't work.
remove position:absolute
.language { float: left; width: 80px; padding: 3px; }
Inspecting these elements in my browser they have all the CSS attribute position:absolute; set, which sets them at a absolute position within the window. But these elements seem to have no left and top position set which sets you all elements to window position 0,0 which is left top corner.
I would recommend to set the position to relative position:relative; or define specific positions for your html elements.
Floating left on a absolute positioned element will not work. Try relative to float it or position it on your page with top:px left:px;

Centralized Text over an Image on Mouse Over

I've been trying to achieve the effect of mouse over on a picture which dims its background and brings over a text on top.
Then I wanted a nice centralized text when I moused over.
These both things were achieved, but then I ran into a small problems.
How can I centralized the text without specifying width and height of the picture (to enable responsive design)
The Problem is that If I specify the width/Height, it would show the text perfectly centered, but when I change the page dimensions, it loses the center point.
HTML
<div id="bottomWide">
<ul>
<li class="first">
<img src="http://127.0.0.1/www/media/wysiwyg/sub-head1.jpg" alt="">
<div class="all-canvas">
<div class="all-text">
<span class="title">A Heading</span><br>
<span class="text">Couples of Lines of Text will come here</span><br>
<span class="shop">See Details.</span>
</div>
</div>
</li>
<li class="second">
<img src="http://127.0.0.1/www/media/wysiwyg/sub-head1.jpg" alt="">
<div class="all-canvas">
<div class="all-text">
Some text here, style as needed
</div>
</div>
</li>
</ul>
</div>
CSS
#bottomWide{
width:100%;
margin:0 auto;
}
#bottomWide ul{
margin:0;
padding:0;
}
#bottomWide li{
list-style-type: none;
display: inline-block;
width:50%;
text-align:justify;
float: left;
/* For Mouse Over*/
position: relative;
display: inline-block;
}
#bottomWide li:last-child img {
border-left: 4px solid #fff;
}
#bottomWide img{
width:100%;
}
#bottomWide li div.all-canvas{
position: absolute;
top: 0;
left: 0;
/* 100% will equal the dimensions of the image, as nothing else will be inside the .container */
width: 100%;
height: 100%;
color: #fff;
background-color: #000;
opacity: 0;
/* This will create the fade effect */
transition: opacity 0.3s;
-webkit-transition: opacity 0.3s;
/* Include all required vendor prefixes for opacity and transition */
margin: 0 auto;
}
#bottomWide li:last-child div.all-canvas {
margin-left: 4px;
}
#bottomWide li div.all-canvas:hover {
opacity: 0.7;
}
#bottomWide li:last-child div.all-canvas:hover {
opacity: 0.7;
margin-left: 4px;
}
div.all-text {
height:358px; /* This is what I want to change to %*/
width: 623px; /* This is what I want to change to %*/
text-align:center;
border:1px solid silver;
display: table-cell;
vertical-align:middle;
margin: 0 auto;
}
div.all-text span.title { padding: 3px; font: 18px/1.35 "Open Sans", Helvetica, sans-serif; text-transform: uppercase;}
Thanks.

Connect two elements keeping responsive value

I am creating a simple real estate website and am currently creating the listing page. I would like a product very similar to this here. I cannot gain ideas from the code because I am using the skeleton framework. This is my current progress and code or below.
The two elements; photo of property and body of text are apart (there's a gap in the middle).
And also if you resize the browser the listing is not rendered as a vertical rectangle as it is supposed to.
My raw questions are:
1) How do I connect the image and the body text so there is no space inbetween?
2) How do I make the body text and image the same width when the body text needs to collapse underneath the photo? (When resizing browser or on device)
The HTML
<div class="five columns image">
<img src="Properties/9-Walter-Street-Claremont/Listing.jpg" alt="Listing">
</div>
<div class="ten columns body-info">
<h2>Walter Street <span>$2500/wk</span></h2>
<h3>Claremont, 6010</h3>
<p>Lorem Ipsum</p>
<div class="info">
<ul>
<li><img src="img/bedrooms.png"> 5</li>
<li><img src="img/bathrooms.png"> 3</li>
</ul>
</div>
</div>
The CSS
.body-info {
background-color: #fff;
height: 200px;
-webkit-box-shadow: 0px 1px 1px rgba(0,0,0,0.1);
-moz-box-shadow: 0px 1px 1px rgba(0,0,0,0.1);
box-shadow: 0px 1px 1px rgba(0,0,0,0.1);
margin-bottom: 30px;
padding: 0px;
}
.image a img:hover {
background-color: rgba(0,0,0,0.5);
background-image: url("img/eye.png");
background-position: center center;
background-repeat: no-repeat;
}
.body-info h2 a {
transition: color 0.2s ease-in;
-webkit-transition: color 0.2s ease-in;
color: #428f9c;
font-size: 23px;
font-weight: normal;
}
.image {
width: 270px;
float: left;
}
.body-info {
margin-left: 280px;
}
.body-info h2 a:hover {
color: #0b7587;
}
.body-info span {
margin-right: 15px;
color: #444;
}
.body-info p {
color: #777;
font-size: 16px;
}
.body-info ul {
list-style: none;
}
.body-info ul li {
color: #777;
}
Thank you in advance!
To help you a little bit on the way, you could use the #media on CSS.
With that you can change the style when for example the screen is smaller than a specific width.
HTML:
<div class="wrap">
<div class="image">img</div>
<div class="info">info</div>
</div>
CSS:
.wrap {
background: gray;
min-height: 200px;
padding: 10px;
}
.image {
width: 270px;
height: 180px;
background: lightgray;
display: inline-block;
}
.info {
background: lightsteelblue;
display: inline-block;
}
#media only screen and (max-width:600px){
.image, .info {
width: 100%;
display: block;
}
}
So what the style does is when you have a fullscreen it shows .image and .info next to each other (using display: inline-block;.
When the screen gets resized and smaller than 600px, for both the divs the display property will change to block, making them appear under each other.
JSFiddle DEMO
Referring to the example in your post, the only thing you need to do is to make or find a script that resizes your image when the screen gets smaller.
Hope this helps you.

Resources