Hello,
I'm playing around with Bourbon Neat, and I am trying to do three columns which cover the 100% of the windows width outside the configured grid ($max-width: em(1160)), and without any gutter. Similar to the following image (blue, yellow and green boxes).
So, to make the full width of the section, I don't specify any 'outer-container' and for remove the gutter I add the mixin 'omega' but looks like this:
I quick fix I thought myself is adding width: calc(100% / 3) to the three articles but I think is not the best solution...
Any idea?
Here I'm leaving the code: codepen.io
Thank you!
I do think your width: calc(100% / 3); was just about the right solution. I came across this exact situation in my work today. #mike-harrison's solution is what I tried first, but as I mentioned there, the span-columns mixin makes the :last-child smaller than the others. Issues in Github about that were answered that it was very intentional and your use case is better served with simple percentages.
So here's my solution: http://codepen.io/alexbea/pen/BzozXw;
The key rules are:
section.HomeProducts
+row
article
float: left
// width: percentage(1 / 3)
width: calc(100% / 3)
I used your solution with calc(), which works, though I also included a commented out approach of width: percentage(1 / 3). Most modern browsers do support calc(), but the other would serve older browsers a bit better, I think. The float should take care of any browser variations and is also what Neat uses in the span-columns mixin.
I also included the row() mixin on the parent to clearfix the whole section and make sure the floating doesn't make them disappear.
The way I would do it would be to have a 100% outer-container, and then use block-collapse on the elements inside. I have done a quick pen here:
http://codepen.io/mikehdesign/pen/ZObEdw
HTML is the same as yours, this is my SCSS:
section.HomeProducts {
#include outer-container(100%);
article {
#include span-columns(4, block-collapse);
height: 200px;
background: green;
&:first-child {
background: blue;
}
&:nth-child(2) {
background: yellow;
}
&:nth-child(3){
background: green;
}
}
}
Related
I wanted to implement a typewriter effect in CSS and I found this great article in CSS Tricks
I was tinkering around with it and wanted to see if I can implement what would be on a hero image, shown here in Codepen
However, you can see that the blinking goes all the way to the end.
Is there way to fix, or this unavoidable, since the display it's set to table-cell?
You can try that. Remove fixed width from intro container and give this into description. And for centering you can add margin: 0 auto into intro.
#intro{
display: table;
height: 100vh;
margin: 0 auto;
.intro-description{
display: table-cell;
vertical-align: middle;
text-align: center;
width: 100vw;
}
}
Codepen: http://codepen.io/anon/pen/WGydqj
The closest I got was by changing your typing keyframe.
#keyframes typing {
from { width: 0 }
51%{border-right:transparent;}
100%{border-right:transparent;}
to { width: 100% }
}
You can hide the cursor from going all the way off but I'm not sure it looks quite right because it takes awhile for the bink/cursor to reappear at the end of the sentence. There are also some responsive issues with this because smaller screen sizes the blinking will disappear too early, the opposite problem... If this solution works for you but you still need it resposive, then you'll need make multiple keyframes and apply them through mq...
That being said, this is really cool. I didn't know you could do a pure css typing effect. I thought the only way to do this was with heavy DOM manipulation like they use in typeWriter.js which may still be a viable solution for you as well if the pure css trick doesn't work out.
I am trying to have 8 images floated by each other with
width: 25%;
float: left;
Here is a fiddle:
https://jsfiddle.net/y06z0em1/
If you resize the section that the images are in, you will see that there are times when it breaks because some of the images are off by a fraction of a pixel. Could I ever change make it so that every pixel always rounds up or down?
Thanks!
Browsers round fractional pixels automatically and this is browser specific, some round it up, some down; There is no way to force it to do one or the other with CSS.
A solution could be to work with LESS, there are functions for that (ceil, floor).
But if you need a solution with CSS I would just suggest define the width as calc(100% - 0.5px) / calc(100% -1px) or 99.9%. That's just not perfect, but a solution. You can adjust it as you like and as it works for you.
But I'm not sure your problem comes from that.
Take a look at the following fiddle and tell me if it solves your problem. Instead of floating I use a layout based on display:inline-block here, and it seems like there is not such a problem.
https://jsfiddle.net/a693yj52/
I'd recommend using Flexbox here.
It'd look something like this:
.container {
display: flex;
flex-wrap: wrap;
}
.container > * {
flex-basis: 25%;
height: auto;
}
I've come across an issue today where trying to use CSS transitions to change an object's dimensions with calc() aren't working in IE. Or, rather, they're working in the sense that the calculated values are being applied but the transition rules are being ignored.
See an example here: http://jsfiddle.net/32Qr7/
.block {
width: 350px; height: 100px;
background-color: red;
margin: 10px; padding-left: 10px;
transition: all 1s ease-in-out;
}
.block:hover {
width: calc(100% - 50px);
height: calc(150px + 10%);
}
In this example, a div exists which changes its' width, height, and background-color over the course of one second on hover. In IE the background color still animates smoothly, but the width and height change is instantaneous.
This is pretty big issue for me as I have a responsive web app with drawers that slide out from the side, and the rest of the layout has to adjust to compensate. Since I'm dealing with a multitude of screen sizes I can't use hard-coded values.
(And yes, I looked at IE 10 + 11: CSS transitions with calc() do not work hoping for a solution there, but that question doesn't involve dimension changes, and as such the accepted solution there doesn't work for me.)
Does anyone know of a workaround for this issue, or have any other alternate strategies to suggest? I'm hoping to be able to do it in CSS and avoid having to fall back to using jQuery animation techniques or somesuch.
Seems like I have found a workaround after playing a bit (at least it works for IE10 and IE11). I have used the max-width property instead for calc() method. CSS for hover:
.notworks:hover {
width: 100%;
max-width: calc(100% - 50px);
height: 175px;
}
Example
I have an interesting problem that came up more than once. I'll present the last one and uploaded both of them to my server.
I'm taking a tuts+ course about responsive webdesign and as the guy has set 20% for creating 5 grids + 2x5px padding between them, it didn't work to me unless I changed the 20 to 19%.
This is my code:
/* WIDTH SETTING */
.nav-hold,
.image-grid,
.container {
width:95%;
max-width:1000px;
margin:0 auto;
}
/* IMAGE GRID */
.image-grid,
.form-container {
overflow: hidden; /* because inside the grid, we'll flow elements */
padding: 5px;
}
.image-grid-square {
float: left;
width: 19%; /* each img container's width (5*)19% */
overflow: hidden; /* because inside the grid, we'll flow elements */
padding: 5px;
}
.image-grid-square img {
width: 100%; /* the img inside the container can be 100% big */
float: left;
}
The only change in his code is the width:20%; (at least what I noticed)
If you guys want to inspect the code deeper, here is my version: http://purpost.me and here is his version: http://purpost.me/tuts
Why his 20% for 5 grids or 25% for 4 grids works perfectly and mine doesn't? :) I'm learning CSS and have a short amount of time to get to know the most of it to use it in a big project. I want to understand the behavior of layouts to be able to build an any type of site. I know frameworks such as Bootstrap, but the command is to use our own codes, so I'm learning as fast as I can. :)
In the course the 300x300 pictures became 188x188, but when I tried it with 20%, mine was 200x200 .. now with 19% its 190x190. I don't understand.
I understand most of the key factors of responsive web-design unless this grid question. I assume I should read a lot about it and try and try and try and in the end I'll be comfortable using it.
I appreciate any help, thanks in advance!
Other guy is having reset.css file where he has some css definitions which you are not using. That is why your UI behaves different.
I just came across something
#element {
left: 50%;
margin-left: -(elemntwidth/2)px;
}
being (elemntwidth/2) already a number like 30px, for ex.
I would like to know if this is a safe way of crossbrowsing the responsive elements positioning so I can abandon the way Im doing right now with .jQuery
$('#element').css(left: (screenwidth - element / 2) + 'px');
More than everything Im interested in a cross mobile device browsers efective solution and this css only I found it clean and simple, so simple that I need to ask if this could be true. Thanks
CSS Frameworks have this functionaility baked in.
Checkout: Foundation 3
Otherwise, you will need to rely heavily on Javascript and Media Queries to achieve pixel perfection.
Not to mention this is the first of many problems you will encounter to acheive cross devices / browser stable elements. All of these things have been carefully thought out for you alreacdy.
This is a way. For some elements it works, resposive, centered and no jQuery.
HTML
<div class="element ver1">TESTE</div>
<div class="element ver2">TESTE</div>
<div class="element ver3">TESTE</div>
<div class="element ver4">TESTE</div>
CSS
.element {
position: relative;
width: 90%;
background: black;
margin: 0 auto 10px;
text-align: center;
color: white;
padding: 20px 0;
}
.ver1{width: 80%;}
.ver2{width: 70%;}
.ver3{width: 60%;}
.ver4{width: 40%;}
Wroking Demo | Final result full screen
AFAIK this solution is browser compatible. it's even better than {margin-left:auto; margin-right:auto;} in some cases. but there is an other interesting point by centering DOM-elements this way:
e.g. if your whole page-wrapper is centered with {left:50%,...} and the browser window width is smaller than the wrapper you cannot see the whole content by scrolling to left and right. the browser cuts the content. try it...
Try to scroll left and right to see the white left- and right-border...
The other known solution is to set {margin-left:auto; margin-right:auto;} but afaik this just works together with {position:relative;}- not with {position:absolute;}-elements
It's been a long time when I started up with this unconventionally solution...
use this code snippet:
.centered {
position: fixed;
top: 50%;
left: 50%;
margin-top: -(height/2);
margin-left: -(width/2);
}
this works even if the parent dimensions change.
The code you have will work - I've used the same approach many times - so long as you know the dimensions of the element you are centering.
Note that you can use the same approach using percentage based widths to work better with responsive layouts.
You're on the right track.