I am an amateur and beginner trying to make my first web page with a fluid image grid for vertical and horizontal photos with same height. So I am applying the Packery javascript to make it more responsive.
See link to Codepen: http://codepen.io/nor159/pen/WbpWpe/?editors=110
* {
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
border: 0px 0px 0px 0px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body {
background: #f0f0f0;
}
img {
width: 100%;
display: block;
}
.packery {
margin: 8% 8% 8% 8%;
}
.packery:after {
content: ' ';
display: block;
clear: both;
}
.item {
float: left;
}
#media screen and (max-width:400px) {
.item.v, .grid-sizer {
width: calc(4/14*100%);
}
.item.h {
width: calc(9/14*100%);
}
.gutter-sizer {
width: calc(1/14*100%);
}
I find 2 problems:
1) Open gaps between the images appear randomly as I resize the screen.
2) Loading in Chrome gives overlapping images.
Does anyone know how to resolve this? Can this grid be made using Packery?
Response to my questions will be highly appreciated.
Regards
Jan, Oslo
Not sure if this will help 100% but Using imagesLoaded(), has fixed some of my problems with masonry before. you can find more information # http://packery.metafizzy.co/appendix.html
$(document).ready(function(){
// element
imagesLoaded( document.querySelector('#container'), function( instance ) {
console.log('all images are loaded');
});
// selector string
imagesLoaded( '#container', function() {
var $container = $('#container').packery({
gutter: 10,isHorizontal:false,stamp: '.stamp',itemSelector: '.item',columnWidth: '.grid-sizer'});
});
});
// multiple elements
another trick is to put the image larger than its supposed to be in the grid. The woman married to the Guy that Sings that 99 problems song => her site did this:
container img{width:105%}
Related
Basically this is one question but might need a multi part answer to remove the excess spacing. Basically the problem occurs when setting the featured image on a post on the default twentysixteen theme. I have a live test environment setup to show this here: http://192.241.239.174/index.php/2016/11/02/hello-world/
Here is a shot of how it currently is vs what I'm expecting it to look like: http://prntscr.com/d204p5
Thank you for any help
Edit: Further researching similar questions I have gotten slightly closer by using some custom css to change the thumbnail/featured image max width to 150 which should be fine as all my featured images are going to be 150x150 anyways. This code was added into custom css:
.post-thumbnail img {
float: left;
margin: 5px 15px 10px 0;
max-width: 150px;
}
Now the text does appear slightly higher but still fails to wrap the thumbnail and is still not close enough to the thumbnail. I'd like to have the text closer to the thumbnail
EDIT: Complete solution
The complete solution I used was adding this code into my custom css:
.entry-footer {
display: none;
}
.post-thumbnail img {
float: left;
margin: 0px 20px 0px 0;
max-width: 150px;
}
body:not(.search-results) article:not(.type-page) .entry-content {
float: none !important;
width: 100%;
}
.entry-content > :last-child {
margin-bottom: 0;
text-align: center;
width:100%;
}
i don't think that's the better choice to make in fact i would have setup a child theme and worked on it, by the way:
.entry-footer {
display: none;
}
.post-thumbnail img {
float: left;
margin: 0px 20px 0px 0;
max-width: 150px;
}
body:not(.search-results) article:not(.type-page) .entry-content {
float: none !important;
width: 100% !important;
}
.entry-content > :last-child {
margin-bottom: 0;
text-align: center;
}
You may need to add !important keyword if something doesn't work.
The result: Is that like what you wanted?
I am trying to create a Reddit page using CSS. My problem is scaling. I want to make an object, .side, smaller in length. On my 1080p monitor, it looks great, but when I zoom in or out it will not scale with the browser. It is also too large on mobile.
Here is the code:
#header {
background: url(%%rtv6a%%);
background-repeat: no-repeat;
background-position: -3px 24px;
height: 130px;
}
#header-bottom-left
{
position: absolute;
bottom: 0;
}
div.side div.spacer:nth-of-type(5)
{
background:url(%%tangoglobe4%%) top center no-repeat;
padding: 250px 0 0;
margin-top: 20px;
}
div.side div.spacer:nth-of-type(5):hover
{
background:url(%%goglobal4%%) top center no-repeat;
padding: 250px 0 0;
margin-top: 20px;
transition: .6s;
}
body, .side, .titlebox form.toggle, .leavemoderator, .icon-menu a, .side .spacer
{
background:url(%%whiteticks%%);
}
.sitetable
{
background:url(%%ticks%%);
}
.morelink .nub
{
display: none;
}
.sitetable
{
max-width: 83%;
border-color: #5C5C5C;
border-style:solid;
border-width:1px;
}
Here is what I want it to look like: http://i.imgur.com/CM1Ejgp.jpg
When I scale it: http://i.imgur.com/HGsnSvD.png
You will notice the grey box get farther and father away. What can I do to fix this?
Sorry, I am new to coding.
You might want to look into media queries:
Media queries look at the capability of the device, and can be used to
check many things, such as:
width and height of the browser window
width and height of the device
orientation (is the tablet/phone in landscape or portrait mode?)
resolution
and much more
You can use media queries to set sizes and widths of text or containers in CSS depending on the size of the browser. Eg:
#media (max-width: 600px) {
.facet_sidebar {
display: none;
}
}
https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries
I haven't been able to find any info on the web to help me out here. Using Magnific Popup I'd like my popup images to display with a single black border. Ive gone into the Magnific-popup.css file and added the following:
/* Main image in popup */
img.mfp-img {
width: auto;
max-width: 100%;
height: auto;
display: block;
line-height: 0;
/*my attempt at adding a border around the image */
**border: 2px solid red;**
/* end attempt */
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding: 40px 0 40px;
margin: 0 auto; }
What I'm getting is a red border in the display area, adding a black greyish border around the image.
Has anyone done this before? Thanks in advance.
The issue is caused by the padding that has been set to the image, try replacing the padding with margin like this:
img.mfp-img {
padding: 0;
margin: 40px auto;
/*Add your border*/
border: 2px solid red;
}
Also I must note that modifying core files for any plugin is considered bad practice because it makes upgrading to a newer version more difficult, I suggest you create a separate CSS file to override or add any custom styles.
The best way I have found to do this is to remove the padding from the image and apply it to a before and after pseudo class on the figure like so
img.mfp-img {
padding: 0;
border: 2px solid red;
}
.mfp-figure figure::before {
padding-top: 40px;
display: block;
content: "";
}
.mfp-figure figure::after {
padding-bottom: 40px;
display: block;
content: "";
}
I'm trying to switch from a CSS grid framework to a flex layout (because of different items height, and flexbox handles that very nicely).
So, this is what I did: http://jsfiddle.net/c3FL2/
.container {
display: flex;
flex-wrap: wrap;
padding: 15px;
background: #9999FF;
}
.g {
background: #FF9999;
border: 1px solid red;
border-radius: 8px;
padding: 15px;
}
.grid-33 {
width: 33.3333%;
}
.grid-50 {
width: 50%;
}
.grid-66 {
width: 66.6666%;
}
.grid-100 {
width: 100%;
}
My question is: how can i add a margin between flex items? I want exactly 15px, not a percentage. If I add that, it breaks the layout because of too much width. Padding is not a solution because I want a border outside elements.
The solution doesn't have to be compatible with old browser, just the latest ones since this will be running on a controlled environment.
Edit: If needed, the HTML can be changed.
The "easiest" way to do this is to use calc(). (It would of course be easier if you didn't have to solve for IE quirks to get there, but the end result is very straightforward.) Your code would look like this:
.container {
padding: 15px 15px 0 0;
}
.g {
margin: 0 0 15px 15px;
}
.grid-33 {
with: calc(33.3333% - 15px);
}
.grid-50 {
width: calc(50% - 15px);
}
.grid-66 {
width: calc(66.6666% - 15px);
}
.grid-100 {
width: calc(100% - 15px); // needed for IE10
}
The reason for using width is because IE10-11 aren't great fans of calc being used together with flex. In this case it's a box-sizing: border-box issue. This example is cross-browser compatible with IE10+.
Demo
(To see vendor prefixes, click "View Compiled" in CSS.)
You might try : background-clip and box-shadow and transparent borders: DEMO
.g {
background: #FF9999;
border: 8px solid transparent;/* you may tune individually border-size to get your 15px */
box-shadow:inset 0 0 0 1px red;/* this will fake your border if set with out blur */
background-clip:padding-box;/* do not show bgcolor under borders */
border-radius: 15px;/* increase value so it has effect deeper seen on inset box-shadow */
padding: 15px;
}
Only tested this in chrome but seems to work
try changing the styles to this:
.g {
//add margin style
margin:15px;
}
.grid-33 {
flex: 1 1 33.3333%;
}
.grid-50 {
flex: 1 1 50%;
}
.grid-66 {
flex: 1 1 66.6666%;
}
.grid-100 {
flex: 1 1 100%;
}
Even though this is old, I had a similar problem. I achieved the margins by adding an extra element and moving the styling to that element. This seems quite robust, calc() no matter how well supported doesn't feel neat enough.
.padder {
background: #FF9999;
border: 1px solid red;
border-radius: 8px;
margin: 0 15px 15px 0;
display:flex;
}
Placing display:flex on the extra element ensures its contents fill the space within.
http://jsfiddle.net/c3FL2/28/
I am trying to dynamicly change the width of a div using CSS and no jquery. The following code will work in the following browsers: http://caniuse.com/calc
/* Firefox */
width: -moz-calc(100% - 500px);
/* WebKit */
width: -webkit-calc(100% - 500px);
/* Opera */
width: -o-calc(100% - 500px);
/* Standard */
width: calc(100% - 500px);
I want also support IE 5.5 and higher, i found the following: expression. Is this the correct usage:
/* IE-OLD */
width: expression(100% - 500px);
Can I also support Opera and the Android browser?
Almost always box-sizing: border-box can replace a calc rule such as calc(100% - 500px) used for layout.
For example:
If I have the following markup:
<div class="sideBar">sideBar</div>
<div class="content">content</div>
Instead of doing this: (Assuming that the sidebar is 300px wide)
.content {
width: calc(100% - 300px);
}
Do this:
.sideBar {
position: absolute;
top:0;
left:0;
width: 300px;
}
.content {
padding-left: 300px;
width: 100%;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
* {
margin: 0;
padding: 0;
}
html,
body,
div {
height: 100%;
}
.sideBar {
position: absolute;
top: 0;
left: 0;
width: 300px;
background: orange;
}
.content {
padding-left: 300px;
width: 100%;
-moz-box-sizing: border-box;
box-sizing: border-box;
background: wheat;
}
<div class="sideBar">sideBar</div>
<div class="content">content</div>
PS: I won't work in IE 5.5 (hahahaha) , but it will work in IE8+ , all mobile, and all modern browsers (caniuse)
Width Demo
Height Demo
I just found this post from Paul Irish's blog where he also shows off box-sizing as a possible alternative for simple calc() expressions: (bold is mine)
One of my favorite use-cases that border-box solves well is columns. I
might want to divide up my grid with 50% or 20% columns, but want to
add padding via px or em. Without CSS’s upcoming calc() this is
impossible… unless you use border-box.
NB: The above technique does indeed look the same as would a corresponding calc() statement. There is a difference though. When using a calc() rule the value of the width of the content div will actually be 100% - width of fixed div, however with the above technique, the actual width of the content div is the full 100% width, yet it has the appearance of 'filling up' the remaining width. (which is probably good enough for want most people need here)
That said, if it is important that the content div's width is actually 100% - fixed div width then a different technique - which makes use of block formatting contexts - may be used (see here and here for the gory details):
1) float the fixed width div
2) set overflow:hidden or overflow:auto on the content div
Demo
Just have a fallback before the calc will do the trick.
width: 98%; /* fallback for browsers without support for calc() */
width: calc(100% - 1em);
See more here https://developer.mozilla.org/en-US/docs/Web/CSS/calc
use this
.content
{
width: 100%;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding-right: 500px;
margin-right: -500px;
}
Just spent the best part of 3 hours trying to workaround this for a specific case on andriod devices, couldnt get box sizing to work so i've linked it into my JS as a dirty workaround... no jQuery required though! :)
Taken on working code on andriod 2.3.
<div class="sessionDiv" style="width:auto;">
<img> <!-- image to resize -->
</div>
<div class="sessionDiv" style="width:auto;">
<img> <!-- image to resize -->
</div>
JS with event listeners
var orient =
{
orientation:window.orientation,
width: window.innerWidth,
check: function()
{
// if orientation does not match stored value, update
if(window.orientation !== this.orientation)
{
this.orientation = window.orientation; //set new orientation
this.width = window.innerWidth; //set new width
this.adjustIrritatingCSS(this.width); //change ui to current value
}
//if width does not match stored value, update
if(window.innerWidth !== this.width)
{
this.width = window.innerWidth; //set new width
this.adjustIrritatingCSS(this.width); //change ui to current value
}
},
adjustIrritatingCSS: function(screenWidth)
{
//disgusting workaround function
var titleBoxes = document.getElementsByClassName('sessionDiv');
var i = titleBoxes.length;
var sessWidth = screenWidth - 300; // calc(100% - 300px); -> equivalent
while(i--)
{
titleBoxes[i].style.width = String( sessWidth + "px");
//resize image in auto sized div
}
sessWidth = null; //clear width
titleBoxes = null; //clear nodelist
i = null; // clear index int
}
};
window.onload = function()
{
window.addEventListener('resize', function(){orient.check();});
//on resize, check our values for updates and if theres changes run functions
window.addEventListener('orientationchange', function(){orient.check();});
//on rotate, check our values for updates and if theres changes run functions
setInterval(function(){orient.check();}, 2000);
//occasionally check our values for updates and if theres changes run functions(just incase!!)
orient.adjustIrritatingCSS(orient.width);
//sets value on first run
};
Hope this helps anyone who cant get the box-sizing working!
PS I have experienced problems with ios using this...
Change #menuLog width with % or px and you will see magic. Works with every device even < 2.3
*{
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
#menuLog{
width:30%;
/*width:300px;*/
height: 60px;
padding: 5px;
background-color: #ddd;
}
#menuLog > div[inline-log="1"]{
display: inline-block;
vertical-align: top;
width: 100%;
height: 100%;
margin-right: -60px;
}
#menuLog > div[inline-log="1"] > div[inline-log="1.1"]{
margin-right: 60px;
height: 100%;
background-color: red;
}
#menuLog > div[inline-log="2"]{
display: inline-block;
vertical-align: top;
width: 60px;
height: 100%;
}
#menuLog > div[inline-log="2"] > div[inline-log="2.1"]{
display: inline-block;
vertical-align: top;
width: 55px;
height: 100%;
background-color: yellow;
margin-left:5px;
}
<div id="menuLog">
<div inline-log="1">
<div inline-log="1.1">
One
</div>
</div><div inline-log="2">
<div inline-log="2.1">
Two
</div>
</div>
</div>
I wanted to add the no-calc, no-border-box (i.e., CSS2) alternative.
Normal-flow block elements initially have width: auto, which is effectively the width of the containing block minus the margin, border, and padding widths.
The example above can be done, without border-box, simply as
.content {
padding-left: 300px;
}
Similarly, with
.content {
margin-left: 1px;
border-left: 1em solid;
padding-left: 1rem;
}
the effective width is 100% - 1px - 1em - 1rem.
For absolutely positioned elements, height: auto has similar properties:
.content {
position: absolute;
top: 0;
bottom: 0;
margin-bottom: 1px;
border-bottom: 1em solid;
padding-bottom: 1rem;
}
Here the effective height is 100% - 1px - 1em - 1rem.