I am trying to accomplish something like this:
As I am using Bootstrap, for now I have this:
<div class="col-md-3">
<div class="test">
<%= (image_tag("http://example.com.image.jpg", :class => "img-responsive")) %>
<h2>hello</h2>
</div>
</div>
</div>
CSS:
.test {
position: relative;
h2 {
background-color: #bebebe;
position: absolute;
bottom: 0px;
left: 0px;
width: 100%;
}
}
This works well for big and medium screens but the problem is on smaller screens. After all elements stack to one column the problem appears with smaller images. On bigger screens where there are multiple elements in one row there is no problem, text appears on the bottom of the image. The problem is that some images are not big enough on smaller screens as they need to have width 100% of the screen and they are only 300-400ox wide. Because of that they don't use 100% of the screen, but header does use it.
It looks something like this:
**********************************
* *
* *
* Image *
* *
* *
********************************************
* Header *
********************************************
So, header spreads all the way to the left and right of the screen and jumps outside of the image. How to keep header inside of the image no matter of screen size?
Thank you!
Try this:
Demo : http://jsfiddle.net/lotusgodkk/bm3mjhm1/
CSS:
.test {
position: relative;
display:inline-block; //Add display:inline-block; if it doesn't affect your code.
}
img {
max-width:100%;
}
h2 {
background-color: #bebebe;
position: absolute;
bottom: 0;
left: 0;
right:0; // Remove width:100% and add left,right offset.
}
HTML:
<div class="test">
<img src="http://lorempixel.com/400/200/sports/1/" />
<h2>Sample TExt. Sample TExt</h2>
</div>
Check the demo for different sizes of image.
DEMO: http://jsbin.com/nobape
There are two options. The first is the answer, but it's not the best idea. When the viewport gets very small, the caption text can cover up a good portion of the image. When you look at the demo, the second row only does the caption over the image at the 500px min-width and under that, it stacks, which looks very nice and easy to read.
CSS
.img-full-width {
width: 100%;
height: auto;
}
.caption {
position: relative;
margin-bottom: 2%;
}
.caption h3 {
margin: 0;
color: #fff;
position: absolute;
bottom: 0;
left: 0;
right: 0;
padding: 10px;
background: rgba(41,82,123,.8);
font-size: 15px;
}
.caption-2 {
position: relative;
margin-bottom: 2%;
}
.caption-2 h3 {
margin: -1px 0 0 0;
color: #fff;
padding: 10px;
background: rgba(41,82,123,1);
font-size: 15px;
}
#media (min-width:500px) {
.caption-2 h3 {
margin:0;
position: absolute;
bottom: 0;
left: 0;
right: 0;
background: rgba(41,82,123,.8);
}
}
HTML
<div class="container">
<div class="row">
<div class="col-sm-4">
<div class="caption">
<img src="http://placekitten.com/g/400/300" class="img-full-width alt="" />
<h3>My Caption Goes Here</h3>
</div>
</div>
<div class="col-sm-4">
<div class="caption">
<img src="http://placekitten.com/g/400/300" class="img-full-width alt="" />
<h3>My Caption Goes Here</h3>
</div>
</div>
<div class="col-sm-4">
<div class="caption">
<img src="http://placekitten.com/g/400/300" class="img-full-width alt="" />
<h3>My Caption Goes Here</h3>
</div>
</div>
</div>
<hr>
<div class="row">
<div class="col-sm-4">
<div class="caption-2">
<img src="http://placekitten.com/g/400/300" class="img-full-width alt="" />
<h3>My Caption Goes Here</h3>
</div>
</div>
<div class="col-sm-4">
<div class="caption-2">
<img src="http://placekitten.com/g/400/300" class="img-full-width alt="" />
<h3>My Caption Goes Here</h3>
</div>
</div>
<div class="col-sm-4">
<div class="caption-2">
<img src="http://placekitten.com/g/400/300" class="img-full-width alt="" />
<h3>My Caption Goes Here</h3>
</div>
</div>
</div>
Related
Using Bootstrap 4 I'm trying to achieve an overlay effect with .png image which is also masking a part of bottom area of first section.
The height of .png image is 130px and it also should remain unscaled on mobile devices.
I've tried to use ::after pseudoelements with content as background image on first section, but this gives me a unwanted bottom margin.
See my example here: https://codepen.io/michalwyrwa/pen/EGbxXb
Is there a better way to do it?
CSS:
body {
color: #ecf0f1;
}
.welcome .col {
background-color: #3498db;
height: 50vh;
}
.welcome::after {
content: url(https://files.tinypic.pl/i/00976/nb1abpgxj5x3.png);
display: block;
margin: 0;
padding: 0;
}
.features .col {
background-color: #6ab04c;
height: 50vh;
}
HTML:
<section class="welcome">
<div class="container-fluid">
<div class="row text-center">
<div class="col-12">
<p class="my-3">Welcome text</p>
</div>
</div>
</div>
</section>
<section class="features">
<div class="container-fluid">
<div class="row text-center">
<div class="col-12">
<p class="my-3">Features</p>
</div>
</div>
</div>
</section>
I didn't find the root cause of your problem but I have the solution for you.
.welcome::after {
content: url(https://files.tinypic.pl/i/00976/nb1abpgxj5x3.png);
display: block;
padding: 0;
margin-bottom: -6px;
}
On the following site, I have a child div absolutely positioned at the bottom of its parent div - the hero image.
http://helpthemgrow.staging.wpengine.com/
Adding padding to the child div causes it to break out of parent div
Here is my code:
<div class="home-hero">
<div class="home-hero-img">
<div class="wrap">
<div class="home-image widget-area">
<section id="media_image-2" class="widget widget_media_image">
<div class="widget-wrap">
<img width="200" height="300" src="http://helpthemgrow.staging.wpengine.com/wp-content/uploads/2018/01/help-tehm-grow-book-cover-200x300.jpg" class="image wp-image-43 attachment-medium size-medium" alt="" style="max-width: 100%; height: auto;" srcset="http://helpthemgrow.staging.wpengine.com/wp-content/uploads/2018/01/help-tehm-grow-book-cover-200x300.jpg 200w, http://helpthemgrow.staging.wpengine.com/wp-content/uploads/2018/01/help-tehm-grow-book-cover.jpg 250w" sizes="(max-width: 200px) 100vw, 200px">
</div>
</section>
</div>
</div><!-- end wrap -->
</div><!-- end home-hero-img -->
<div class="home-hero-cta">
<div class="wrap">
<div class="three-fourths first">
<div class="home-hero-cta-text">Careers are developed one conversation at a time – over time.</div>
</div>
<div class="one-fourth">
<a class="button" href="/book/">Learn more</a>
</div>
</div><!-- end wrap -->
</div><!-- end home-hero-cta -->
</div><!-- end home-hero -->
Here is my CSS:
.home-hero {
background-image: url('/wp-content/uploads/2018/02/htg-hero-slide-one.jpg');
background-position: center;
background-repeat: no-repeat;
background-size: cover;
width: 100%;
padding: 100px 0 150px 0;
color: #fff;
margin: 0;
position:relative;
}
.home-hero-cta {
height: 50px;
width: 100%;
background: rgba(0,0,0,0.5);
position: absolute;
bottom: 0;
}
.home-hero-cta .wrap {
padding: 20px 0;
}
.home-hero-cta-text {
font-size: 25px;
}
What am I doing wrong?
Remove the set height that you have for home-hero-cta and that should fix your issue.
I have a section in my site that should stretch all the way across the screen.
I want to add 4 images in this section, one beside the other, and make them responsive. I want them to fill the background and breaks between them as needed. How should I modify my code below to accomplish the effects I desire?
#games {
background-color: #000;
}
#games img {
width: 100%;
height: auto;
}
.4columns {
width: 32%;
display: inline-block;
}
<section id="games" class="section section-games">
<div class="container-fluid">
<div class="row">
<img class="4columns" src="resources/media/icons/1.png">
<img class="4columns" src="resources/media/icons/2.png">
<img class="4columns" src="resources/media/icons/3.png">
<img class="4columns" src="resources/media/icons/4.png">
</div>
</div>
</section>
I think you want something like this :
.map{
margin:0;
padding:0;
}
.map img{
float: left;
width: 25%;
}
<div class="map">
<span>
<img src="http://www.inkntoneruk.co.uk/ink-cartridge-news/wp-content/uploads/2016/01/LOTRFOTRmovie.jpg" />
<img src="http://www.inkntoneruk.co.uk/ink-cartridge-news/wp-content/uploads/2016/01/LOTRFOTRmovie.jpg" />
<img src="http://www.inkntoneruk.co.uk/ink-cartridge-news/wp-content/uploads/2016/01/LOTRFOTRmovie.jpg" />
<img src="http://www.inkntoneruk.co.uk/ink-cartridge-news/wp-content/uploads/2016/01/LOTRFOTRmovie.jpg" />
</span>
</div>
Take a look at this http://jsfiddle.net/0ftrnkxo/
and the site http://omarhabash.com/sites
This looks great from a desktop.. I usually dont have problems with responsive design but what can I do to make this responsive?
THE HTML
<div id="g-site1" class="col-xs-12 demo-container">
<div class="same-s same-1">
<img class="img-responsive" src="http://omarhabash.com/sites/assets/img/sites/site1.jpg" alt="">
</div>
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#site1"> <i class="fa fa-search-plus"></i>
</button>
<div class="same-s same-2">
<img class="img-responsive" src="http://omarhabash.com/sites/assets/img/sites/mac.png" alt="">
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="site1" tabindex="-1" role="dialog" aria-labelledby="site1Label" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content1">
<div class="modal-body">
<img class="img-responsive site" src="http://omarhabash.com/sites/assets/img/sites/site1.jpg" alt="">
</div>
</div>
</div>
</div>
THE CSS
.same-s {
height: 160px;
width: 100%;
margin: 0 auto;
}
.same-s img {
width: 100%;
display: block;
margin: 0 auto;
height: auto;
}
.same-s.same-1 {
width: 66.5%;
overflow: scroll;
position: absolute;
margin-left: 174px;
margin-top: 65px;
height: 57.25%;
}
.demo-container {
height: 56em;
}
button.btn.btn-primary.btn-lg {
margin-left: 9.9em;
margin-top: 26.5em;
position: absolute;
}
img.site {
border: 4px solid #ccc;
}
With any grid system it's best to keep it and your content separate. Don't "hack the core", as the saying goes. Here's a simplified start:
http://jsfiddle.net/isherwood/0ftrnkxo/3
.demo-container {
overflow: hidden; /* demo only--accounts for image whitespace */
}
.mac {
position: relative;
margin: -5.3% -20.5% 0 -18.5%; /* demo only--accounts for image whitespace */
}
.screen {
position: absolute;
top: 9%; /* demo only--accounts for image whitespace */
right: 17%; /* demo only--accounts for image whitespace */
left: 15.6%; /* demo only--accounts for image whitespace */
height: 58%;
overflow: auto;
}
<div class="row">
<div class="col-xs-12">
<div class="demo-container">
<div class="mac">
<img class="img-responsive" src="http://omarhabash.com/sites/assets/img/sites/mac.png" alt="" />
<div class="screen">
<img class="img-responsive" src="http://omarhabash.com/sites/assets/img/sites/site1.jpg" alt="" />
</div>
</div>
</div>
</div>
</div>
To eliminate all those negative margins and the corresponding values on .screen, crop your Mac image tight to the black border. Of course, you'll still need smaller top, right, and left values to allow the Mac's frame to show around it.
I'd also fill the Mac image's screen entirely with black. That will eliminate the need to so perfectly position what's overlaying it.
Here's a demo with two Macs in two rows.
I have a div with some text, then an image underneath the text, whenever you add more text it goes behind the image, (basic example I created in jsfiddle I want it to push the image down just far enough so you can see the text. However I want the two boxes to still be inline, so the images stay consistent, ideally I don't want to just change the height of the div as this text is constantly changing.
<div class="box one">
<div>
<h1>Some text 1</h1>
<p>My paragraph of text is not going to be visible behind the car</p>
</div>
<a href="http://www.google.co.uk">
<img src="http://www.wallpaperswala.com/wp-content/gallery/audi-r8-gt/audi-r8-gt-in-garage.jpg" height="80px" width="150px">
</a>
</div>
<div class="box two">
<div>
<h1>Some text 2</h1>
<p>My paragraph of text is not going to be visible behind the car again!</p>
</div>
<a href="http://www.google.co.uk">
<img src="http://www.wallpaperswala.com/wp-content/gallery/audi-r8-gt/audi-r8-gt-in-garage.jpg" height="80px" width="150px">
</a>
</div>
.box {
color: #333333;
font-size: 12px;
height: 305px;
padding: 10px 15px 0;
width:150px;
}
.box div {
color: #333333;
font-size: 12px;
height: 90px;
padding: 10px 15px 0;
}
.two {
float:right;
margin-top:-310px;
}
Remove height and put min-height: 90px;
.box div {
color: #333333;
font-size: 12px;
padding: 10px 15px 0;
min-height: 90px;
}
http://jsfiddle.net/KApb6/10/
It is happening because you have given height:90px to .box div.
Instead of height, write this 'min-height:90px'.
Here is the fiddle.
So basically you want your text height to stay consistent between all your boxes?
This is quite hard.
One solution is to put every block you have in one row container, like this:
<div class="header">
<div class="one">Some text one</div>
<div class="two">Some text two</div>
</div>
<div class="image">
<div class="one"><img src="image-one.jpg"></div>
<div class="two"><img src="image-two.jpg"></div>
</div>
Or similarly with tables, but it would be hideously hard to maintain all the styles and layout in check.
Other way is just to use javascript to set the height, which is way easier.
Codepen
See this code to know if is the result that you want.
You could put the text in one box and the images in anorther one.
<div class="clearfix">
<div class="box one">
<div>
<h1>Some text 1</h1>
<p>My paragraph of text is not going to be visible behind the car</p>
</div>
</div>
<div class="box two">
<div>
<h1>Some text 2</h1>
<p>My paragraph of text is not going to be visible behind the car again!</p>
</div>
</div>
</div>
<div class="clearfix">
<div class="box one">
<a href="http://www.google.co.uk">
<img src="http://www.wallpaperswala.com/wp-content/gallery/audi-r8-gt/audi-r8-gt-in-garage.jpg" height="80px" width="150px">
</a>
</div>
<div class="box two">
<a href="http://www.google.co.uk">
<img src="http://www.wallpaperswala.com/wp-content/gallery/audi-r8-gt/audi-r8-gt-in-garage.jpg" height="80px" width="150px">
</a>
</div>
</div>
Then in the css remove the height of the div and add the clearfix class:
.box div {
color: #333333;
font-size: 12px;
padding: 10px 15px 0;
}
.clearfix:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
.clearfix {
display: inline-block;
}
html[xmlns] .clearfix {
display: block;
}
* html .clearfix {
height: 1%;
}