CSS Two grid DIVs, images and text gives me blackout - html

I've been playing with this grid for a while, it's a two grid system in which i'm trying to add two different images. I've added the images with success. However, It's when i try to make two separate containers for the text i would like to place over the images everything goes wrong. Been trying to wrap my head around this for hours without results.
I did succeed to add text over the image with the one column. However, these two columns just won't let me.
What is the best way to solve this?
CSS
/* SECTIONS */
.section-ad {
clear: both;
padding: 0px;
margin:0;
}
/* COLUMN */
.col {
display: block;
float:left;
margin: 0% 0% 0% 1%;
}
.col:first-child { margin-left: 0; }
/* GROUP */
.group:before,
.group:after { content:""; display:table; }
.group:after { clear:both;}
.group { zoom:1; /* For IE 6/7 */ }
/* TWO GRID */
.span_2_of_2 {
width: 100%;
height: auto;
}
.span_1_of_2 {
width: 49.5%;
height: auto;
}
.span_2_of_2 img {
width: 100%;
height: auto;
}
.span_1_of_2 img {
width: 100%;
height: auto;
}
/* GO FULL WIDTH AT LESS THAN 480 PIXELS */
#media only screen and (max-width: 480px) {
.col {
margin: 0% 0 0% 0%;
}
}
#media only screen and (max-width: 480px) {
.span_2_of_2, .span_1_of_2 { width: 100%; }
}
HTML
<div class="section-ad group">
<div class="col span_1_of_2">
<img src="https://cdn.shopify.com/s/files/1/0786/5107/files/main-sale-large.jpg?11274335160121521292" />
</div>
<div class="col span_1_of_2">
<img src="https://cdn.shopify.com/s/files/1/0786/5107/files/main-plain-x450_ab05c8e5-7269-4d98-b510-8ba5127db9c4.jpg?13010707129353802904" />
</div>
</div>
Best Regards,
Robin.

You can place text over image following way.
Add span inside col div and add text inside. And give position:absolute and parent div to position:relative;. Then you can set it's position using left and right value.
.section-ad {
clear: both;
padding: 0px;
margin:0;
}
/* COLUMN */
.col {
display: block;
float:left;
margin: 0% 0% 0% 1%;
position: relative;
}
.col:first-child { margin-left: 0; }
/* GROUP */
.group:before,
.group:after { content:""; display:table; }
.group:after { clear:both;}
.group { zoom:1; /* For IE 6/7 */ }
/* TWO GRID */
.span_2_of_2 {
width: 100%;
height: auto;
}
.span_1_of_2 {
width: 49.5%;
height: auto;
}
.span_2_of_2 img {
width: 100%;
height: auto;
}
.span_1_of_2 img {
width: 100%;
height: auto;
}
span {
color: #000000;
font-size: 25px;
left: 50%;
position: absolute;
top: 50%;
transform: translate(-50%, -50%);
}
/* GO FULL WIDTH AT LESS THAN 480 PIXELS */
#media only screen and (max-width: 480px) {
.col {
margin: 0% 0 0% 0%;
}
}
#media only screen and (max-width: 480px) {
.span_2_of_2, .span_1_of_2 { width: 100%; }
}
<div class="section-ad group">
<div class="col span_1_of_2">
<img src="https://cdn.shopify.com/s/files/1/0786/5107/files/main-sale-large.jpg?11274335160121521292" />
<span>Some text</span>
</div>
<div class="col span_1_of_2">
<img src="https://cdn.shopify.com/s/files/1/0786/5107/files/main-plain-x450_ab05c8e5-7269-4d98-b510-8ba5127db9c4.jpg?13010707129353802904" />
<span>Some text</span>
</div>
</div>

Thanks to all your replies.
Ketan - Altough your solution worked, it did not fit my needs.
However, thanks to your reply i managed to surpass my blackout. So i owe it too you anyway. Thanks!
This might now be the best way,
but this is how i did it.
CSS
CSS
/* TVĂ… KOLUMN ADVERT # 705x450 */
.span_1_container {
position: absolute;
top: 80%;
left: 25%;
z-index: 0;
padding: 0;
padding: 1.2em;
font-size: .5em;
text-align: center;
width: 45%;
}
.span_1_heading {
font-size: 20px;
line-height: 100px;
display:inline-block;
position: relative;
}
.span_2_container h2:before {
content: '';
border-top: 1px solid #383a4f;
position: absolute;
width: 25%;
left: 35%;
top: 50px;
}
.span_2_container {
position: absolute;
top: 25%;
left: 0%;
z-index: 0;
padding: 0;
padding: 1.2em;
font-size: .5em;
text-align: center;
width: 45%;
}
.span_2_container h2:after {
content: '';
border-bottom: 1px solid #383a4f;
position: absolute;
width: 25%;
left: 35%;
bottom: 50px;
padding-bottom: 20px;
}
<div class="section-ad group">
<div class="col span_1_of_2">
<img src="https://cdn.shopify.com/s/files/1/0786/5107/files/main-sale-large.jpg?5000542013708637763" />
<div class="span_1_container">
SHOP NOW</div>
</div>
<div class="col span_1_of_2">
<img src="https://cdn.shopify.com/s/files/1/0786/5107/files/main-plain-x450_ab05c8e5-7269-4d98-b510-8ba5127db9c4.jpg?13010707129353802904" />
<div class="span_2_container">
<h2 class="span_2_heading" style="font-weight: normal; color: #383a4f;">Pocketsquares</h2>
<p style="font-family: 'Lato'; font-size: 14px; color: #383a4f; line-height: 15px; padding-bottom: 20px;">Explore our premium pocketsquares.</p>
SHOP NOW</div>
</div>
</div>

Related

Overlapping image with background image that has navbar and logo

How do I stack images on bg-image exactly like this using html there is a navbar and logo on the BG as well
i tried something like this
// clearfix
.image-stack::after {
content: ' ';
display: table;
clear: both;
}
.image-stack__item--top {
float: left;
width: 66%;
margin-right: -100%;
padding-top: 15%; // arbitrary
position: relative;
z-index: 1;
}
.image-stack__item--bottom {
float: right;
width: 75%;
}
it didnt work as anticipated
enter image description here
There are many ways to approach this.
But first you need to understand
CSS Positioning, CSS Layout (Using Grid / FlexBox / Float, etc ) & CSS BoxModel.
So based on the snippet you posted, I am going with float, but I would have recommended flex as it's powerful and flexible.
Below is what I came up with.
/* USING MOBILE-FIRST APPROACH, I.E DEFINING CSS FOR MOBILE FIRST */
body {
padding: 0;
margin: 0;
font-family: sans-serif;
}
/* Will serve as container */
.image-stack {
position: relative;
}
.image-stack .bg {
position: absolute;
height: 100%;
width: 100%;
/* overlay-color */
background: black;
}
.image-stack .bg>img {
opacity: .75;
width: 100%;
height: 100%;
object-fit: cover;
}
/* will serve as row */
.image-stack .image-stack__item {
position: relative;
padding: 20px 10px;
height: 100%;
}
.col-half {
padding: 0 10px;
position: relative;
height: 100%;
}
.text-format {
color: white;
margin-bottom: 30px;
}
.text-format h1 {
font-size: 3rem;
font-weight: 700;
margin: 5px 0;
}
.img-overlap {
width: 100%;
height: 100%;
object-fit: cover;
}
/* RESPONSIVE CSS FOR BIG DEVICES */
#media screen and (min-width: 768px) {
.image-stack {
background: yellow;
/* height must be set in vh, px, rem, em */
height: 80vh;
margin-bottom: 60px;
}
.col-half {
/* SINCE WE ARE NOT USING `box-sizing: border-box` WE HAVE TO REMOVE THE LEFT AND RIGHT PADDING WE GIVE FROM MOBILE CSS = (20PX) FROM THE WIDTH */
width: calc(50% - 20px);
float: left;
}
.text-format {
margin-bottom: 0px;
}
.img-overlap {
position: absolute;
left: 0;
bottom: -30px;
}
}
<div class="image-stack">
<div class="bg">
<img src="https://picsum.photos/id/1045/1440/400">
</div>
<div class="image-stack__item">
<div class="col-half text-format">
<p>5th Consistent Award Winning Year!</p>
<h1>Modern Design Solutions</h1>
<p>A descriptive paragraph that tells clients how good you are and proves that you are the best choice.</p>
<p>A descriptive paragraph that tells clients how good you are and proves that you are the best choice.</p>
See our Projects
</div>
<div class="col-half">
<img src="https://picsum.photos/id/1008/600/400" class="img-overlap" alt="Overlapping Image" />
</div>
<!-- Notice Break that I used to clear float -->
<br clear="both" />
</div>
</div>
<div style="background: brown">
Other test
</div>
I added comments in the css section to guide you.
CodePen Link => https://jsfiddle.net/d5urpbL2/17/

How to adjust the elements responsively for different widths and heights

Below is the screenshot that contains OK text as an element and 2 other elements in the left & right side and in the last buttons.
.center-text {
font-weight: bold;
font-style: normal;
text-align: center;
font-size: 25px;
line-height: 30px;
letter-spacing: normal;
opacity: 1.0;
margin-top: 25% !important;
}
.lower-content {
margin-bottom: 30px;
}
.group:before, .group:after {
content: "";
display: table;
}
.group:after {
clear: both;
}
.group {
clear: both;
*zoom: 1;
}
.lower-content-left {
float: left;
margin: 0 1.5%;
width: 63%;
}
.lower-content-right {
float: right;
margin: 0 1.5%;
width: 30%;
}
.button-left {
position: absolute;
width: 140px;
height: 140px;
left: 100px !important;
right: 0;
bottom: 0;
top: 620px;
}
.button-left>div {
width: 100px;
height: 100px;
}
.notification-button {
margin-left: 15px;
margin-top: 10px;
zoom: 2.0;
}
.button-right {
position: absolute;
width: 140px;
height: 140px;
left: 250px;
right: 20px;
bottom: 0;
top: 620px;
}
.button-right>div {
width: 100px;
height: 100px;
}
.heart-button {
margin-left: 15px;
margin-top: 10px;
zoom: 2.0;
}
<div class="center-text">Ok</div>
<div class="group">
<div class="lower-content-left">
<div class="lower-left">click here</div>
<div class="search-channels">Click
<br>Here</div>
</div>
<div class="lower-content-right">
<div class="lower-right">Otherwise Click here</div>
<div class="qrCode">Click here
<br>Also</div>
</div>
<div class="button-left">
<div>
<ion-icon name="notification" class="notification-button"></ion-icon>
</div>
</div>
<div class="button-right">
<div>
<ion-icon name="heart" class="heart-button"></ion-icon>
</div>
</div>
Problem : When I change the width of the screen the buttons hide away or is not present at the present position and same for all elements.
I have posted in the screenshot.I just need to edit my css to make it responsive according to the screenshot.
Try to use to css by resolution.
Example:
#media (max-width: 300px) {
.your-class {
your:option; }
}
#media (max-width: 600px) {
.your-class {
your:option; }
}

CSS center content in relative wrapper

I am making a personal website with a parallax background which takes 100% of the screen size, however when I change the screen size to the minimum size the text goes out of the div, I use a padding-top percentage. I do know quite a bit of css but I don't want to fiddle around and mess everything up, I've looked everywhere but no answer came close to my problem. Basically I just want to vertically and horizontally center my content even when I resize my screen.
Here's my CSS:
.wrapper {
width: 100%;
/* whatever width you want */
display: inline-block;
position: relative;
}
.wrapper:after {
padding-top: 52.50%;
/* 16:9 ratio */
display: block;
content: '';
}
.main {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
/* fill parent */
background-image: url('/storage/images/background.jpeg');
/* let's see it! */
color: white;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.text {
margin-top: 15%;
text-align:center;
}
And my HTML:
<div class="row">
<div class="wrapper">
<div class="main">
<div class=text>
<img src="/storage/images/image.jpg" style="border-radius:100%; width:150px; height:auto;">
<h1>My name</h1>
</div>
</div>
</div>
</div>
Use :
.main {
text-align: center;<-----------------------
//More code..........
}
.text {
max-width: 150px;
text-align: center;
display: inline-block;
margin-top: 15%;
}
.text img {
border-radius:100%;
width:70%;
height:auto;
}
.text h1 {
margin: 0;
padding: 0;
}
.wrapper {
width: 100%;
/* whatever width you want */
display: inline-block;
position: relative;
}
.wrapper:after {
padding-top: 52.50%;
/* 16:9 ratio */
display: block;
content: '';
}
.main {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
/* fill parent */
background-image: url('http://justcuteanimals.com/wp-content/uploads/2016/10/baby-bear-pictures-cute-animal-pics.jpg');
/* let's see it! */
color: white;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
text-align: center;
}
.text {
max-width: 150px;
text-align: center;
display: inline-block;
margin-top: 15%;
}
.text img {
border-radius:100%;
width:70%;
height:auto;
}
.text h1 {
margin: 0;
padding: 0;
}
<div class="row">
<div class="wrapper">
<div class="main">
<div class=text>
<img src="http://justcuteanimals.com/wp-content/uploads/2016/10/baby-bear-pictures-cute-animal-pics.jpg">
<h1>My name</h1>
</div>
</div>
</div>
</div>

Responsive horizontal timeline into vertical timeline with bootstrap

I've tried looking up tutorials/examples/codepens like this but wasn't successful. Please link to any I might have missed.
I'm trying to make this image into html/css/Bootstrap, which shouldn't be so bad, except the vertical line might be a difficult (could use advice on this):
And then when you're changing the size of your browser or looking at it on portrait on a smartphone, I want it to look more like:
But I don't know how to go about doing this so that the circle and caption that correspond to each other in the horizontal timeline are also together on the vertical timeline.
Thank you so much for your help! Basic codepens would be super appreciated!
Try This
.Img1{
margin-top:30px;
position:relative;
}
.Img1:before{
content: "";
position: absolute;
left: 0;
right: 0;
height: 21px;
width: 1px;
background: red;
margin: 0 auto;
top: -26px;
}
.Img1 img{width:100%;border-radius:50%;width:100px;
height:100px;}
.Text2{
width:200px;
}
.Img2{
margin-bottom:30px;
position:relative;
}
.Img2:before{
content: "";
position: absolute;
left: 0;
right: 0;
height: 21px;
width: 1px;
background: red;
margin: 0 auto;
bottom: -26px;
}
.Img2 img{width:100%;border-radius:50%;width:100px;
height:100px;}
.container {
float: left;
margin: 0 10px;
text-align:center;
}
#media screen and (max-width: 767px) {
.container {
float: none;
clear: both;
margin:20px 0;
}
.container:after { content: "\00A0"; display: block; clear: both; visibility: hidden; line-height: 0; height: 0;}
.container{ display: inline-block;}
html[xmlns] .container { display: block;}
* html .container{ height: 1%;}
.container {display: block}
.Text1 {
float: right;
margin:30px 0;
}
.Img1 {
float: left;
margin-top:0;
}
.Text2 {
float: left;
margin:30px 0;
}
.Img2 {
float: right;
margin-bottom:30px;
}
.wrapper{width:60%;margin:0 auto;}
.Img2:before,.Img1:before{display:none;}
}
<div class="wrapper">
<div class="container">
<div class="Text1">
Idea formed
</div>
<div class="Img1">
<img src="https://www.nasa.gov/sites/default/files/styles/image_card_4x3_ratio/public/thumbnails/image/leisa_christmas_false_color.png">
</div>
</div>
<div class="container">
<div class="Img2">
<img src="https://www.nasa.gov/sites/default/files/styles/image_card_4x3_ratio/public/thumbnails/image/leisa_christmas_false_color.png">
</div>
<div class="Text2">
Private funding for prototype raise
</div>
</div>
</div>
Right now I have used image but you can create a div instead of image. And I have just created structure you need to modify this code.

Unable to horizontally center my list (containing an image)

I have two lists that's location I would like to move as the screen size gets smaller. When the screen reaches 327px in length, I would like the "headlogo" to be centered on the screen, and everything else exactly as it is... how do I do this?
#charset "utf-8";
/* CSS Document */
body {
margin: 0;
padding: 0;
background-color: #DDDCDC;
}
ul {
list-style-type: none;
}
li {
display: inline;
padding: 10px;
}
.secondlist {
margin-top: 30px;
}
#headlogo {
width: 80px;
margin-left: 10px;
margin-top: 10px;
}
.firstlist {
position: relative;
float: left;
}
.secondlist {
position: absolute;
right: 0;
margin-right: 50px;
margin-top: 50px;
z-index: 2;
}
li#about {
width: 5px;
}
#media only screen and (max-width: 610px) {
.firstlist {
position: relative;
float: left;
}
.secondlist {
position: relative;
right: 0;
margin-right: 50px;
margin-top: 50px;
z-index: 2;
text-align: center;
}
li {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
li.listli {
line-height: 30px;
}
#headlogo {
width: 80px;
margin-left: 10px;
margin-top: -22px;
}
}
#media only screen and (max-width: 424px) {
#headlogo {
margin-top: -3px;
}
}
#media only screen and (max-width: 394px) {
#headlogo {
margin-top: 7.5px;
}
}
#media only screen and (max-width: 327px) {
#centerme {
display: inline-block;
position: relative;
top: 30px;
}
.firstlist {
float: none;
display: block;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
}
li.listli {
position: relative;
top: -10px;
}
}
<div id="centerme">
<ul class="firstlist">
<a class="alist" href="http://www.coopertimewell.com">
<li class="listl" id="image">
<img id="headlogo" src="images/logotestme.png" />
</li>
</a>
</ul>
</div>
<ul class="secondlist">
<a class="alist" href="#">
<li class="listli" id="home"><strong>HOME</li></a>
<a class = "alist" href = "http://www.coopertimewell.com/about"><li class = "listli" id = "about">ABOUT ME</li></a>
<a class = "alist" href = "http://www.coopertimewell.com/work"><li class = "listli" id = "work">PORTFOLIO</li></a>
<a class = "alist" href = "http://www.coopertimewell.com/contact"><li class = "listli" id = "contact">CONTACT</li></a>
</ul>
If you would only center it horizontally u have to edit #center in the 'max-width: 327px' query to the following:
#centerme {
display: block;
position: relative;
top: 30px;
width: 100%;
text-align: center;
}
I made the #center div a 100% width and set the text-align to center, which affects the image also. So this way you can center the image horizontally.
Or if you would center it horizontally and vertically you can use:
#centerme {
display: block;
position: relative;
top: 50%;
transform: translateY(50%);
-webkit-transform: translateY(50%);
width: 100%;
text-align: center;
}
With the same code from above I added
top: 50%;
transform: translateY(50%);
to center it horizontally.
Goodluck!
This should centre it below 327px;
#media (max-width: 327px){
#headlogo{
display: block;
margin: 0 auto
}
}
Check this out for more info
You can do
#media (max-width: 327){
#headlogo{
//with your code her//
}
}
Or you can use a new css file with media added
<link rel="stylesheet" media="screen and (max-width: 327px)" href="small.css/>
With this line you can add a complete new css if your screen will be 327px or smaller.