Responsive Square Parent, with responsive square background image - css

What I need is simple, but I'm striking out.
I need to create three divs that are a perfect responsive square using vws.
Inside those div's I need div's with a background image that are also perfect squares when you scale your browser.
The catch is that I need the background image to always be a square as well, and resize accordingly so that none of the image is clipped off.
Here's a fiddle:
http://jsfiddle.net/Lm7qd/2/
<div class="image-wrapper">
<div class="image">
</div>
</div>
<div class="image-wrapper">
<div class="image">
</div>
</div>
<div class="image-wrapper">
<div class="image">
</div>
</div>
.image-wrapper {
width: 90vw;
height: 90vw;
border: 1px solid #ccc;
}
.image {
background-image: url('http://upload.wikimedia.org/wikipedia/commons/thumb/1/15/Square_on_plane.svg/200px-Square_on_plane.svg.png');
background-repeat: no-repeat;
background-size:contain;
background-position:center;
background-size: 100%;
margin-bottom: 30px;
padding: 100px;
}

html
<div class="image-wrapper">
<div class="image">
<img src="http://3.bp.blogspot.com/--7gtJQo5mHE/UGMKHZapqmI/AAAAAAAAWGU/5X26Pgj_St4/s1600/funny-cat-pictures-017-005.jpg"/>
</div>
<div class="image">
<img src="http://3.bp.blogspot.com/--7gtJQo5mHE/UGMKHZapqmI/AAAAAAAAWGU/5X26Pgj_St4/s1600/funny-cat-pictures-017-005.jpg"/>
</div>
<div class="image">
<img src="http://3.bp.blogspot.com/--7gtJQo5mHE/UGMKHZapqmI/AAAAAAAAWGU/5X26Pgj_St4/s1600/funny-cat-pictures-017-005.jpg"/>
</div>
css
.image-wrapper {
width: 90vw;
height: 90vw;
border: 1px solid #ccc;
}
.image {
margin-bottom: 30px;
width: 100%;
}
.image img {
width: 100%;
}
http://jsfiddle.net/Lm7qd/12/

I'm not sure if this is what you are looking for because the only square i see here is the image-wrapper. Please check this out.
Fiddle
if this is not what you are looking for, can you post some of the images of your desired output.

Related

Adding a line of text underneath underneath a horizontal scroll of images with CSS

I am trying to put a line of text underneath the first image in an horizontal scroll. However, each time I try, it inserts the text mid way down the page and doesn't line up with the image.
I have attached my code below. Would someone be able to help and let me know the best way to achieve the above.
Edit Please find an image attached of what I am trying to achieve.
Thank you in advance. Esmé
* {
margin: 0;
padding: 0;
line-height: inherit;
}
.horizontal_slider {
display: block;
width: 100%;
overflow-x: scroll;
padding: 0px;
box-sizing: border-box;
background-color: #fff;
line-height: 25em;
}
.horizontal_slider_video {
display: block;
width: 100%;
overflow-x: hidden;
padding: 0px;
box-sizing: border-box;
background-color: #fff;
line-height: 25em;
}
.horizontal_slider::-webkit-scrollbar {
display: none;
}
/* for ms*/
.horizontal_slider {
-ms-overflow-style: none;
}
.slider_container {
display: block;
white-space: nowrap;
}
.item {
display: inline-block;
margin-right: 10px;
}
.item img {
width: px;
height: 850px;
object-fit: cover;
}
<div class="slider_container">
<div class="horizontal_slider">
<div class="slider_container">
<div style="text-align: left">
<h2>Side by side sisters</h2>
</div>
<div class="item">
<img src="https://freight.cargo.site/t/original/i/0b6e5d416b8d2666e95ad95076f5a051e7c744345a0c66f43667f08f1a2619d6/0007-copy.jpg">
</div>
<div class="item">
<img src="https://freight.cargo.site/t/original/i/21fae0988d8a0ae94a7dabcf10286fd8fc6e0488a3801de8017c2932024f46bb/0008-copy.jpg">
</div>
<div class="item">
<img src="https://freight.cargo.site/t/original/i/d045fce91bf44d863d7e5221f7ec9b61dbfe8d74145cb65120cbf7302f0ebbab/0006.jpg">
</div>
<div class="item">
<img src="https://freight.cargo.site/t/original/i/d045fce91bf44d863d7e5221f7ec9b61dbfe8d74145cb65120cbf7302f0ebbab/0006.jpg">
</div>
<div class="item">
<img src="https://freight.cargo.site/t/original/i/d045fce91bf44d863d7e5221f7ec9b61dbfe8d74145cb65120cbf7302f0ebbab/0006.jpg">
</div>
<img src="https://freight.cargo.site/t/original/i/d045fce91bf44d863d7e5221f7ec9b61dbfe8d74145cb65120cbf7302f0ebbab/0006.jpg">
</div>
</div>
</div>
The semantically correct way to do this is to wrap each image in a figure element and include a figcaption for the text. So something like:
<figure>
<img src="image.jpg" alt="image descriptor">
<figcaption>The caption that goes below the image</figcaption>
</figure>
You will no doubt need to adjust the css to make this look correct.

Adjusting bootstrap jumbotron background image to avoid collision with text

I have a jumbotron with background image and text. I need to have the image adjust so that the text does not collide with any part of the background image.
HTML:
<div class="jumbotron">
<div class="container">
<h1>Header title text</h1>
<p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. </p>
</div>
</div>
CSS:
.jumbotron {
position: relative;
background: #fff url("https://s3.us-east-2.amazonaws.com/ftp-assets/family.png") center center;
width: 100%;
height: 400px;
background-size: cover;
}
h1 {
margin-top: -30px;
margin-left: -20px;
}
p {
margin-left: -2%;
}
JSFIDDLE:https://jsfiddle.net/2ek2e2rf/
Try converting to something like this:
<div class="jumbotron jumbotron-fluid bg-dark">
<div class="jumbotron-background">
<img src="assets/background_img4.jpg" class="blur ">
</div>
<div class="container text-white" style="background-color: transparent; border: none;">
<h1>Some text</h1>
</div>
</div>
Then, you can adjust the background by changing the following properties:
.jumbotron-background {
top: 50px;
bottom: 50px;
left: 50px;
right: 50px;
}

Image gallery block with CSS with different image dimension?

I was trying to achieve the below layout with CSS. Here is the layout snap:
https://archive.org/details/Untitled1_20161122
Without masonry as this is not possible with masonry I guess (row/column width/height both changes which is not the case in masonry, I might be wrong though). Is there a nice pure CSS solution. It would be much appreciated. I have been searching for a CSS solution for quite long. www.bata.com for example have similar result in their homepage if that helps to explain the purpose, and without masonry as far as I am concerned.
Here is my code:
.gallery {
width: 70%;
margin: 0 auto;
background: crimson;
position: relative;
}
.col-20 {
width: 20%;
float: left;
/*border: 1px solid red;*/
}
.col-40 {
width: 40%;
float: left;
/*border: 1px solid red;*/
}
.col-60 {
width: 60%;
float: left;
/*border: 1px solid red;*/
}
div {
overflow: hidden;
}
img {
width: 100%;
height: auto;
}
<div class="gallery">
<div class="col-40">
<img src="1.png" alt="">
</div>
<div class="col-20">
<img src="2.jpg" alt="">
</div>
<div class="col-20">
<img src="3.jpg" alt="">
</div>
<div class="col-20">
<img src="4.png" alt="">
</div>
<div class="col-20">
<img src="2.jpg" alt="">
</div>
<div class="col-20">
<img src="3.jpg" alt="">
</div>
</div>
Thank you in advance.
If you are fine with a static layout, you could use a table with a fixed layout and no borders.
https://css-tricks.com/fixing-tables-long-strings/
Set your images as backgrounds for the table with background-size: cover;
Then using width, colspan and rowspan, create a fixed layout on your table.

Create 6 boxes with css

I really need some help with some easy css that I just can't get my head around.
I want to create boxes like in the link below.
I guess I could have the code for just one of them, and then use it over and over again, but how do I create the boxes so that they don't mind the other stuff around them?
Example here: http://s23.postimg.org/qypbfvv0r/boxes.jpg
Here: I have figured out a way of doing this. I hope that this helps you in some way in helping you figure out how to finish your task.
HTML:
<div class="containers">
<p class="heading">Heading</p>
<div class="inner1"></div>
<div class="inner2"></div>
</div>
<div class="containers">
<p class="heading">Heading</p>
<div class="inner1"></div>
<div class="inner2"></div>
</div>
<div class="containers">
<p class="heading">Heading</p>
<div class="inner1"></div>
<div class="inner2"></div>
</div>
CSS:
.containers {
width: 300px;
height: 150px;
border: 1px solid black;
margin-bottom: 10px;
overflow: hidden;
position: relative;
}
.inner1 {
margin-left: 5px;
width: 135px;
height: 80px;
border: 1px solid black;
background-color: blue;
}
.inner2 {
position: relative;
float: right;
top: -60%;
margin-left: 5px;
margin-right: 5px;
width: 135px;
height: 80px;
border: 1px solid black;
background-color: red;
}
.heading {
padding-left: 20px;
}
You can start off using this code. After this you can give border styles and colors to the individual divs.
<div>
<div style="float:right"> Content </div>
<div style="float:left"> Content </div>
</div>
<div style="padding-top:10px">
<div style="float:right"> Content </div>
<div style="float:left"> Content </div>
</div>
<div style="padding-top:10px">
<div style="float:right"> Content </div>
<div style="float:left"> Content </div>
</div>
Hope this helps

CSS boarders on floating divs

enter link description hereI have a set 8 floated divs, each taking 25% width (and having another div and img inside), so they line up in two rows.
<div class="galleryboard" id="gallery3">
<div class="view view-first">
<img src="img/galleries/3/thumb/1.jpg">
<div class="mask">
Enlarge
</div>
</div>
<div class="view view-first">
<img src="img/galleries/3/thumb/2.jpg">
<div class="mask">
Enlarge
</div>
</div>
<div class="view view-first">
<img src="img/galleries/3/thumb/3.jpg">
<div class="mask">
Enlarge
</div>
</div>
<div class="view view-first">
<img src="img/galleries/3/thumb/4.jpg">
<div class="mask">
Enlarge
</div>
</div>
<div class="view view-first">
<img src="img/galleries/3/thumb/5.jpg">
<div class="mask">
Enlarge
</div>
</div>
<div class="view view-first">
<img src="img/galleries/3/thumb/6.jpg">
<div class="mask">
Enlarge
</div>
</div>
<div class="view view-first">
<img src="img/galleries/3/thumb/7.jpg">
<div class="mask">
Enlarge
</div>
</div>
<div class="view view-first">
<img src="img/galleries/3/thumb/8.jpg">
<div class="mask">
Enlarge
</div>
</div>
</div>
I want to add only the inner borders to all floats by manually picking each float by css, like so:
.view:nth-child(1) {
border-left:none
}
.view:nth-child(5) {
border-left:none
}
.view:nth-child(4) {
border-right:none
}
.view:nth-child(8) {
border-right:none
}
.view:nth-child(1), .view:nth-child(2), .view:nth-child(3), .view:nth-child(4) {
border-top:none;
}
.view:nth-child(5), .view:nth-child(6), .view:nth-child(7), .view:nth-child(8) {
border-bottom:none;
}
but somehow, I'm getting the borders of 2nd, 3rd, 6th and 7th float all wrong - see it here
jsfiddle
the divs are styled here
.view {
width: 25%;
box-sizing:border-box;
float: left;
overflow: hidden;
position: relative;
text-align: center;
border:3px solid blue
}
.view .mask, .view .content {
width: 100%;
height: 100%;
position: absolute;
overflow: hidden;
top: 0;
left: 0;
}
.view img {
display: block;
position: relative;
width:100%;
height:auto;
}
and apparently the problem is caused by the img having its width set to 100%. Can you find a solution to have my inner borders all the same size? Thanks
Try
Remove all child styling and apply following
.view:nth-child(1), .view:nth-child(2), .view:nth-child(3), .view:nth-child(5), .view:nth-child(6), .view:nth-child(7) {
border-right: medium none;
}
.view:nth-child(1), .view:nth-child(2), .view:nth-child(3), .view:nth-child(4) {
border-bottom: medium none;
}
In the .view i have just added height or pass the height dynamicaly
.view {
border: 3px solid blue;
box-sizing: border-box;
float: left;
**height: 240px;**
overflow: hidden;
position: relative;
text-align: center;
width: 25%;
}

Resources