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/
Related
Im trying to position this image and tittle with text on my website.
How can I make it responsive so that the scale doesnt change on different devices and everything stays at the same position.
Im new at this, so im probably making a lot of mistakes.
div.content {
width: 100vw;
display: flex;
}
div.column1 {
width: 15%;
background-color: #F7F7F7;
overflow: hidden;
height: 100vh;
}
div.column2 {
width: 70%;
overflow: hidden;
}
.lobby {
width: 45%;
height: 45%;
padding-top: 5.6rem;
padding-left: 1rem;
}
.title {
padding-top: 4.7rem;
display: inline-block;
float: right;
width: 50%;
font-size: 1.8rem;
}
.descr {
display: inline-block;
width: 30vw;
float: right;
font-size: 1rem;
padding-top: 0.4rem;
}
<div class="content">
<div class="column1">
</div>
<div class="column2">
<div class="title">Installations
<p class="descr"> We are a gym based in Carballo, A Coruña, counting with an installation </p>
</div>
<img class="lobby" src="img/lobby.jpg" alt="photo of the lobby of the gym" />
</div>
</div>
<div class="column1">
</div>
As you can see im trying to position the image and the text on the middle row of my website, since it is divided into 3 columns.
Anything I can do to improve the code and to make it more responsive.
Thanks!
You don't need 3 columns. My approach starts defining the wrapper layout (the container), then working on the content layout (2 columns nested on the wrapper).
Here is my way of doing it:
HTML
<div class="main-container container">
<div class="inner-container content">
<div class="column-left column column-1">
<img class="lobby" src="https://upload.wikimedia.org/wikipedia/en/c/cb/Placeholder_logo.png" alt="photo of the lobby of the gym">
</div>
<div class="column-right column column-2">
<h1 class="title">Installations</h1>
<p class="descr">We are a gym based in Carballo, A Coruña, counting with an installation </p>
</div>
</div>
</div>
CSS
<style>
html,
body {
padding: 0px;
margin: 0px;
}
/* set the layout */
.main-container {
width: 100%;
max-width: 100vw;
min-height: 100vh;
box-sizing: border-box;
padding-left: 15%;
padding-right: 15%;
position: relative;
}
/* this is a pseudo element, it renders the grey background on the left */
.main-container:before {
content: "";
display: block;
height: 100%;
background-color: #F7F7F7;
/* same width of padding-left as it covers only the left side */
width: 15%;
position: absolute;
z-index: 1000;
top: 0;
left: 0;
}
.inner-container {
width: 100%;
display: flex;
flex-wrap: wrap;
padding: 2rem 1rem 0;
box-sizing: border-box;
}
.column {
padding: 3.6rem 0 1rem;
box-sizing: border-box;
/* Column width - Change this with media Queryes */
width: 50%;
flex-basis: 50%;
}
/* page elements*/
.title {
font-size: 1.8rem;
margin-top: 0px;
}
.descr {
font-size: 1rem;
padding-left: 3rem;
}
.lobby {
width: 45%;
height: auto;
}
/* responsive media query */
/* decide the breakpoint to start having 1 column */
#media screen and (max-width: 767px) {
.column {
width: 100% !important;
flex-basis: 100%;
}
}
</style>
Here is a working Codepen: https://codepen.io/Davevvave/pen/BaPZRbb
Consider the #Sfili_81 advice, first study and learn about #media_queries (https://www.w3schools.com/css/css3_mediaqueries_ex.asp), avoid float, and
(I suggest) try to understand the natural behavior of HTML rendering flux, the semantic meaning of HTML tags and empower all with CSS.
I don't have much knowledge about html and css and I couldn't find the answer on the internet so I am here.
Problem:
I am trying to make an image fill top part of the screen but one thing stops me from it and it's the default margin of the <body>. I've managed it by using margin: -10px; But now the image can't fill the screen by 20px, probably because there is no margin, image still thinks screen is that big.
html,body {
width: 100%;
height: 100%;
margin: -10px;
padding: 0;
overflow: hidden;
}
img {
width: 1600px;
height: 300px;
opacity: 70%;
object-fit: cover;
object-position: top 10px;
}
.cont {
position: relative;
text-align: center;
padding: 10px;
}
.main-text {
font-size: 100px;
color: white;
position: absolute;
top: 100px;
left: 70px;
}
<body>
<div class="cont">
<img src="https://i.stack.imgur.com/DWZAk.jpg">
<div class="main-text">Big Ass Title</div>
</div>
</body>
NOTE: If you have any questions or didn't understand anything about the question, please ask because I am ready for any answer. :) Thanks.
If your image is meant to be a decoration(design), then background is fine to use.
.cont can be a flex or grid element, to avoid position absolute and possible unwanted sides effects.
here an example with a background and grid:
body {
margin: 0;
min-height: 100vh; /* optionnal if it does not have a purpose */
}
.cont {
height: 300px; /* guessed from your code */
display: grid; /* default make a single column*/
background: url(https://picsum.photos/id/1015/600/300) 0 0 / cover; /* background covering */
}
.main-text {
margin-block: auto; /* vertical-centering in its row from here */
margin-inline-start:70px;
font-size: 100px; /* from your code */
color: white; /* from your code */
font-weight: normal; /* you looked for this? */
text-shadow: 0 0 1px #000; /*Optionnal increase readability*/
}
<div class="cont">
<h1 class="main-text">Big Ass Title</h1><!-- if that's a title, then make it a title ;) -->
</div>
Generally to eliminate all the margins and paddings you can add:
* {
margin: 0;
padding: 0;
}
By the way I attached a snippet where it's working as you requested. Is better to eliminate the margins than adding a negative margin, if you want to do it that way you must to compensate it in the width to achieve the 100% width intended.
html,
body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
overflow: hidden;
}
img {
width: 100%;
margin: 0;
height: 300px;
opacity: 70%;
object-fit: cover;
}
.cont {
position: relative;
text-align: center;
}
.main-text {
font-size: 100px;
color: white;
position: absolute;
top: 100px;
left: 70px;
}
<html>
<body>
<div class="cont">
<img src="https://images2.alphacoders.com/941/thumb-1920-941898.jpg">
<div class="main-text">Big Ass Title</div>
</div>
</body>
</html>
I'm trying to learn HTML/CSS and working on a nav bar, however, I am experiencing a scaling problem. This is the website in full screen.
This is the website minimized a bit.
Then this is the website minimized all the way.
As you can tell when I scale the website around into different scales then the proportions mess up and things begin to overlap. I have tried making the children absolute while keeping the containers relative. I am also using em's for measurement and not using pixels. What can I do to keep everything proportional while scaling?
This is the js fiddle
https://jsfiddle.net/2w1r136j/2/
HTML
<div class="container">
<header>
<nav>
<img class="logo" src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/8a/Westworld_Logo.svg/2000px-Westworld_Logo.svg.png" alt="logo">
<div class="leftNavContainer">
Home
Story
</div>
<div class="rightNavContainer">
Characters
Create
</div>
</nav>
</header>
</div>
CSS
* {
box-sizing: border-box;
}
body {
margin: 0;
background: #222;
font-size: 1em;
}
.container {
width: 100%;
height: 100%;
position: absolute;
}
header {
background: white;
height: 3.5em;
}
.logo {
height: 4.5em;
width: 4.5em;
position: absolute;
left: 50%;
margin-left: -50px !important; /* 50% of your logo width */
display: block;
margin-top: 0;
}
.leftNavContainer {
position: absolute;
float: left;
}
.leftNavContainer a {
position: relative;
display: inline;
margin-right: 2em;
margin-left: 2em;
}
.rightNavContainer {
float: right;
}
.rightNavContainer a {
position: relative;
display: inline;
margin-right: 2em;
margin-left: 2em;
}
Well Media queries might work, but a much better implementation would be using Flexbox or better CSS Grid.
I've updated the fiddle with a flexbox implementation.
https://jsfiddle.net/khpv2azq/3/
HTML
<head>
<title>
Westworld
</title>
<link rel="stylesheet" href="css/style.css">
</head>
<div class="container">
<header>
<nav>
<div class="leftNavContainer">
Home
Story
</div>
<img class="logo" src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/8a/Westworld_Logo.svg/2000px-Westworld_Logo.svg.png" alt="logo">
<div class="rightNavContainer">
Characters
Create
</div>
</nav>
</header>
</div>
CSS
* {
box-sizing: border-box;
}
body {
margin: 0;
background: #222;
font-size: 1em;
}
nav{
display: flex;
justify-content: space-between;
}
.container {
width: 100%;
height: 100%;
}
header {
background: white;
height: 3.5em;
}
.logo {
height: 4.5em;
width: 4.5em;
position: absolute;
left: 50%;
margin-left: -50px !important;
/* 50% of your logo width */
display: block;
margin-top: 0;
}
.leftNavContainer {
}
.leftNavContainer a {
position: relative;
display: inline;
margin: 4px;
}
.rightNavContainer {
}
.rightNavContainer a {
position: relative;
display: inline;
margin: 4px;
}
Also MDN resource for Flex box -
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox
Hope this help! 😇
You can use media queries to change sizes at breakpoints
ex:
#media only screen and (max-width: 600px) {
body {
font-size: .7em;
}
}
https://jsfiddle.net/2w1r136j/7/
However, you might consider using the media queries to incorporate a responsive design which will work for mobile.
A common idiom is to collapse the menu items into full width elements, and to bump up the font size.
something like: https://jsfiddle.net/2w1r136j/40/
I'm trying to put a pseudo element as a background image that simply crops at the document's width. However, when I put a background image in it keeps expanding the width of the document, making some other divs really wide.
Specifically, you can see from the screenshot that the nav is extending its width to accommodate the pseudo element's background image.
My attempt:
I've seen it done, but am not what the difference is, as the code in the actual pseudo element is the same. An example:
HTML:
<nav class="navbar navbar-default navbar-fixed-top navbar-custom">
<div class="container nav-down">
<div class="navbar-header page-scroll">
<a class="navbar-brand" href="/"><img src="/static/ScoopsLogo.png" alt="${out.global.siteName} Logo"></a>
<p class="navbar-blog">Blog</p>
</div>
</div>
<div id="scroll-progress">
<div id="scroll-progress-bar"></div>
</div>
</nav>
<section id="home">
<div class="home-1">
<div class="home1-1">
<h1>Sound smart at the dinner table</h1>
<h5>Learning made easy & fun</h5>
</div>
</div>
<div class="home-lessons fade-in-up-static delay-2">
<!-- List of Lessons -->
<h5 class="text-center">NEW SCOOPS</h5>
<div class="lessons-list">
</div>
</div>
</section>
CSS:
.navbar {
min-height: 50px;
margin-bottom: 20px;
}
.navbar-default {
background-color: #f8f8f8;
border-color: #e7e7e7;
}
.navbar-fixed-top {
top: 0;
border-width: 0 0 1px;
}
.container {
max-width: 600px;
}
.navbar-custom {
.navbar-header {
width: inherit;
max-width: inherit;
}
.navbar-brand {
img {
width: auto;
height: 100%;
}
}
.navbar-blog {
float: right;
padding: 10px;
margin: 3px 10px 0 0;
}
}
.home-lessons {
width: 100%;
padding: 3%;
#media (min-width: $screen-md-min) {
margin-bottom: 20px;
padding: 20px 40px;
}
h5 {
margin-top: -100px;
}
&::before {
content: '';
background-image: url(/static/Scoops-Icons.png);
background-size: cover;
width: 500px;
height: 500px;
display: block;
position: absolute;
margin-left: 200px;
margin-top: -200px;
}
}
I just answered a very similar question that you put a bounty on over here. In this case, I think that your best bet would be to either enforce a max width on your background-carrying pseudo-element, or drop the overflow-x on your document.
Below is a snipper of your CSS with the fix:
.home-lessons {
width: 100%;
padding: 3%;
#media (min-width: $screen-md-min) {
margin-bottom: 20px;
padding: 20px 40px;
}
h5 {
margin-top: -100px;
}
&::before {
content: '';
background-image: url(/static/Scoops-Icons.png);
background-size: cover;
width: 500px;
height: 500px;
display: block;
position: absolute;
margin-left: 200px;
margin-top: -200px;
max-width: calc(100% - 200px); /* HERE IS THE FIX */
}
}
If that didn't work, the quick fix would be to go for this:
html {
overflow-x: hidden;
}
I've seen some people overkill it slightly by using, html, body as their CSS selectors, this is up to you.
Parent element should use a position: relative whilst the child element uses top: 0 and left: 0.
Like this:
.parent {
position: relative;
}
.child {
top: 0;
left: 0;
}
I have some code as follows where I think my layering is causing a rendered link to be unclickable. Some of this example I've converted to styles from external CSS classes for ease of writing this up as a small use case. This is currently being testing on modern browsers (latest stable FF and Chrome).
<body>
<!-- whole container needs to be at z-index of -1 -->
<div id="container">
<div class="corner" id="backgroundTopLeft"></div>
<div class="corner" id="backgroundTopRight"></div>
<div class="corner" id="backgroundBottomLeft"></div>
<div class="corner" id="backgroundBottomRight"></div>
<!-- whole container needs to be at z-index of 1 -->
<div id="container2">
<div id="headerSection"><img src="images/jClarity_logo.png" alt="logo" /></div>
<div id="navigationSection">
<a class="selected" href="#">Introduction</a><span class="menuDivider">|</span>About
</div>
</div>
</div>
</body>
And the CSS
#charset "utf-8";
/* Default margin, padding and font-family */
*
{
font-family: Arial;
margin: 0px;
padding: 0px;
}
/* All images should have no borders by default */
img
{
border: none;
}
/* Global styling for links, uses black as the color */
a
{
color: #000000;
text-decoration: none;
}
a.selected
{
font-weight: bold;
}
a:hover
{
color:#FF00FF;
}
#container
{
position: relative;
z-index: -1;
height: 100%;
}
.corner
{
position: absolute;
height: 100px;
width: 100px;
background-color: #172944;
z-index: -1;
}
#backgroundTopLeft
{
top: 0px;
left: 0px;
}
#backgroundTopRight
{
top: 0px;
right: 0px;
}
#backgroundBottomLeft
{
bottom: 0px;
left: 0px;
}
#backgroundBottomRight
{
bottom: 0px;
right: 0px;
}
#container2
{
position: relative;
width: 100%;
height: 100%;
z-index: 1;
opacity: 0.8;
filter:alpha(opacity=80);
background-image:url('../images/groovepaper.png');
}
/* The headerSection div, designed to fit in a centered logo */
#headerSection
{
margin-left: auto;
margin-right: auto;
padding-bottom: 70px;
padding-top: 54px;
height: 70px;
width: 250px;
}
/* The navigationSection div, designed to fit in the menu */
#navigationSection
{
padding-bottom: 15px;
margin-left: auto;
margin-right: auto;
width: 600px;
text-align: right;
}
.menuDivider
{
color: #666666;
padding-left: 5px;
padding-right: 5px;
}
It all looks fine (lots of other purely color/font-size type styling is applied), but foobar.html is not clickable.
I'm pretty sure I've done something wrong with the layering, but I thought the use of z-indices would sort me out..
Working fine http://jsfiddle.net/hPkTu/, if the problem is with IE8, use z-index:1; IE8 is known to be buggy with this particular problem of z-index's.
UPDATE You changed your question, here is the working jsFiddle of your updated problem http://jsfiddle.net/VjTXu/2/. I changed z-index of container to O, -1 was making it go below body and that's why your link was not clickable, now it is.