My codepen
http://codepen.io/leongaban/pen/sBvfL
So having a strange issue, I'm trying to get the background of the #portfolio div to stretch to contain the thumbnails below which are in an ul list inside of the portfolio div.
However 100% or auto doesn't affect the height. I have to set a static height, like 1000px. To get the background to cover the thumbs. However I'm trying to not set a static height since the thumbnails will get longer.
Perhaps I've been coding this too long, how would you code this?
HTML
<div id="portfolio">
<div class="portfolio-nav">
<h1>Portfolio</h1>
</div>
<div id="showcase-holder">
<div id="showcase-div">
<ul id="portfolio-thumbs">
<li>
<a href="/portfolio/chipestimate">
<img class="role-thumb" src="http://leongaban.com/images/thumb_chipestimate.jpg" alt="ChipEstimate"/>
</a><p>ChipEstimate</p>
</li>
<li>
<a href="/portfolio/shabang" title="Shabang">
<img class="role-thumb" src="http://leongaban.com/images/thumb_shabang.jpg" alt="Shabang"/>
</a><p>Shabang</p>
</li>
</ul>
</div>
</div>
CSS
body {
background: brown;
}
#portfolio {
position: relative;
width: 100%;
height: 50%;
background: #fff;
border-top: 2px solid #ccc;
z-index: 1;
}
#portfolio ul { list-style: none; }
.portfolio-nav { margin: 0 0 20px 0; }
.portfolio-nav h1 {
padding: 30px 0 10px 0;
text-align: center;
font-size: 2.5em;
font-weight: 700;
color: #d74927;
text-shadow: 1px 1px #ccc;
}
#showcase-holder {
position: relative;
width: 80%;
height: 100%;
margin: 0 auto;
border-bottom: 2px solid #ccc;
}
#portfolio-thumbs {
position: relative;
float: left;
list-style-type: none;
margin: 0 0 40px 0;
padding: 0 0 0 5%;
width: 100%;
height: 100%;
}
#portfolio-thumbs li {
position: relative;
float: left;
width: 20%;
margin: 1%;
text-align: center;
padding: 5px 5px 15px 5px;
background-size: 100% auto;
overflow: hidden;
background: white;
-webkit-transition: background .3s;
-moz-transition: background .3s;
-ms-transition: background .3s;
transition: background .3s;
}
#portfolio-thumbs li:hover {
color: #fff;
background: #d74927;
-webkit-transition: background .5s;
-moz-transition: background .5s;
-ms-transition: background .5s;
transition: background .5s;
}
#portfolio-thumbs li a {
color: #333;
text-decoration: none;
}
#portfolio-thumbs li p {
padding: 10px 0 0 0;
}
#portfolio-thumbs li img.role-thumb {
width: 95%;
min-width: 170px;
padding-top: 5px;
}
Parents will normally expand to the height of their children, though won't in case the children are relative.
You can remove positions and floats to accomplish expanding.
In order to expand a parentdiv based on positioned children try overflow: auto; on #portfolio. This will make #portfolio expand to the height of its children. As seen on this fork of your example.
overflow: auto; will actually let your browser decide, which normally renders this to overflow: hidden;. Though I tend to use overflow: auto; to prevent issues with scrollbars as the page possibly expands later on.
You have added float to your li elements, which means that the parent will not expand to contain these elements.
You can work around this by adding a clearing div.
<div style="clear:both;"></div>
after the showcase-holder div.
Adding overflow: hidden to both #showcase-div and #portfolio-thumbs should do it for you.
http://jsfiddle.net/5SFFP/
Related
I was experimenting around with box-shadows and thought it would be possible to make a window effect (as in the example below) so that you can hide text or an image underneath that can only be seen - or "opened" - when you hover/click.
Unfortunately it doesn't work like that, because the shadow will always be below the text or image, which I didn't realize until I was done.
Is there a fix for this, or should I use another way to get the same result without box-shadows?
body {
background: #20262E;
}
.window {
display: inline-block;
height: 200px;
width: 300px;
margin: 20px;
background: #F8F8F8;
text-align: center;
line-height: 200px;
}
.window {
box-shadow: inset 0 200px #0084FF;
transition: box-shadow 1s ease-in-out;
}
.window:hover {
box-shadow: inset 0 0 #0084FF;
}
<div class="window">
box 1
</div>
*Note: I haven't been able to figure out why the transition is flickering :/
Agree that it's probably a bug with box-shadow. If you're looking for another CSS way to handle this, how about the :before or :after pseudo elements?
body {
background: #20262E;
}
.window {
display: inline-block;
height: 200px;
width: 300px;
margin: 20px;
background: #F8F8F8;
text-align: center;
line-height: 200px;
position: relative;
}
.window:after {
content: '';
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background: #0084FF;
transition: bottom 1s ease-in-out;
}
.window:hover:after {
bottom: 100%;
}
<div class="window">box 1</div>
I'm very new to CSS and HTML combination. I'm trying to make use of following code for dropdown menu. But when mouse is moved away from dropdown menu, it gets closed. I would like to close it onclick outside the dropdown menu. Can anyone suggest me a fix in CSS to achieve this? JSFiddle for me code is at following location Fiddle link. Your help will be much appreciated. HTML looks like this.
<div id="main">
<div class="wrapper">
<div class="content">
<content>
<div>
<ul>
<li>Lorem ipsum dolor</li>
<li>Consectetur adipisicing</li>
<li>Reprehenderit</li>
<li>Commodo consequat</li>
</ul>
</div>
</content>
</div>
<div class="parent">Drop Down Parent 1</div>
</div>
And CSS looks like this
#main {
margin: 30px 0 50px 0;
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
}
#main .wrapper {
display: inline-block;
width: 180px;
margin: 0 10px 0 0;
height: 20px;
position: relative;
}
#main .parent {
height: 100%;
width: 100%;
display: block;
cursor: pointer;
line-height: 30px;
height: 30px;
border-radius: 5px;
background: #F9F9F9;
border: 1px solid #AAA;
border-bottom: 1px solid #777;
color: #282D31;
font-weight: bold;
z-index: 2;
position: relative;
-webkit-transition: border-radius .1s linear, background .1s linear, z-index 0s linear;
-webkit-transition-delay: .8s;
text-align: center;
}
#main .parent:hover, #main .content:hover ~ .parent {
background: #fff;
-webkit-transition-delay: 0s, 0s, 0s;
}
#main .content:hover ~ .parent {
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
z-index: 2;
}
#main .content {
position: absolute;
top: 0;
display: active;
z-index: 2;
height: 0;
width: 180px;
padding-top: 30px;
-webkit-transition: height .5s ease;
-webkit-transition-delay: .4s;
border: 1px solid #777;
border-radius: 5px;
box-shadow: 0 1px 2px rgba(0, 0, 0, .4);
}
#main .wrapper:active .content {
height: 123px;
z-index: 3;
-webkit-transition-delay: 0s;
}
#main .content div {
background: #fff;
margin: 0;
padding: 0;
overflow: hidden;
height: 100%;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
}
#main .content:hover {
height: 123px;
z-index: 3;
-webkit-transition-delay: 0s;
}
I'm looking at something like this and will set new content to content tag. What I'm really looking at is following
1) Click on dropdown menu. Show the dropdown.
2) When hovered on it keep displaying. When hover outside dropdown keep showing it.
3) When clicked somewhere outside dropdown then close the dropdown.
I know I'm using hover selector so my behavior is like that. But I want to covert it to above behavior and I don't know how to do it.
<div id="main">
<div class="wrapper">
<div class="content">
<content>
</content>
</div>
<div class="parent">Drop Down Parent 1</div>
Your HTML is wrong. If you see, you have wrapped <li> inside the <a> tag. That's a basic issue you have. And there are other issues.
Change your existing HTML:
<a><li>...</li></a>
To the right form:
<li><a>...</a></li>
And then the click works. An <a> cannot contain an <li> inside it. So the click doesn't happen.
I want to center my text in a relative height div which contains an image. I use absolute position but when my text is on two lines, the text is not centered. I've already tried to use a table but it doesn't work due to the img.
HTML:
<div id="hubs">
<h3>Nos Hubs</h3>
<hr>
<a class="thumbnail vignette-hub" href="http://kkw.fr">
<img style="opacity: 0.6;filter: alpha(opacity=60);" alt="AĆ©roport de Nantes" src="http://kkw.fr/uploads/upload-center/nantes-vue-aerienne091501270208.png" width="100%" />
<p class="txt-hub-image">
Hub de</br>Nantes
</p>
</a>
</div>
CSS :
.txt-hub-image {
z-index: 100;
position: absolute;
left: 0px;
top: 50%;
width: 100%;
height: 100%;
text-align: center;
text-decoration: none;
color: white;
font-weight: bold;
font-size: 16px;
}
.vignette-hub {
position: relative;
width: 25%;
min-width: 135px;
}
.thumbnail {
display: block;
padding: 4px;
margin-bottom: 20px;
line-height: 1.42857143;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 4px;
-webkit-transition: border .2s ease-in-out;
-o-transition: border .2s ease-in-out;
transition: border .2s ease-in-out;
}
.thumbnail > img,
.thumbnail a > img {
margin-right: auto;
margin-left: auto;
}
a.thumbnail:hover,
a.thumbnail:focus,
a.thumbnail.active {
border-color: #337ab7;
}
.thumbnail .caption {
padding: 9px;
color: #333;
}
Do you have any ideas ?
There are a few changes required to your snippet to make it automatically work for all dimensions:
p tags by default have a margin-top. If you don't reset it, then absolutely positioning it at 50% would become 50% + margin-top. This needs to be reset.
When you absolutely position an element at top: 50%, the box gets positioned at 50% height of the container and text keeps getting added from that position on. So, to match the center of the text block with the center of the parent, you have to translate the box with the text up by 50% of its own size. This can be done by adding transform: translateY(-50%).
You don't need to add a height: 100% on the p tag and it can be removed.
Note: Using transform method for positioning needs CSS3 support but I assume this shouldn't be a problem because you are already using transition.
If you want to support non CSS3 compatible browsers, have a look at the other approaches mentioned here. I have added a different answer just to explain the first two points I had mentioned above.
.txt-hub-image {
z-index: 100;
position: absolute;
left: 0px;
top: 50%;
width: 100%;
text-align: center;
text-decoration: none;
color: white;
font-weight: bold;
font-size: 16px;
/* added to fix the vertical centering */
margin-top: 0px;
transform: translateY(-50%);
}
.vignette-hub {
position: relative;
width: 25%;
min-width: 135px;
}
.thumbnail {
display: block;
padding: 4px;
margin-bottom: 20px;
line-height: 1.42857143;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 4px;
-webkit-transition: border .2s ease-in-out;
-o-transition: border .2s ease-in-out;
transition: border .2s ease-in-out;
}
.thumbnail > img,
.thumbnail a > img {
margin-right: auto;
margin-left: auto;
}
a.thumbnail:hover,
a.thumbnail:focus,
a.thumbnail.active {
border-color: #337ab7;
}
.thumbnail .caption {
padding: 9px;
color: #333;
}
<div id="hubs">
<h3>Nos Hubs</h3>
<hr>
<a class="thumbnail vignette-hub" href="http://kkw.fr">
<img style="opacity: 0.6;filter: alpha(opacity=60);" alt="AĆ©roport de Nantes" src="http://kkw.fr/uploads/upload-center/nantes-vue-aerienne091501270208.png" width="100%" />
<p class="txt-hub-image">
Hub de</br>Nantes
</p>
</a>
</div>
Here is a demo fiddle as the snippets feature seems to be down.
Change your .txt-hub-image class, top value from 50% to 25%.
I have 5 divs aligned with float left and inline-block. I want move out one div of they and centered in the middle of the page.
I try to reset the float and set the position absolute, but the div doesn't centered (still in the right at page).
If reset the position (relative) the div is centered correctly, but the others divs move to the bottom of the page (i don't understand why).
* {
margin: 0;
padding: 0;
}
body {
background-color: #00ced1;
}
/* Box */
.box {
background-color: #ff0000;
border: .250rem solid #fff;
color: white;
cursor: pointer;
display: block;
float: left;
font-family: segoe ui;
margin: 1.5% 1%;
padding: 1rem;
text-align: center;
transition: position .35s ease-in,
margin .35s ease-in,
width .35s ease-in,
transform .35s ease-in;
}
.box:hover {
background-color: #20b2aa;
}
.box:nth-child(1) {
display: block;
float: none;
position: relative;
width: calc(100/4- 2*1rem - 2*1% - 2*.250rem);
margin: 200px auto;
}
/* Width of the boxes */
.width {
width: calc(100%/4 - 2*1rem - 2*1% - 2*.250rem);
}
Here is the example at jsFiddle: http://jsfiddle.net/035j1s90/1/
Thanks.
If I am not wrong, you want to center one <div> in the middle and place the other four <div>'s directly underneath it. The large gap between the centered div and the four div's is because of the margin: 200px auto property which you've specified inside the CSS for .box:nth-child(1). Simply change it to margin: 0px auto 0px auto and your layout will be fine then, like this:
* {
margin: 0;
padding: 0;
}
body {
background-color: #00ced1;
}
/* Box */
.box {
background-color: #ff0000;
border: .250rem solid #fff;
color: white;
cursor: pointer;
display: block;
float: left;
font-family: segoe ui;
margin: 1.5% 1%;
padding: 1rem;
text-align: center;
transition: position .35s ease-in,
margin .35s ease-in,
width .35s ease-in,
transform .35s ease-in;
}
.box:hover {
background-color: #20b2aa;
}
.box:nth-child(1) {
display: block;
float: none;
position: relative;
width: calc(100/4- 2*1rem - 2*1% - 2*.250rem);
margin: 0px auto 0px auto;
}
/* Width of the boxes */
.width {
width: calc(100%/4 - 2*1rem - 2*1% - 2*.250rem);
}
<div class="box width">Translate</div>
<div class="box width">Rotate</div>
<div class="box width">Scale</div>
<div class="box width">Skew</div>
<div class="box width">Matrix</div>
UPDATED:
I've modified your HTML structure just a little bit. <div class="box width">Translate</div> which you want to be centered has been moved in the end of your HTML and I've put it inside <div id="centered"><div>.
* {
margin: 0;
padding: 0;
}
body {
background-color: #00ced1;
}
/* Box */
.box {
background-color: #ff0000;
border: .250rem solid #fff;
color: white;
cursor: pointer;
display: block;
float: left;
font-family: segoe ui;
margin: 1.5% 1%;
padding: 1rem;
text-align: center;
transition: position .35s ease-in, margin .35s ease-in, width .35s ease-in, transform .35s ease-in;
}
.box:hover {
background-color: #20b2aa;
}
#centered {
text-align: center;
}
#centered .box {
display: inline-block;
float: none;
}
/* Width of the boxes */
.width {
width: calc(100%/4 - 2*1rem - 2*1% - 2*.250rem);
}
<div class="box width">Rotate</div>
<div class="box width">Scale</div>
<div class="box width">Skew</div>
<div class="box width">Matrix</div>
<div id="centered">
<div class="box width">Translate</div>
</div>
I've built these circles that expand a border when there is a mouseover. The only problem I'm getting now is some times the circle will jitter/shake. And it becomes more apparent when I set the transition: all .1s ease-in-out; to more than .2s.
Is there a work around to this problem or is that just the way it is?
Here's the code in JsFiddle
Thanks for any and all help!
EDIT: I am transitioning the dimensions (width and height) of the circles to maintain centering. I realize this is causing the jittering during the transition. Is there a work around?
I got rid of the percent values for top/left positioning, cleaned up the margins and aligned the border-width of the outer circle:
Here is a DEMO
.box {
position: relative;
width: 220px;
height: 220px;
float: left;
margin-right: 50px;
}
.clearcircle {
position: absolute;
top:15px;
left:15px;
width: 190px;
height:190px;
border-radius: 100%;
background-color: transparent;
border: 5px solid #c0392b;
transition: all .2s ease-in-out;
}
.clearcircle:hover {
width:220px;
height: 220px;
top: 0px;
left: 0px;
border: 5px solid #c0392b;
}
.circle {
position: absolute;
top:50%;
margin-top: -100px;
left: 50%;
margin-left:-100px;
width: 200px;
height:200px;
border-radius: 100%;
background-color: #e74c3c;
overflow: hidden;
transition: all .2s ease-in-out;
}
.circle p {
position:relative;
text-align: center;
top: 50%;
margin-top: -55px;
color: white;
transition: all .3s;
}
.circle:hover{
background-color: #e97468;
}
Don't transition the width and the height. Keep the same width and height and just transition the border of your outer circle.
For your inner circle (.circle), set a white border 12px solid #ffffff. Now it is always in the same place relative to the outer circle, and now it will not have to change size. Also the title can not jump around because it is always in the same position.
For the outer circle, when it is not hovered, make sure it has the same size and border as when it is, but make the border white, 5px solid #ffffff.
I think you can then also do away with a lot of your extra positioning.
Here is a modified jsFiddle so you can take a look, and here is the CSS modified:
.box {
position: relative;
width: 220px;
height: 220px;
float: left;
margin-right: 50px;
text-align: center;
}
.clearcircle {
width: 225px;
height:225px;
border-radius: 100%;
background-color: transparent;
border: 5px solid #ffffff;
transition: all .2s ease-in-out;
}
.clearcircle:hover {
border: 5px solid #c0392b;
}
.circle {
width: 200px;
height:200px;
border: 12px solid #ffffff;
border-radius: 100%;
background-color: #e74c3c;
overflow: hidden;
transition: all .2s ease-in-out;
}
.circle p {
position:relative;
text-align: center;
color: white;
transition: all .3s;
}
.circle:hover{
background-color: #e97468;
}
Incidentally, putting a div or a p in your a tag breaks the tag for validated XHTML. You may want to use a div instead, with an "on click" action added that causes it to behave as a link.
Debounce jitter by margin: 0 -12%; if adding padding padding: 0 12%;
menu li a:hover {
margin: 0 -12%;
padding: 0 12%;
color: #fff;
background: #ff5a5f;
display: inline-block;
}