I'm trying to do two things here but can't make either work. I've never played with CSS before so I've just been sitting on jsfiddle for a few hours trying to just make this basic div table
The first thing I'm trying to do is get 30px border spacing working. I've tried to enter it everywhere in the CSS and all the cells are still attached instead of having space between them
The second thing is the hover effect. I would like a message to pop up on each cell, but the way I have it now, when you put your mouse over the cell, it shows the hover effect on the entire row
any help would be appreciated. Here's my current code
.BestSeller {
border-spacing: 30px;
display: table;
background-color: #fafafa;
text-align: center;
border-collapse: collapse;
width: 100%;
position: relative;
}
.BestSellerRow {
display: table-row;
}
.BestSellerBody {
display: table-row-group;
}
.BestSellerCell {
display: table-cell;
border: 1px solid #ececec;
padding: 10px;
}
.BestSellerTextBox {
background-color: #ff9225;
display: inline-block;
border-radius: 3px;
cursor: pointer;
color: #ffffff;
padding: 3px 75px;
text-decoration: none;
}
.BestSellerTextBox:hover {
background-color: #ff9f3f;
color: #ffffff;
}
.BestSellerOverlay {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: #008CBA;
overflow: hidden;
width: 100%;
height: 0;
transition: .5s ease;
}
.BestSellerCell:Hover .BestSellerOverlay {
height: 50%;
}
.BestSellerOverlayText {
white-space: nowrap;
color: white;
font-size: 20px;
position: absolute;
overflow: hidden;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
<div class="BestSeller">
<div class="BestSellerBody">
<div class="BestSellerRow">
<div class="BestSellerCell">I Like Eggs<br><br><br><br><br><br><br><br><br>
<div class="BestSellerOverlay">
<div class="BestSellerOverlayText">Hello World</div>
</div>
</div>
<div class="BestSellerCell">This is just a quick test </div>
<div class="BestSellerCell">This is just a quick test </div>
<div class="BestSellerCell">This is just a quick test </div>
</div>
<div class="BestSellerRow">
<div class="BestSellerCell">I Like Eggs<br><br><br><br><br><br><br><br><br>
<div class="BestSellerOverlay">
<div class="BestSellerOverlayText">Why This No Work</div>
</div>
</div>
<div class="BestSellerCell">This is just a quick test </div>
<div class="BestSellerCell">This is just a quick test </div>
<div class="BestSellerCell">This is just a quick test </div>
</div>
</div>
</div>
Firstly, border-spacing work with border-collapse : separate. Add that to .BestSeller and it will do the work. More refer to the MDN.
Secondly, you set .BestSellerOverlay to position: absolute, which is a good start. However, absolute positions the element to its nearest positioned ancestor.. If there is no nearest positioned ancestor, it will fallback to the viewport. Which is the result you see, the overlay attached to the bottom to the page. I apply position: relative to .BestSellerCell, such the overlay will stick to the cell.
.BestSeller {
display: table;
background-color: #fafafa;
text-align: center;
border-collapse: separate;
border-spacing: 30px;
width: 100%;
position: relative;
}
.BestSellerRow {
display: table-row;
}
.BestSellerBody {
display: table-row-group;
}
.BestSellerCell {
display: table-cell;
border: 1px solid #ececec;
padding: 10px;
position: relative;
}
/*==============================================================================
#BestSellerTextBox
==============================================================================*/
.BestSellerTextBox {
background-color: #ff9225;
display: inline-block;
border-radius: 3px;
cursor: pointer;
color: #ffffff;
padding: 3px 75px;
text-decoration: none;
}
.BestSellerTextBox:hover {
background-color: #ff9f3f;
color: #ffffff;
}
/*==============================================================================
#HoverOverlay For Best Selelr
==============================================================================*/
.BestSellerOverlay {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: #008CBA;
overflow: hidden;
width: 100%;
height: 0;
transition: .5s ease;
}
.BestSellerCell:Hover .BestSellerOverlay {
height: 50%;
}
.BestSellerOverlayText {
white-space: nowrap;
color: white;
font-size: 20px;
position: absolute;
overflow: hidden;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
<div class="BestSeller">
<div class="BestSellerBody">
<div class="BestSellerRow">
<div class="BestSellerCell">
I Like Eggs<br> <br> <br> <br> <br> <br> <br> <br> <br>
<div class="BestSellerOverlay">
<div class="BestSellerOverlayText">Hello World</div>
</div>
</div>
<div class="BestSellerCell">This is just a quick test</div>
<div class="BestSellerCell">This is just a quick test</div>
<div class="BestSellerCell">This is just a quick test</div>
</div>
<div class="BestSellerRow">
<div class="BestSellerCell">
I Like Eggs<br> <br> <br> <br> <br> <br> <br> <br> <br>
<div class="BestSellerOverlay">
<div class="BestSellerOverlayText">Why This No Work</div>
</div>
</div>
<div class="BestSellerCell">This is just a quick test</div>
<div class="BestSellerCell">This is just a quick test</div>
<div class="BestSellerCell">This is just a quick test</div>
</div>
</div>
</div>
I advise you to use grid.layoutit, where you'll be able to design tables using the grid layout display.
Try with below code. Where I have made changes.
//CSS
.BestSellerCell {
/* display: table-cell; */
border: 1px solid #ececec;
padding: 10px;
margin: 21px;
float: left;
height: 200px;
}
.BestSellerCell:hover{
background-color:red;
}
.child-span{display:none;}
//HTML -- for each div I have added the child span
<div class="BestSellerCell"><span class="child-span">child span</span> This is just a quick test </div>
//Script -- I have added the mouse event
$('.BestSellerCell').mouseenter(function(){
$(this).find('.child-span').show();
});
$('.BestSellerCell').mouseleave(function(){
$(this).find('.child-span').hide();
});
Related
I wanted to know why my styles of class="project-borders" and class="project-overlay" are not applying to div elements of data-modal="modal3" and data-modal="modal6". These styles are applying to every div element where used, except these two. I don't understand what's the problem even though the classes are the same across every div element. You can see the styles by removing class="project-borders" from div elements of data-modal="modal3" and data-modal="modal6".
Here is the visual representation:- Codepen
Please any help would be appreciated.
My HTML:
<div class="projects">
<div data-modal="modal1" class="project-borders">
<div class="project-overlay">
<p>Coffee Grounds</p>
</div>
<img src="https://upload.wikimedia.org/wikipedia/commons/4/45/A_small_cup_of_coffee.JPG" alt="">
</div>
<div data-modal="modal2" class="project-borders">
<div class="project-overlay">
<p>Startup Employee Directory</p>
</div>
<img src="https://www.hofstra.edu/images/positioning/id-directories.jpg" alt="">
</div>
<div data-modal="modal3" class="project-borders">
<div class="project-overlay">
<p>Words Guessing Game</p>
</div>
<img src="https://images.newindianexpress.com/uploads/user/imagelibrary/2019/10/15/w900X450/PUBG_.JPG" alt="">
</div>
<div data-modal="modal4" class="project-borders">
<div class="project-overlay">
<p>Motorcycle Parallax</p>
</div>
<img src="https://cdp.azureedge.net/products/USA/ZERO/2020/MC/MCY/SR-F/50/BOARDWALK_RED/2000000002.jpg" alt="">
</div>
<div data-modal="modal5" class="project-borders">
<div class="project-overlay">
<p>Picture Portfolio</p>
</div>
<img src="https://media.wired.com/photos/598e35fb99d76447c4eb1f28/master/pass/phonepicutres-TA.jpg" alt="">
</div>
<div data-modal="modal6" class="project-borders">
<div class="project-overlay">
<p>Video Creator Portfolio</p>
</div>
<img src="https://storage.googleapis.com/proudcity/petalumaca/uploads/2020/01/video-infographic.jpg" alt="">
</div>
</div>
My SASS:
.projects{
display: grid;
grid-template-columns: 1fr 1fr 1fr;
width: 80%;
margin: 0 auto;
column-gap: 50px;
row-gap: 50px;
// margin-top: 60px;
padding-top: 6%;
img{
width: 100%;
height: 100%;
cursor: pointer;
}
}
.project-borders{
position: relative;
border: 2px solid #000;
img{
width: 100%;
height: 100%;
cursor: pointer;
position: absolute;
left: 10px;
top: 10px;
}
&::before{
position: absolute;
border: 2px solid #ffde59;
content: "";
display: block;
position: absolute;
top: 25px;
left: 25px;
right: -20px;
bottom: -20px;
}
.project-overlay{
position: absolute;
left: 10px;
top: 10px;
bottom: 0;
transition: .5s;
background-color: rgb(76, 72, 68);
transition: .5s ease;
width: 100%;
height: 100%;
opacity: 0;
& p{
position: absolute;
font-size: 20px;
top: 45%;
width: 100%;
text-align: center;
color: #fff;
transition: .5s;
opacity: 0;
}
}
&:hover .project-overlay{
cursor: pointer;
opacity: 1;
z-index: 1;
}
&:hover .project-overlay p{
cursor: pointer;
display: block;
opacity: 1;
z-index: 1;
}
}
Based on your codepen, it doesn't seem like the 3rd and 6th modals are the problem with the styles displaying. The real problem is that all the content in your modals are absolutely positioned which takes them out of the ordinary context of the document, which causes the project-borders containers to have a height that only consists of the borders. You'll need to define a fixed height for that container for things to display correctly like so...
.project-borders {
position: relative;
border: 2px solid #000;
height: 209px;
}
Okay, so I thought that the grid was perfectly aligned to the center, only to realise that it was a few pixels out. I completely stripped all of my attempts at centering and looked online but couldn't find anything.
I know I can use CSS Grids, Flexbox etc. but I am trying to learn how to create websites without using any aid. So I can learn the reasoning behind things.
Fiddle:
https://jsfiddle.net/8L9ye7nj/5/
Grid HTML:
<div class="box-wrapper">
<div class="box-container">
<div class="box" id="stethoscope">
<div class="box-label">
<p>Book an appointment</p>
</div>
</div>
<div class="box" id="prescription">
<div class="box-label">
<p>Request a repeat prescription</p>
</div>
</div>
<div class="box" id="group">
<div class="box-label">
<p>Join the Patient Group</p>
</div>
</div>
</div>
</div>
Grid CSS:
.box {
float: left;
width: 25%;
height: 300px;
background-color: #252625;
color: #FFF;
position: relative;
padding: 15px;
margin: 0.5%;
}
.box-label {
position: absolute;
bottom: 0;
text-align: center;
background-color: rgba(0,0,0,0.5);
width: 100%;
padding: 7px 0;
left: 0;
}
.box-label:hover {
animation: box-stretch 1s forwards ease-in-out;
cursor: pointer;
}
.box-container {
width: 90%;
}
.box-container::after {
content: "";
clear: both;
display: table;
}
.box-wrapper {
background-color: #B21645;
padding: 30px;
}
How can you divide the box and center them?
You can use calc to use mathematical expressions to calculate height, widths etc in css. You can divide the width by three here for the box.
.box {
display: inline-block;
width: calc(100% / 3);
}
Things to consider
Mind the space between inline-block elements. You can read more about
that here.
Avoid using floats as much as possible. Most layouts done with float can be achieved with inline-block. Floats are simply meant to take an element, put it to one side, and let other content flow around it. That’s all.
box-wrapper and box-container either one is only needed to wrap the contents inside.
Code Snippet
body {
margin: 0;
padding: 0;
}
* {
box-sizing: border-box;
}
.box-wrapper {
background-color: #b21645;
padding: 20px;
}
.box {
position: relative;
display: inline-block;
width: calc(100% / 3);
padding: 0 10px;
height: 300px;
overflow: hidden;
}
.box img {
height: 100%;
width: 100%;
object-fit: cover;
object-position: left top;
}
.box-label {
position: absolute;
bottom: 0;
width: calc(100% - 20px);
text-align: center;
background-color: rgba(0, 0, 0, .6);
padding: 10px 0;
transition: padding 0.3s;
}
.box-label:hover {
padding: 25px 0;
}
.box-label p {
font-family: Helvetica;
color: white;
font-size: 20px;
}
<div class="box-wrapper">
<div class="box">
<img src="https://images.unsplash.com/photo-1509027572446-af8401acfdc3?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=ef8f839186c5a6055d2802005b575194&auto=format&fit=crop&w=500&q=60" alt="" />
<div class="box-label">
<p>Some Title Here</p>
</div>
</div><div class="box">
<img src="https://images.unsplash.com/photo-1509027572446-af8401acfdc3?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=ef8f839186c5a6055d2802005b575194&auto=format&fit=crop&w=500&q=60" alt="">
<div class="box-label">
<p>Some Title Here</p>
</div>
</div><div class="box">
<img src="https://images.unsplash.com/photo-1509027572446-af8401acfdc3?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=ef8f839186c5a6055d2802005b575194&auto=format&fit=crop&w=500&q=60" alt="">
<div class="box-label">
<p>Some Title Here</p>
</div>
</div>
</div>
I've come up with what seems like a very hacky, non-semantic way to code a design that I'd like to use. Basically, it's a set of 4 equal-sized circles, distributed so their centers are the same as those of equilateral triangles. I've used a bunch of presentational divs to solve two issues: (1) to get the spacing of the circles right, I need their bounding boxes to overlap; and (2) to vertically space text in the circles without changing their size, it seems like I need to use display:table in my CSS.
It works, but I hate it, and I feel like there has to be a better way. I am new to CSS, and this method is the result of a fair amount of research about how to solve this design problem.
The design is at this codepen: http://codepen.io/bhagerty/pen/rejEPZ
(I put borders on a bunch of the elements just to show the structure.)
Here is the HTML:
<body>
<h1 id="home_title">test</h1>
<div id="container_1">
<div id="picture" class="box">
<div class="circle_outer">
<div class="circle_inner">
<div class="inner-text">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/58/%22In_Which_We_Serve%22_Advertisement_1943.jpg/1024px-%22In_Which_We_Serve%22_Advertisement_1943.jpg" width=100%; />
</div>
</div>
</div>
</div>
<div id="dog" class="box">
<div class="circle_outer">
<div class="circle_inner">
<div class="inner-text">
dog
</div>
</div>
</div>
</div>
<div id="shoes" class="box">
<div class="circle_outer">
<div class="circle_inner">
<div class="inner-text">
shoes
</div>
</div>
</div>
</div>
<div id="dance" class="box">
<div class="circle_outer">
<div class="circle_inner">
<div class="inner-text">
dance
</div>
</div>
</div>
</div>
<div id="footer_1">
Footer<br>
test
</div>
</div>
</body>
Here is the CSS:
* {
box-sizing: border-box;
padding: 0;
margin: 0;
font-size: 16px;
}
h1#home_title {
text-align: center;
font-size: 3rem;
margin: 0;
padding: .1rem 0 .5rem 0;;
background-color: grey;
}
div#container_1 {
border: green solid 5px;
width: 320px;
margin: auto;
position: relative;
}
div.box {
border: red solid 1px;
position: absolute;
width: 53.6%;
text-align: center;
background-color: transparent;
}
/*pseudo-element to give relative height,
per http://jsfiddle.net/simevidas/PFPDU/
and http://www.mademyday.de/css-height-equals-width-with-pure-css.html */
div.box::before {
content: "";
display: block;
padding-top: 100%;
height: 0;
}
/* if inner text has position relative, it influences the size of the containing box */
/*setting all of the positions to zero forces it inside the circle for some reason */
.circle_outer {
position: absolute;
overflow: hidden;
border: black solid 2px;
border-radius: 50%;
/* to create breathing room all around, set top and left to 1/2 of 100% - width (where width = height) */
top: 5%;
left: 5%;
width: 90%;
height: 90%;
}
.circle_inner {
/* border: grey solid 5px; */
display: table;
width: 100%;
height: 100%;
}
.inner-text {
display: table-cell;
/* border: green solid 2px; */
font-size: 2em;
vertical-align: middle;
}
/*First bounding box is at upper left corner */
div#picture {
overflow: hidden;
left: 0;
margin-top: 0;
}
/*Percent positions all based on W, derived from fact
that bounding boxes circumscribe tangent circles, and
circle centers are connected by equilateral triangles */
div#dog {
left: 46.4%;
margin-top: 26.8%;
}
div#shoes {
left: 0;
margin-top: 53.6%;
}
div#dance {
left: 46.4%;
margin-top: 80.4%;
}
div#footer_1 {
border: red solid 2px;
position: relative;
width: 100%;
left: 0;
margin-top: 137%;
text-align: center;
background-color: blue;
}
I much appreciate any thoughts or help. Thanks!
Well, IMO what you've done is really good. I wouldn't be too concerned about the extra divs.
But, it can be done with fewer divs, making use of float and margins.
Codepen is here
html {
font-size: 16px;
}
h1#home_title {
text-align: center;
font-size: 3rem;
margin: 0;
padding: .1rem 0 .5rem 0;;
background-color: grey;
}
div#container_1 {
border: green solid 5px;
width: 320px;
margin: auto;
position: relative;
box-sizing: border-box;
}
div.box {
border: red solid 1px;
position: relative;
float:left;
width: 53.6%;
text-align: center;
background-color: transparent;
box-sizing:border-box;
margin-bottom:-27%;
}
div.box:nth-child(2n) {
float:right;
}
div.box:nth-child(2n+1) {
float:left;
}
/*pseudo-element to give relative height,
per http://jsfiddle.net/simevidas/PFPDU/
and http://www.mademyday.de/css-height-equals-width-with-pure-css.html */
div.box::before {
content: "";
display: block;
padding-top: 100%;
height: 0;
}
/* if inner text has position relative, it influences the size of the containing box */
/*setting all of the positions to zero forces it inside the circle for some reason */
.featuring {
position: absolute;
overflow: hidden;
border: black solid 2px;
border-radius: 50%;
/* to create breathing room all around, set top and left to 1/2 of 100% - width (where width = height) */
top: 5%;
left: 5%;
width: 90%;
height: 90%;
font-size: 2em;
}
.featuring:before {
content:'';
margin-left:-0.25em;
display:inline-block;
vertical-align:middle;
height:100%;
}
/*Percent positions all based on W, derived from fact
that bounding boxes circumscribe tangent circles, and
circle centers are connected by equilateral triangles */
div#footer_1 {
border: red solid 2px;
position: relative;
width: 100%;
left: 0;
margin-top: 137%;
text-align: center;
background-color: blue;
clear:both;
}
<body>
<h1 id="home_title">test</h1>
<div id="container_1">
<div id="picture" class="box">
<div class="featuring">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/58/%22In_Which_We_Serve%22_Advertisement_1943.jpg/1024px-%22In_Which_We_Serve%22_Advertisement_1943.jpg" width=100%; />
</div>
</div>
<div id="dog" class="box">
<div class="featuring">
dog
</div>
</div>
<div id="shoes" class="box">
<div class="featuring">
shoes
</div>
</div>
<div id="dance" class="box">
<div class="featuring">
dance
</div>
</div>
<div id="footer_1">
Footer<br>
test
</div>
</div>
</body>
I have a carousel with images/descriptions in it and my height:auto does not work properly. Height computed is too big
JSBin: JSBin
I can only guess that this is because my .shadow class which is relative with height 150px.
Please take a look on it.
Edit: code as requested
This is result of one item from carousel
<div class="carousel2">
<div class="carousel">
<div class="owl-carousel owl-theme" id="owl-example" style=
"opacity: 1; display: block;">
<div class="owl-wrapper-outer">
<div class="owl-wrapper" style=
"width: 4092px; left: 0px; display: block; -webkit-transform: translate3d(0px, 0px, 0px); -webkit-transition: all 200ms ease; transition: all 200ms ease;">
<div class="owl-item" style="width: 341px;">
<div class="pc">
<div class="c">
<img alt="image" src=
"http://www.ramp-alberta.org/_system/ThumbnailCache/UserFilesImageAug~16~Site~1_004jpg.300.-1.-1108757834.jpg">
<div class="shadow">
<div class="description">
Event1
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
And here is my css
.carousel2
{
overflow: hidden;
/* height:400px; */
background-color: #344754;
}
.carousel
{
width: 1364px;
float: left;
height: auto;
}
.shadow
{
position: relative;
bottom: 150px;
left: 0;
right: 0;
background: rgba(222,103,21,0.7);
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#B2344855', endColorstr='#B2344855');
height: 150px;
vertical-align: middle;
z-index: 1;
width: 100%;
text-align: center;
}
.pc{
/* border: blue 1px solid; */
width: 1%;
display: table;
margin: auto;
height: auto;
overflow: hidden;
}
.c
{
overflow: hidden;
}
.description
{
padding-top: 15px;
font-family: "FSRufus";
font-size: 30px;
font-weight: bold;
color: white;
}
.owl-item
{
overflow: hidden;
}
You should give class carousel2 a min-height so that CSS will know till what it needs to scale image. Try to use exact size images to save processing time. Also remove height from class Shadow. This should help.
I'm writing an online chatting widget and I plan to design it as Facebook's.
In my page, a bar is fixed on the bottom, and every chat rooms are contained in that bar.
While the bar's height is fixed, the chat rooms cannot extend its height outside the bar.
Is there any method to achieve this? I have used z-index, !important, and overflow, but all failed.
CSS:
#SNbar {
background-color: rgba(203, 203, 203, 0.80);
position: fixed;
bottom: 0;
width: 100%;
height: 25px;
z-index: 900;
overflow: visible;
}
#chatSessions {
position: relative;
bottom: 0;
float:right;
z-index: 901;
}
.chatSession {
/*
position: fixed;
bottom: 0;
*/
padding: 0 10px 0 0;
width: 260px;
float: right;
z-index: 999;
}
.CStitle {
height: 25px;
background-color:#3B5998;
cursor: pointer;
}
.CStitle .titleText{
text-decoration: none;
font-weight:bold;
color: #FFFFFF;
text-decoration: none;
line-height:2em;
}
.CSbody {
background-color: #FFFFFF;
opacity: 1.0;
display: none;
height: 0 !important;
}
.opened{
min-height: 260px !important;
display: block;
}
.CSMsgContainer {
overflow-y: scroll;
height: 210px;
}
HTML:
<div id="SNbar">
<div id="chatSessions">
<div class="chatSession" id="Div4">
<div class="CStitle" onclick="toggleChatSession(this)"><span class="titleText">Title (With Whom)</span> </div>
<div class="CSbody">
<div class="CSMsgContainer">
<div class="message">b: test1</div>
<div class="message">b: this is used to test css</div>
<div class="message">a: This may be help</div>
</div>
</div>
</div>
<div class="chatSession" id="Div8">
<div class="CStitle" onclick="toggleChatSession(this)"><span class="titleText">Title (With Whom)</span></div>
<div class="CSbody">
<div class="CSMsgContainer">
<div id="Div9" class="message">d: hi C!!</div>
<div id="Div10" class="message">c: Hello D~~</div>
<div id="Div11" class="message">
c: We are the second chat session
</div>
</div>
</div>
</div>
</div>
</div>
position:absolute for the inner container is what you want. Then you can put it anywhere you want. Best is probably to set position:relative to the parent container, so that the position of the inner containers will using the parent as "base".
If I am not wrong, from this when you click on .CStitle, you are toggling the CSbody. So for this, you can set position relative to chatSession class and to the CSbody, give position absolute.
.chatSession {
position: relative;
padding: 0 10px 0 0;
width: 260px;
float: right;
z-index: 999;
}
.CStitle {
height: 25px;
background-color:#3B5998;
cursor: pointer;
}
.CSbody {
position:absolute;
background-color: #FFFFFF;
opacity: 1.0;
display: none;
height: 0;
bottom:25px;
}
.opened{
min-height: 260px;
display: block;
}
.CSMsgContainer {
overflow-y: scroll;
height: 210px;
}
Hope this helps.
try adding this
#SNbar {
height: 25px;
max-height: 25px;
}