Resizing multiple divs on resizing window - html

I asked a question some days ago about resizing a div when resizing the browser so that it looks good on desktop and on mobile devices. But now I have an extended problem to the same. I have 2 divs one below the other and the bottom footer div resizes on resizing the browser. The working solution can be found here in my previous post: Resize div on resizing window
But in the problem here, I added another div on top of it. On resizing the browser window, the divs don't stack on top of one another. They work fine on a full window on a desktop. Would appreciate any suggestions that you may have or if you'd like to modify the sample code - that would be great!
.info-banner {
position: fixed;
width: 100%;
font-family: Arial, sans-serif;
font-size: 24px;
background: #000000;
color: #FFFFFF;
text-align: center;
bottom: 30px;
left: 0%;
opacity: 0.8;
}
.info-banner a {
color: #FFFFFF;
text-decoration: none;
}
.info-banner a:hover {
color: #aaa;
}
.footer-box {
position: fixed;
font-family: Arial, sans-serif;
color: #FFFFFF;
background-color: #000000;
font-size: 11px;
width: 100%;
opacity: 0.8;
z-index: 50;
bottom: 0px;
left: 0px;
}
.footer-box h2 {
margin-top: 0;
margin-bottom: 0;
font-size: 20px;
text-align: center;
line-height: 30px;
font-weight: normal;
font-family: Arial, sans-serif;
color: #A9A9A9;
}
.footer-box a {
text-decoration: none;
outline: none;
color: #A9A9A9;
}
.footer-box a:hover {
text-decoration: underline;
}
<div id="contact-footer-merged">
<div id="contact-banner" class="info-banner">
<div>HEADER</div>
<div>SUB-HEADER</div>
<div>SUB-SUB-HEADER</div>
</div>
<div class="footer-box">
<h2>
LINK |
LINK |
LINK |
LINK |
LINK |
LINK |
LINK
</h2>
</div>
</div>
</div>

You have 'posititon:static' assigned to both '.footer-box' and ''#contact-banner'' elements. The '#contact-banner' element has a bottom position of 30px, so when the '.footer-box' list elements stack it increases the height of that element. Once the height of the '.footer-box' element is greater than 30px, it will overlap the '#contact-banner' element.
To solve this issue I have just remove position:static from both of those elements and added it to the '#contact-footer-merged' wrapper.
#contact-footer-merged {
position:fixed;
bottom:0;
left:0;
right:0;
width:100%;
}
.info-banner {
font-family: Arial, sans-serif;
font-size: 24px;
background: #000000;
color: #FFFFFF;
text-align: center;
opacity: 0.8;
}
.info-banner a {
color: #FFFFFF;
text-decoration: none;
}
.info-banner a:hover {
color: #aaa;
}
.footer-box {
font-family: Arial, sans-serif;
color: #FFFFFF;
background-color: #000000;
font-size: 11px;
opacity: 0.8;
z-index: 50;
}
.footer-box h2 {
margin-top: 0;
margin-bottom: 0;
font-size: 20px;
text-align: center;
line-height: 30px;
font-weight: normal;
font-family: Arial, sans-serif;
color: #A9A9A9;
}
.footer-box a {
text-decoration: none;
outline: none;
color: #A9A9A9;
}
.footer-box a:hover {
text-decoration: underline;
}
<div id="contact-footer-merged">
<div id="contact-banner" class="info-banner">
<div>HEADER</div>
<div>SUB-HEADER</div>
<div>SUB-SUB-HEADER</div>
</div>
<div class="footer-box">
<h2>
LINK |
LINK |
LINK |
LINK |
LINK |
LINK |
LINK
</h2>
</div>
</div>
</div>

Related

How to not move images around and push elements when browser is resizing

This is my HTML and CSS code. If you run this, there will be a image of a macbook and a 'buy' button. When the browser is minimised, the image is alittle off from the center. When it is in full screen, it causes the image to move up and the 'buy' button gets pushed to the bottom. I tried to use position: fixed but it didnt work. How do you make the picture have fixed position in the middle
.new {
font-family: Arial;
color: rgb(202, 137, 15);
font-size: 18px;
margin-bottom: 15px;
}
.macbook {
font-family: Arial;
font-weight: bold;
font-size: 44px;
margin-top: 0px;
margin-bottom: 10px;
}
.supercharged {
font-family: Arial;
font-weight: bold;
font-size: 60px;
margin-top: 0px;
margin-bottom: 25px;
}
.price {
font-family: Arial;
font-size: 18px;
margin-top: 0px;
}
.button {
background-color: #007aff;
color: white;
border-radius: 100px;
font-weight: bold;
border: none;
padding-left: 16px;
padding-right: 16px;
padding-bottom: 10px;
padding-top: 10px;
position: 50px;
}
.button:hover {
opacity: 0.8;
}
.button:active {
opacity: 0.5;
}
.charged {
color: plum;
text-decoration: underline;
}
.picture {
margin-top: 50px;
}
<!DOCTYPE html>
<html align='center'>
<body>
<p class='new'>New</p>
<h2 class='macbook'>MacBook Pro</h3>
<h1 class='supercharged'><span class='charged'>Supercharged</span> for pros.</h1>
<p class='price'>From $1999</p>
<button class='button'>Buy</button>
<img src="https://images.macrumors.com/t/PV_LL2AlRJvaRvbuXCTUOuDpwzU=/800x0/smart/article-new/2013/09/16-inch-macbook-pro.jpg?lossy" alt="Macbook" class='picture'>
</body>
</html>
Just apply display: block to the <a>-element. When you use display: block on an element, it will try to take up as much width as possible. Seeing as it is not inside a parent container, it will take up 100% width of the <body>-element, as that is the elements closest parent. This way, it won't wrap around the image. The link will however stretch and fill the entire parent container as well. To combat this, apply max-width: fit-content, so the link's width is only relative to its content. Then you can apply margin: auto to center the element again.
For a responsive image, apply max-width: 100% and height: auto. This way it will automatically scale down, as the max-width: 100% property won't let it overflow its parent container (the <body>-element)
body {
text-align: center;
}
.new {
font-family: Arial;
color: rgb(202, 137, 15);
font-size: 18px;
margin-bottom: 15px;
}
.macbook {
font-family: Arial;
font-weight: bold;
font-size: 44px;
margin-top: 0px;
margin-bottom: 10px;
}
.supercharged {
font-family: Arial;
font-weight: bold;
font-size: 60px;
margin-top: 0px;
margin-bottom: 25px;
}
.price {
font-family: Arial;
font-size: 18px;
margin-top: 0px;
}
.button {
background-color: #007aff;
color: white;
border-radius: 100px;
font-weight: bold;
border: none;
padding-left: 16px;
padding-right: 16px;
padding-bottom: 10px;
padding-top: 10px;
position: 50px;
}
.button:hover {
opacity: 0.8;
}
.button:active {
opacity: 0.5;
}
.charged {
color: plum;
text-decoration: underline;
}
.picture {
margin-top: 50px;
max-width: 100%;
height: auto;
}
a {
display: block;
max-width: fit-content;
margin: auto;
}
<p class='new'>New</p>
<h2 class='macbook'>MacBook Pro</h3>
<h1 class='supercharged'><span class='charged'>Supercharged</span> for pros.</h1>
<p class='price'>From $1999</p>
<button class='button'>Buy</button>
<img src="https://images.macrumors.com/t/PV_LL2AlRJvaRvbuXCTUOuDpwzU=/800x0/smart/article-new/2013/09/16-inch-macbook-pro.jpg?lossy" alt="Macbook" class='picture'>
By default an image is displayed inline, which is causing your issue. You're on the right track, but instead of position fixed, position: block; would be a better choice.
(You can also centre your image and avoid it overflowing using a max-width and some margin)
.new {
font-family: Arial;
color: rgb(202, 137, 15);
font-size: 18px;
margin-bottom: 15px;
}
.macbook {
font-family: Arial;
font-weight: bold;
font-size: 44px;
margin-top: 0px;
margin-bottom: 10px;
}
.supercharged {
font-family: Arial;
font-weight: bold;
font-size: 60px;
margin-top: 0px;
margin-bottom: 25px;
}
.price {
font-family: Arial;
font-size: 18px;
margin-top: 0px;
}
.button {
background-color: #007aff;
color: white;
border-radius: 100px;
font-weight: bold;
border: none;
padding-left: 16px;
padding-right: 16px;
padding-bottom: 10px;
padding-top: 10px;
position: 50px;
}
.button:hover {
opacity: 0.8;
}
.button:active {
opacity: 0.5;
}
.charged {
color: plum;
text-decoration: underline;
}
.picture {
margin: 50px auto 0 auto;
display: block;
max-width: 100%;
}
<!DOCTYPE html>
<html align='center'>
<body>
<p class='new'>New</p>
<h2 class='macbook'>MacBook Pro</h3>
<h1 class='supercharged'><span class='charged'>Supercharged</span> for pros.</h1>
<p class='price'>From $1999</p>
<button class='button'>Buy</button>
<img src="https://images.macrumors.com/t/PV_LL2AlRJvaRvbuXCTUOuDpwzU=/800x0/smart/article-new/2013/09/16-inch-macbook-pro.jpg?lossy" alt="Macbook" class='picture'>
</body>
</html>

make entire image fill background with css

Struggling to write CSS to format the image so that it covers the entire background of the page, as it doesn't seem to be able to do so below. It seems to be getting stuck up on the header and I am not sure how to correct that.
margin-top: 0px;}
h1 a {
background-color: black;
font-size: 40px;
color: white;
margin-left: 40px;
padding: 10px 20px;
letter-spacing: -1px;
text-decoration: none;
font-weight: bold;
}
.sidenav {
width: 150px;
position: fixed;
z-index: 1;
top: 85px;
left: 10px;
/*background: #ffffff;*/
overflow-x: hidden;
padding: 8x 0;
}
.sidenav a {
padding: 4px 1px 4px 40px;
text-decoration: none;
font-size: 25px;
color: #000000;
display: block;
font-weight: bold;
font-family: 'Helvetica Neue', 'Helvetica', 'Arial', 'sans-serif';
}
Make the image the background of the body or a div (is how I would do it).
CSS:
body {
background: url("");
}
or
.coolbackground {
background: url("");
}
You can set how it covers the page using:
background-size: ;
and
background-repeat: ;
Else if you dont want to do that, use a float, absolute positioning and z-index.

Trying to centre main banner with responsive text aligned left

I'm trying to centre my banner img that is right underneath the nav bar. I want to put text on it aligned left.
I've been able to do that BUT the text on the image is not responsive at all. How do I make it so that the text changes size when browser changes size? Also, I think my CSS is all over the place so if you have any advice on that it would be much appreciated!
Here is the markup:
.topimage img {
position: relative;
width: 100%;
padding-top: 10px;
}
li {
list-style-type: none;
}
h1 {
z-index: 100;
position: absolute;
color: #272727;
font-size: 45px;
font-weight: normal;
left: 650px;
top: 250px;
font-family: Helvetica Neue, arial, serif;
}
.maintitle p {
z-index: 100;
position: absolute;
color: #272727;
font-size: 17px;
font-weight: normal;
left: 650px;
top: 390px;
font-family: Helvetica Neue, arial, serif;
}
.maintitle ul {
list-style-type: none;
}
a {
text-decoration: none;
}
.maintitle li {
z-index: 100;
position: absolute;
color: #272727;
font-size: 15px;
font-weight: bold;
left: 650px;
top: 470px;
font-family: Helvetica Neue, arial, serif;
border-style: solid;
border-width: medium;
border-color: #272727;
border-radius: 6px;
padding: 6px;
}
a:visited {
text-decoration: none;
color: #272727;
}
.maintitle a:hover {
background-color: #6db618;
border-color: #6db618;
color: white;
}
.maintitle li:hover {
background-color: #6db618;
border-color: #6db618;
color: white;
}
<div class="topimage">
<img alt="plant" src="images/main.png" />
</div>
<div class="maintitle">
<h1>Marketing Communications & <br> Digital Design</h1>
<p>Marketing enthusiast who has also ventured into the digital design world. Combining <br> strategy with creativity is essential in my books!</p>
<ul>
<li class="aboutme"><a id="aboutmelink" href="#about">My Story</a></li>
</ul>
</div>
This is what I'm trying to achieve:
enter image description here
There are several issues here. Yet, the most important is your use of absolute positioning. It's completely unnecessary. All you really need to do is use a margin of auto to center the elements.
In this case, instead of positioning h1, p and ul separately, we can move them into a wrapper element.
If you want to shrink the actual font size according to screen width, use something along the lines of font-size: 10vw;
.wrap{
margin: 200px auto 0;
min-width: 320px;
max-width: 500px;
}
.topimage img {
position: relative;
width: 100%;
padding-top: 10px;
}
li {
list-style-type: none;
}
h1 {
z-index: 100;
color: #272727;
font-size: 45px;
font-weight: normal;
top: 250px;
font-family: Helvetica Neue, arial, serif;
}
.maintitle p {
z-index: 100;
color: #272727;
font-size: 17px;
font-weight: normal;
top: 390px;
font-family: Helvetica Neue, arial, serif;
}
.maintitle ul {
list-style-type: none;
padding: 0;
}
a {
text-decoration: none;
}
.maintitle li {
z-index: 100;
color: #272727;
font-size: 15px;
font-weight: bold;
font-family: Helvetica Neue, arial, serif;
border-style: solid;
border-width: medium;
border-color: #272727;
border-radius: 6px;
padding: 6px;
}
a:visited {
text-decoration: none;
color: #272727;
}
.maintitle a:hover {
background-color: #6db618;
border-color: #6db618;
color: white;
}
.maintitle li:hover {
background-color: #6db618;
border-color: #6db618;
color: white;
}
<div class="topimage">
<img alt="plant" src="images/main.png" />
</div>
<div class="maintitle">
<div class="wrap">
<h1>Marketing Communications & <br> Digital Design</h1>
<p>Marketing enthusiast who has also ventured into the digital design world. Combining <br> strategy with creativity is essential in my books!</p>
<ul>
<li class="aboutme"><a id="aboutmelink" href="#about">My Story</a></li>
</ul>
</div>
</div>
* {
box-sizing: border-box;
}
ul {
list-style-type: none;
padding: 0;
margin: 0;
}
a {
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #272727;
}
body {
font-family: Helvetica Neue, arial, serif;
}
.container {
max-width: 1024px;
width: 100%;
margin: 0 auto;
padding: 0 2%;
}
.topimage img {
position: relative;
width: 100%;
padding-top: 10px;
}
.maintitle h1 {
position: relative;
color: #272727;
font-size: 8vw;
}
.maintitle p {
z-index: 100;
position: relative;
color: #272727;
font-size: 4vw;
font-weight: normal;
}
.maintitle ul li {
z-index: 100;
position: relative;
color: #272727;
font-size: 15px;
font-weight: bold;
border-style: solid;
border-color: #272727;
border-radius: 6px;
padding: 6px;
}
.maintitle ul li:hover {
background-color: #6db618;
border-color: #6db618;
color: white;
}
<div class="container">
<div class="topimage">
<img alt="plant" src="images/main.png" />
</div>
<div class="maintitle">
<h1>Marketing Communications &<br>Digital Design</h1>
<p>Marketing enthusiast who has also ventured into the digital design world. Combining <br> strategy with creativity is essential in my books!</p>
<ul>
<li class="aboutme"><a id="aboutmelink" href="#about">My Story</a></li>
</ul>
</div>
</div>
I might have understand it wrong, but if you want to have a background image with text over it, you can use a background-image in CSS.
<div class="banner">
<div class="maintitle">
<h1>Marketing Communications & <br> Digital Design</h1>
<p>Marketing enthusiast who has also ventured into the digital design
world. Combining <br> strategy with creativity is essential in my books!</p>
<ul>
<li class="aboutme"><a id="aboutmelink" href="#about">My Story</a></li>
</ul>
</div>
</div>
And then the CSS
.banner {
background-image:url('images/main.jpg');
background-position:center;
position: relative;
width: 100%;
padding-top: 10px;
}
.maintitle {
width:100%;
blahblahblah
... }

How to put a hover effect to an after content is css?

I want to show a div named dot-menu when hover the after content of h1. I have tried the following code but did't work.
h1{
font-size: 20px;
font-weight: 400;
color: #3d3d3d;
margin-top:50px
}
h1:after{
content: "\22EE";
float: right;
font-size: 35px;
padding-right: 20px;
}
.dot-menu{
float: right;
background-color: #3d3d3d;
color: #FFFFFF;
font-size: 16px;
padding: 10px;
font-weight: 400;
font-family: "Montserrat Light", "Open Sans";
position: relative;
top:-10px;
opacity:0;
}
h1:after:hover .dot-menu{
opacity:1;
}
<h1>Henry Little</h1><h3 class="dot-menu">about</h3>
Your selector h1:after:hover .dot-menu is wrong.
This selector will look for .dot-menu element that is descendant of h1 but this is not the case. And 2nd you can't select another element on hover of a pseudo element.
You will need to change your code a bit. Consider the following HTML:
<h1>Henry Little
<span class="icon">&vellip;</span>
<span class="dot-menu">about</span>
</h1>
Make menu opener and menu both child elements of same parent. Then you can show menu on hover of icon with Sibling (+ ) selector.
h1 .icon:hover + .dot-menu{
opacity:1;
}
h1{
font-size: 20px;
font-weight: 400;
color: #3d3d3d;
margin-top:50px;
position: relative;
}
h1:after {
display: block;
clear: both;
content: '';
}
h1 .icon {
float: right;
font-size: 35px;
padding-right: 20px;
position: relative;
cursor: pointer;
}
.dot-menu {
float: right;
background-color: #3d3d3d;
color: #FFFFFF;
font-size: 16px;
padding: 10px;
font-weight: 400;
font-family: "Montserrat Light", "Open Sans";
position: relative;
top:30px;
opacity:0;
right: 0;
}
h1 .icon:hover + .dot-menu{
opacity:1;
}
<h1>Henry Little
<span class="icon">&vellip;</span>
<div class="dot-menu">about</div>
</h1>
See this just after making the .dot-menu a child of h1 it is working.
h1{
font-size: 20px;
font-weight: 400;
color: #3d3d3d;
margin-top:50px
}
h1:after{
content: "\22EE";
float: right;
font-size: 35px;
padding-right: 20px;
}
.dot-menu{
float: right;
background-color: #3d3d3d;
color: #FFFFFF;
font-size: 16px;
padding: 10px;
font-weight: 400;
font-family: "Montserrat Light", "Open Sans";
position: relative;
top:-10px;
opacity:0;
}
h1:hover .dot-menu{
opacity:1;
}
<h1>Henry Little<span class="dot-menu">about</span></h1>

Changing children elements when hovering the parent

I have my a container wich has a background image a title and button.
I want to hover on the container and change the title text-align to left, same as the button and display some information.
My question is if this is possible using only CSS3?
Here are the images of what I want to do:
(The name doesn't matter it's just an example)
Here's my HTML:
<article class="destination__item destination__item--jacksonhole">
<h2 class="destination__item--name">Jackson Hole</h2>
Ver más
</article>
My CSS:
.destination__item {
padding: 16em 0;
text-align: center;
}
.destination__item--canyons {
background: url(../images/destinos/dest1.jpg) no-repeat;
background-size: cover;
}
.destination__item--name {
color: white;
font-size: 36px;
font-weight: 700;
padding-bottom: .5em;
text-transform: uppercase;
}
.destination__item--btn {
background-color: $color__red--primary;
color: white;
font-weight: 400;
font-size: 14px;
padding: 1em 2.5em;
transition: all .5s ease;
text-transform: uppercase;
&:hover {
text-decoration: none;
background-color: $color__red--dark;
color: white;
}
}
To be honest, I have no idea where to start on the hover state, hope you guys can guide me a little bit.
Sure you can, just add the following to your CSS:
.destination__item:hover .destination__item--name,
.destination__item:hover .destination__item--btn {
display:block;
text-align:left;
}
here is a working example
You can change other div on hover of other example:
.destination__item--jacksonhole:hover + destination__item--name{
text-align: left;
}
To change Content check this Fiddle , text on link is changed.
html:
<article class="destination__item destination__item--jacksonhole">
<h2 class="destination__item--name">Jackson Hole</h2>
<span>Ver más<span>
</article>
CSS:
.destination__item {
padding: 16em 0;
text-align: center;
}
.destination__item--canyons {
background: url(../images/destinos/dest1.jpg) no-repeat;
background-size: cover;
}
.destination__item--name {
color:black;
font-size: 36px;
font-weight: 700;
padding-bottom: .5em;
text-transform: uppercase;
}
.destination__item--btn {
background-color: $color__red--primary;
color: black;
font-weight: 400;
font-size: 14px;
padding: 1em 2.5em;
transition: all .5s ease;
text-transform: uppercase;
&:hover {
text-decoration: none;
background-color: $color__red--dark;
color: white;
}
}
.destination__item:hover .destination__item--name,
.destination__item:hover .destination__item--btn {
display:block;
text-align:left;
}
.destination__item:hover .destination__item--btn span{
display:none;
}
.destination__item:hover .destination__item--btn:after{
content:"New Content"
}