CSS for image layout issues - css

I'm learning responsive CSS, so this is all fairly new to me. However, why aren't the images on the 2nd row hugging the top images?
Ideally I just want 4 images per row, but if on a smaller screen or phone etc. it will dynamically reduce the image size and reduce the number of images per row. Cannot seem to get this working? Any help is appreciated! All CSS relative for the images is on that one static page.
div.gallery {
border: 1px solid #ccc;
}
div.gallery:hover {
border: 1px solid #777;
}
div.gallery img {
width: 100%;
height: auto;
}
div.desc {
padding: 10px;
text-align: center;
}
* {
box-sizing: border-box;
}
.responsive {
padding: 0 6px;
float: right;
width: 24.99999%;
}
#media only screen and (max-width: 700px) {
.responsive {
width: 49.99999%;
margin: 6px 0;
}
}
#media only screen and (max-width: 500px) {
.responsive {
width: 100%;
}
}
.clearfix:after {
content: "";
display: table;
clear: both;
}
<div class="responsive">
<div class="gallery">
<a target="_blank" href="https://memorybox.pt">
<img src="images/memory-box.png" alt="Algarve Wedding Photography" width="600" height="400">
</a>
<div class="desc">Algarve Wedding Planners</div>
</div>
</div>
<div class="responsive">
<div class="gallery">
<a target="_blank" href="https://algarvedjhire.com/">
<img src="images/algarve_dj_hire.jpg" alt="Algarve Wedding Photography" width="600" height="400">
</a>
<div class="desc">Algarve DJ & Music</div>
</div>

Use height and instead of float right use float left in your .responsive class. See example below. I use height 290px you can use based on your need.
.responsive {
padding: 0 6px;
float: left;
width: 24.99999%;
height: 290px;
}
Also you can use margin-bottom in your responsive break point so that it's look good. See example below.
#media only screen and (max-width: 700px) {
.responsive {
width: 49.99999%;
margin: 6px 0 30px 0;
}
}

Related

How to modify responsive timeline?

http://codepen.io/kjohnson/pen/azBvaE
My friend and I are thinking of using that timeline in our website. But the problem is we've 5 sections that needs to be added to timeline, whereas the original timeline have only 3 sections.
I've tried to add two more sections to that code, but it's losing its shape and responsiveness.
Is it possible to extend that timeline and maintain its responsiveness?
HTML
<!-- STEPS -->
<section id="Steps" class="steps-section">
<h2 class="steps-header">
Responsive Semantic Timeline
</h2>
<div class="steps-timeline">
<div class="steps-one">
<img class="steps-img" src="http://placehold.it/50/3498DB/FFFFFF" alt="" />
<h3 class="steps-name">
Semantic
</h3>
<p class="steps-description">
The timeline is created using negative margins and a top border.
</p>
</div>
<div class="steps-two">
<img class="steps-img" src="http://placehold.it/50/3498DB/FFFFFF" alt="" />
<h3 class="steps-name">
Relative
</h3>
<p class="steps-description">
All elements are positioned realtive to the parent. No absolute positioning.
</p>
</div>
<div class="steps-three">
<img class="steps-img" src="http://placehold.it/50/3498DB/FFFFFF" alt="" />
<h3 class="steps-name">
Contained
</h3>
<p class="steps-description">
The timeline does not extend past the first and last elements.
</p>
</div>
</div><!-- /.steps-timeline -->
CSS
$outline-width: 0;
$break-point: 500px;
#import url(http://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic);
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
body {
font-family: lato;
}
$gray-base: #999999;
$brand-primary: #3498DB; //Zen Blue
.section-header {
color: $brand-primary;
font-weight: 400;
font-size: 1.4em;
}
.steps-header {
#extend .section-header;
margin-bottom: 20px;
text-align: center;
}
.steps-timeline {
outline: 1px dashed rgba(red, $outline-width);
#media screen and (max-width: $break-point) {
border-left: 2px solid $brand-primary;
margin-left: 25px;
}
#media screen and (min-width: $break-point) {
border-top: 2px solid $brand-primary;
padding-top: 20px;
margin-top: 40px;
margin-left: 16.65%;
margin-right: 16.65%;
}
&:after {
content: "";
display: table;
clear: both;
}
}
.steps-one,
.steps-two,
.steps-three {
outline: 1px dashed rgba(green, $outline-width);
#media screen and (max-width: $break-point) {
margin-left: -25px;
}
#media screen and (min-width: $break-point) {
float: left;
width: 33%;
margin-top: -50px;
}
}
.steps-one,
.steps-two {
#media screen and (max-width: $break-point) {
padding-bottom: 40px;
}
}
.steps-one {
#media screen and (min-width: $break-point) {
margin-left: -16.65%;
margin-right: 16.65%;
}
}
.steps-two {
}
.steps-three {
#media screen and (max-width: $break-point) {
margin-bottom: -100%;
}
#media screen and (min-width: $break-point) {
margin-left: 16.65%;
margin-right: -16.65%;
}
}
.steps-img {
display: block;
margin: auto;
width: 50px;
height: 50px;
border-radius: 50%;
#media screen and (max-width: $break-point) {
float: left;
margin-right: 20px;
}
}
.steps-name,
.steps-description {
margin: 0;
}
.steps-name {
#extend .section-header;
#media screen and (min-width: $break-point) {
text-align: center;
}
}
.steps-description {
overflow: hidden;
#media screen and (min-width: $break-point) {
text-align: center;
}
}
If you a novice I'd recommend you LEARN first. Copy templates/snippets is good to save your time when you know what you are doing.
I found a perfect tutorial for you here
Just to emphasize that's my opinion, I hope it helps in a certain way..
EDIT: If still want to develop in that way here's a codepen snippet with a fully responsive horizontal timeline. Just have to put more <li> inside the <ul>

How can I center an image between two other images in this example?

I have a div 'imgcontainer' and a div 'commentcontainer'. Representing a large image and a white box filled with comments below. I want to add a third image that sits on top of the two, vertically centered.
So basically what I'm trying to do is this: https://d13yacurqjgara.cloudfront.net/users/488816/screenshots/1726057/1_1x.jpg
My problem is that I can't figure out how to integrate the CSS to do this into my code below. What can I add to the 'profilepic' div in order to set that image to sit midway between the imgcontainer and commentcontainer ?
HTML
<div id="timeline">
<div class="block2x3 block">
<div class="imgcontainer">
<img src="top-picture.jpg" />
<div class="profilepic">
<img src="facepic.png" />
</div>
</div>
<div class="commentcontainer">
<div class="peoples">
<strong class="people name">Joe Schmoe</strong> and 42 other people bought this
<p>Have commented on your wall post</p>
</div>
</div>
</div>
CSS3
#media (max-width:1860px) {
#timeline .block .imgcontainer img {width:100%;}
#timeline div[class*="block"][class*="x1"] {height:150px;}
#timeline div[class*="block"][class*="x2"] {height:300px;}
#timeline div[class*="block"][class*="x3"] {height:450px;}
#timeline div[class*="block2x3"] .imgcontainer {height:60%; position:relative; z-index:1;}
#timeline div[class*="block2x3"] .commentcontainer {height:40%; z-index:2;}
.profilepic {
margin: 40px 0px 0px 0px;
border: 7px solid white;
border-radius: 70px;
}
On your CSS to center the 'profile' pic you can add this to you CSS:
.profilepic {
/*margin: 40px 0px 0px 0px; INSTED OF THIS */
margin-left: auto; /* USE */
margin-right: auto; /* THIS */
border: 7px solid white;
border-radius: 70px;
}
but first you will have to add this to you css file:
html { width: 100%; height: 100%; margin: 0; padding: 0; }
body { width: 100%; height: 100%; margin: 0; padding: 0; }
Hope it works :')

Stuck with responsive and timeline design with masonry

I am very new to tumblr and jQuery Masonry, I have create a test blog.
I have a timeline design, by which posts are aligned in two sides and also I used Masonry to remove the space between the posts.
And I have added responsive behavior to this.
Post and Masonry is working properly with responsive on different window size when the page loads but when i resize the window, its design goes to haywire.
I am not able to identify is it my code's mistake or Masonry's :(
Any help will be really helpful.
It is not working with only (min-width: 768px), (min-width: 1024px) and (min-width: 1824px)
Here is my code:
JS
$(document).ready(function() {
if ($(window).width() <= 679) {
$('#posts_container').masonry('destroy');
}
if ($(window).width() > 680) {
$('#posts_container').masonry({itemSelector: '.shadow', });
}
Arrow_Points();
});
function Arrow_Points() {
//alert("function call");
var s = $('#posts_container').find('.shadow');
$.each(s, function(i, obj) {
var posLeft = $(obj).css("left");
$(obj).addClass('borderclass');
if (posLeft == "0px") {
html = "<span class='rightCorner'></span>";
html += "<div class='rightpostcorner'></div>";
$(obj).prepend(html);
$(this).addClass('margin_hack_left_post');
}
else
{
html = "<span class='leftCorner'></span>";
html += "<div class='leftpostcorner'></div>";
$(obj).prepend(html);
$(this).addClass('margin_hack_right_post');
}
});
}
Media
#media only screen and (max-width: 480px) {
.wrapper {width: 100%;}
.rightCorner, .leftCorner{ display: none; }
.shadow {width: 90%; margin: 40px 5% 10px 5%; }
}
#media only screen and (max-width: 680px) and (min-width: 480px){
.wrapper {width: 100%;}
.rightCorner, .leftCorner{ display: none; }
}
#media only screen and (max-width: 768px) and (min-width: 680px){
.wrapper {width: 100%;}
.rightCorner, .leftCorner{ display: none; }
.shadow {width: 90%; margin: 40px 5% 10px 5%; }
}
#media only screen and (min-width: 768px) and (max-width: 1024px) {
.leftCorner { margin-left:-9%;}
.shadow { width: 45.5%; margin-top: 40px; }
.margin_hack_left_post { margin-left:1.5%%; }
.margin_hack_right_post { margin-left:7.5%; }
}
#media only screen and (min-width: 1025px) and (max-width: 1824px) {
.wrapper {width: 100%; }
.leftCorner {margin-left: -5.5%; }
.shadow { width: 43.7%; margin-top: 40px; }
.margin_hack_left_post { margin-left:4%; }
.margin_hack_right_post { margin-left:8%; }
}
/* LARGE SCREENS */
#media only screen and (min-width: 1824px) {
.wrapper {width: 1200px; margin: 0 auto;}
.shadow { width: 43.7%; margin-top: 40px; }
.margin_hack_left_post { margin-left:4%; }
.margin_hack_right_post { margin-left:8%; }
}
My CSS:
.shadow
{
float: left;
background-color: #ffffff;
min-height: 50px;
text-align: justify;
word-wrap:break-word;
}
.timeline_container
{
width: 16px;
text-align: center;
margin: 0 auto;
cursor:pointer;
display: block;
}
.timeline
{
margin: 0 auto;
background-color: red;
display: block;
float: left;
height: 100%;
left: 49.75%;
position: absolute;
width: 1px;
z-index: -1;
}
.timeline:hover{cursor: pointer;margin: 0 auto;}
.timeline div.plus{width: 14px;height: 14px;position: relative;left: -6px;}
.rightCorner
{
background-image: url("xyz.png");
height: 30px;
margin-left: 99.5%;
margin-top: 8px;
padding: 0;
vertical-align: top;
width: 30px;
z-index: 2;
position: absolute;
}
.leftCorner
{
background-image: url("abc.png");
height: 30px;
width: 30px;
margin-top: 8px;
position: absolute;
z-index:2;
}
.content
{
margin-left: auto;
margin-right: auto;
max-width: none;
min-width: 86%;
position: relative;
z-index: 2;
}
And my tumblr HTML is
{block:Posts}
<article class="shadow">
{block:Date}
<div class="post_info">
<section class="post-controls">
<ul style="padding-left: 0px; float: left; width:80%">
<li style="width: 30%; margin-left: 0px; padding-left: 0px; margin-top: 7px;">
<i class="icon-clock"></i> {DayOfMonthWithZero} {ShortMonth} {ShortYear}
</li>
{block:NoteCount}<li style="width: 30%; margin-left: 0px; padding-left: 0px; margin-top: 7px;">
<i class="icon-heart"></i> {NoteCount}</li>{/block:NoteCount}
</ul>
<ul style="float:right;">
<li class="like_link">{ReblogButton size="20"}</li>
<li class="reblog_link">{LikeButton size="20"}</li>
</ul>
</section>
</div>
{/block:Date}
<div class="post_padding">
{block:Audio}
<div class="audio" id="{PostID}">
<div class="album_art">{block:AlbumArt}<img class="scale-with-grid" src="{AlbumArtURL}" />{/block:AlbumArt}</div>
<div class="audio_player_container">
{block:AudioEmbed}{AudioEmbed}{/block:AudioEmbed}
{block:AudioPlayer}{AudioPlayerWhite}{/block:AudioPlayer}
</div>
<div class="caption">
<ul class="audio_details">
{block:TrackName}<li><span class="audio_bold">Song Title:</span> {TrackName}</li>{/block:TrackName}
{block:Artist}<li><span class="audio_bold">Artist:</span> {Artist}</li>{/block:Artist}
{block:Album}<li><span class="audio_bold">Album:</span> {Album}</li>{/block:Album}
<li><span class="audio_bold">Plays:</span> {PlayCount}</li>
</ul>
{block:Caption}{caption}{/block:Caption}
</div>
</div>
{/block:Audio}
{block:Chat}
{block:Title}<div class="chat_title"><h2>{Title}</h2></div>{/block:Title}
{block:Lines}
<div class="lines"><div class="line {Alt}">{block:Label}<strong>{Label}</strong>{/block:Label} {Line}</div></div>
{/block:Lines}
{/block:Chat}
{block:Link}
<div class="link_title"><a href="{URL}" {Target}>{Name} →</a></div>
<div class="caption">{block:Description}{Description}{/block:Description}</div>
{/block:Link}
{block:Photo}
<div class="photo_post">
<a href="{Permalink}" rel="prettyPhoto">
<img class="scale-with-grid" src="{PhotoURL-HighRes}"/>
</a>
</div>
{block:Caption}<div class="caption">{Caption}</div>{/block:Caption}
{/block:Photo}
{block:Photoset}
<div class="photo-slideshow" data-layout="{PhotosetLayout}">
{block:Photos}
<div class="photo-data">
<div class="photo">
<a href="{Permalink}" rel="prettyPhoto[set]">
<img alt="{PhotoAlt}" src="{PhotoURL-500}" data-highres="{PhotoURL-HighRes}" class="{block:Exif}exif-yes {/block:Exif}{block:Caption}caption-yes{/block:Caption}" {block:Exif}data-camera="{block:Camera}{Camera}{/block:Camera}" data-iso="{block:ISO}{ISO}{/block:ISO}" data-aperture="{block:Aperture}{Aperture}{/block:Aperture}" data-exposure="{block:Exposure}{Exposure}{/block:Exposure}" data-focal="{block:FocalLength}{FocalLength}{/block:FocalLength}"{/block:Exif} {block:Caption}data-caption="{Caption}"{/block:Caption}>
</a>
</div>
<div class="icons">
<a rel="prettyPhoto" class="view" rel="post-{PostID}" href="{PhotoURL-HighRes}"><span class="zoom">Zoom</span></a>
<span class="info">Info</span>
</div>
</div>
{/block:Photos}
</div><!-- close SLIDESHOW -->
<div class="caption">{block:Caption}{Caption}{/block:Caption}</div>
{/block:Photoset}
{block:Quote}
<div class="quote_title"><h2>"{Quote}"</h2></div>
<div class="caption"><p>{block:Source}- {Source}{/block:Source}</p></div>
{/block:Quote}
{block:Text}
{block:Title}<div class="post_title"><h2>{Title}</h2></div>{/block:Title}
<div class="caption">{Body}</div>
{/block:Text}
{block:Video}
<div class="video_post">
<figure><div class="embed">{Video-500}</div></figure>
{block:Caption}<div class="caption">{Caption}</div>{/block:Caption}
</div>
{/block:Video}
</div>
</article>
{/block:Posts}
The Javascript will generate hard-pixels for the left-margin, depending on the width of browser window. Change the hard pixels to 50%.
jQuery:
$(this).css("left", "50%");

Ways to change margin by screen size

How I can set this CSS margin:
.url {
margin: 10px 0 0;
}
When screen is resized? From margin: 10px 0 0; to margin: 20px 0;
you have Several option:
1:Responsive Option:
media query consists of a media type and at least one expression that limits the style sheets' scope by using media features, such as width, height, and color. Media queries, added in deprecated CSS3, let the presentation of content be tailored to a specific range of output devices without having to change the content itself.
#media all and (max-width: 1000px) and (min-width: 700px) {
.class {
margin:50px;
}
}
2:Using Percentage:
you can use:
.class{
margin:40%;
}
resource:
https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries
http://css-tricks.com/css-media-queries/
Use media queries, for example to change the margin on screens smaller than 600px wide:
#media screen and (max-width: 600px) {
.url {
margin:20px 0;
}
}
Try this
.url {
margin: x% 0 0;
}
**replace x with your requirement
eg:
.url {
margin: 5% 0 0;
}
hope this helps.
There is a simple way to deal with margins when you resize the screen.
Just define your container width and set margin to auto:
.url {
width: 768px;
margin: auto;
}
The container width will be fixed and it will be on the center of the screen. Therefore the margins will be automatically adjusted to fit the rest of the screen.
try to use screen units vw
.url {
margin: 4vw;
}
for mobile first {tablets to mobile devices with min-width 320px}, you could try fixed position for the menu bar and make the centre button relative. display: flex
#media screen and (max-width: 767px) and (min-width: 320px){
.menu {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
position: fixed;
bottom: 0;
height: 5%;
width: 100%;
background-color: rgb(227, 248, 255);
border-top: 1px solid;
z-index: 0;
}
.btns {
width: 2rem;
height: 2rem;
background: none;
border: none;
font-size: 80%;
margin: 0 auto;
}
#mic {
position: relative;
bottom: 2em;
background-color: rgb(227, 248, 255);
border-radius: 50%;
padding: 10px;
border: 2px;
box-shadow: 0 8px 6px .01px;
z-index: 1;
}
<div class="background">
<div class="menu">
<button type="submit" class="btns"><i class="fas fa-home"></i></button>
<button type="submit" class="btns"><i class="fas fa-compass"></i></button>
<button type="submit" id="mic" class="btns"><i class="fas fa-microphone"></i></button>
<button type="submit" class="btns"><i class="fab fa-youtube"></i></button>
<button type="submit" class="btns"><i class="fas fa-user-circle"></i></button>
</div>
</div>
Use !important to override the the previous margin.
Eg:
#media screen and (max-width: 600px) {
.marginleftright {
margin-left: 0 !important;
margin-right:0 !important;
}}
.marginleftright{
margin-right: 10%;margin-left: 10%;
}

solution for all resolutions

my css is
#charset "utf-8";
* {
margin: 0;
padding: 0;
}
body {
background-color: #FFFFFF;
}
div#header {
background-color: #969696;
height: 80px;
}
div#mid-bar {
background: url(images/home.jpg) left no-repeat #6f6565;
height: 200px;
padding: 10px 0 10px 0;
}
#searchbox {
float: left;
background-color: #c1c1c1;
height: 200px;
width: 400px;
margin-left: 300px;
}
#multi-ads {
float: left;
background-color: #c1c1c1;
height: 200px;
width: 450px;
margin-left: 10px;
}
my html is
<body>
<div id="header">
</div>
<div id="mid-bar">
<div id="searchbox">
</div>
<div id="multi-ads">
</div>
</div>
</body>
I am currently working on 1280 x 800 resolution. When i change degrade resolution, scrollbars activate. I want that my page automatically fits in the resolution of the clients. What should i do?
use %'s and/or em's for dimensions
look into elastic / fluid layout techniques
Less Framework 2: http://lessframework.com/

Resources