I can't position the button inside my image - html

Basically, I want to position the button inside the image, and make it stay in its position when I switch to mobile mode or change the size of the window.
This is what I want it to look like:
https://prnt.sc/mij0s6
.img-wrapper {
position: relative;
}
.img-responsive {
max-width: 100%;
height: auto;
margin-top: 180px;
margin-left: 360px;
}
a.btn {
display: inline-block;
padding: 0.2em 1.45em;
margin: 0.1em;
border: 0.15em solid #CCCCCC;
box-sizing: border-box;
text-decoration: none;
font-family: 'Segoe UI', 'Roboto', sans-serif;
font-weight: 400;
color: #000000;
background-color: #ffc966;
text-align: center;
position: relative;
}
a.btn:hover {
border-color: #7a7a7a;
}
a.btn:active {
background-color: #999999;
}
#media all and (max-width:30em) {
a.btn {
display: block;
margin: 0.2em auto;
}
}
<h1>De zakelijke VR/AR hardware leverancier van Benelux</h1>
<div class="img-wrapper">
<img class="img-responsive" src="vrgt.png">
</div>
Meer Info

(I posted prematurely.. pressed the post button by accident)... You had no css for img or H1.. I added some, I also added a max-width for image in both the main css and the reponsive (media) css.
The code could do with a bit of tweaking but I'd advise you have a look and adapt it to your needs. It's closer to what you want I think!
EDIT: I'd advise you add a few more media queries to accommodate different screen resolutions as absolute positioning can be a bit of a nightmare on differently-sized devices. Screenfly is a good tool for testing how your code looks on multiple sizes. Using large margin-bottoms measured in pixels (such as 360px) may result in your button not even displaying on a screen, so try to use vertical height (vh) or percentages when measuring height especially. The [calc function] is also very useful 2. Useful css for centering are margin : 0 auto or text-align:center;
Best of luck, and hope this helps
h1 {
text-align: center;
font-weight: bold;
font-size: 1.8em;
}
img {
max-width: 70%;
max-height: 80%;
margin: 10px 12%;
}
img-wrapper {
display: inline-block;
position: relative;
}
nav {
margin: 0 auto;
}
nav ul {
list-style-type: none;
background-color: lightgrey;
width:100%;
}
nav ul li {
min-width:18%;
display: inline-block;
text-align: center;
padding: 10px;
margin:0 auto;
}
ul li a {
padding: 10px 15px;
text-decoration: none;
}
/*.img-responsive {
/* margin-top: 100px;
margin-left: 360px;
}*/
a.btn {
display: inline-block;
padding: 0.2em 1.45em;
margin: 0.1em;
border: 0.15em solid #CCCCCC;
box-sizing: border-box;
text-decoration: none;
font-family: 'Segoe UI', 'Roboto', sans-serif;
font-weight: 400;
color: #000000;
background-color: #ffc966;
text-align: center;
position: relative;
}
a.btn:hover {
border-color: #7a7a7a;
}
a.btn:active {
background-color: #999999;
}
#media all and (max-width:30em) {
img {
max-width: 400px;
}
a.btn {
display: block;
margin: 0.2em auto;
}
}
<h1>De zakelijke VR/AR hardware leverancier van Benelux</h1>
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Gallery</li>
<li>Contact</li>
</ul>
</nav>
<div class="img-wrapper">
<img class="img-responsive" src="https://gilsig.ca/wp-content/uploads/2015/10/12391435_192385974441516_971157875868647436_n.jpg-North-Shore-Mountains-Dec-2015.jpg">
</div>
Meer Info

Button's position should be absolute relative to it's first parent element.
a.btn
{
position: absolute;
top: 50%;
left: 50%;
}
.img-wrapper {
position: relative;
}
a.btn {
position: absolute;
top: 50%;
left: 50%;
padding: 0.2em 1.45em;
margin: 0.1em;
border: 0.15em solid #CCCCCC;
box-sizing: border-box;
text-decoration: none;
font-family: 'Segoe UI', 'Roboto', sans-serif;
font-weight: 400;
color: #000000;
background-color: #ffc966;
text-align: center;
}
a.btn:hover {
border-color: #7a7a7a;
}
a.btn:active {
background-color: #999999;
}
<div class="img-wrapper">
<img src="https://www.w3schools.com/css/img_5terre_wide.jpg" alt="Cinque Terre" width="1000" height="300">
</div>
Meer Info

Related

text stuckt to the header? [duplicate]

This question already has answers here:
CSS margin terror; Margin adds space outside parent element [duplicate]
(7 answers)
Closed 4 years ago.
I’m trying to move my text to the middle of my header on the image but as soon as I move it the whole header follows. Could someone try to help me solve this issue? As you see I’m trying to make it using margin-top but when I implement this the header follows. I have closed all the divs that affects the image.
html, body {
margin: 0;
padding: 0;
text-align: center;
width: 100%;
}
body {
font-family: 'Josefin Sans', sans-serif;
text-align: center;
}
header {
width: 100%;
height: 400px;
background: url(/assets/image/tjanst.jpg) no-repeat 50% 50%;
background-size: cover;
}
.content {
width: 94%;
margin: 4em auto;
font-size: 20px;
line-height: 30px;
text-align: justify;
}
.logo {
line-height: 60px;
position: fixed;
float: left;
margin: 16px 46px;
color: #fff;
font-weight: bold;
font-size: 20px;
letter-spacing: 2px;
}
nav {
position: fixed;
width: 100%;
line-height: 60px;
z-index: 10;
}
nav ul {
line-height: 60px;
list-style: none;
background: rgba(0, 0, 0, 0);
overflow: hidden;
color: #fff;
text-align: right;
margin: 0;
padding-right: 40px;
transition: 1s;
}
nav.black ul {
background: #000;
padding: 16px 40px;
}
nav ul li {
display: inline-block;
padding: 16px 40px;
}
.move-down h3{
margin-top: 200px;
max-width: 400px;
}
nav ul li a {
font-family: 'Josefin Sans', sans-serif;
font-size: 14px;
color: #fff;
font-weight: 600;
text-transform: uppercase;
text-decoration: none;
}
a {
color: #fff;
text-decoration: none;
}
.menu-icon {
line-height: 60px;
width: 100%;
background: #000;
text-align: right;
box-sizing: border-box;
padding: 15px 24px;
cursor: pointer;
color: #fff;
display: none;
}
#media(max-width: 786px) {
.logo {
position: fixed;
top: 0;
margin-top: 16px;
}
nav ul {
max-height: 20px;
background: #000;
}
nav.black ul {
background: #000;
}
.showing {
max-height: 34em;
}
nav ul li {
box-sizing: border-box;
width: 100%;
padding: 24px;
text-align: center;
}
.menu-icon {
display: block;
}
}
<header>
<nav>
<div class="menu-icon">
<i class="fa fa-bars fa-2x"></i>
</div>
<div class="logo wow tada">
</div>
<div class="menu">
<ul>
<li>START</li>
<li>TJÄNSTER</li>
<li>OM OSS</li>
<li>KONTAKT</li>
</ul>
</div>
</nav>
<div class="move-down wow fadeInUp"><h3> VILL GÖRA KUNDEN NÖJD</h3>
<h3> tel: 070719763 </h3></div>
</header>
how it looks now
https://i.stack.imgur.com/vOQGa.png
Well remove 'margin-top: 200px;' in the '.move-down h3' and add 'padding: 200px 0px 0px 0px;' or 'padding-top: 200px;'
Yes, Simple solution is.
Add this CSS
h3{
maring:0;
}
Hope this helps.
Instead of adding margin-top add top value to relatively positioned element.
.move-down h3 {
max-width: 400px;
position: relative;
top: 205px;
}
https://jsfiddle.net/6uedrb89/12/

Main Menu does not show on mobile (portrait)

So I am still learning about css / html for Mobile devices. I have a site that when on desktop looks good. When you pull it up on mobile device the menu is gone. If you go into landscaping mode the menu will appear. Any help on why?
menu code.
<div class="menu_block ">
<div class="container_12">
<div class="grid_12">
<nav class="horizontal-nav full-width horizontalNav-notprocessed">
<ul class="sf-menu">
<li <img src="images/logo.png" alt="wake up rentals"></li>
<li class="current">Home</li>
<li>Rentals</li>
<li>Lakes</li>
<li>Rent Now</li>
<li>FAQ's</li>
<li>Login</li>
<li>Contact Us</li>
</ul>
</nav>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
</div>
Menu Block CSS
.menu_block {
z-index: 999;
position: relative;
background: url(../images/menu_bg.png) 0 0 repeat-x #d8d8db;
padding: 12px 0 11px;
}
.menu_block nav {
position: relative;
font-family: 'Marvel', sans-serif;
}
nav>.sf-menu {
z-index: 990;
text-align: center;
position: relative;
}
nav{ position:relative;padding: 0px 0 0 0;}
.sf-menu ul {position:absolute;top:-999px; display:none;/* left offset of submenus need to match (see below) */}
.sf-menu>li {
display: block;
position: relative;
display: inline-block;
font-size: 24px;
line-height: 20px;
}
.sf-menu>li>ul>li {
float: none;
position: static;
}
.sf-menu>li+li {
margin-left: 27px;
}
.sf-menu>li>a{
font-weight: bold;
text-align: center;
color: #313030;
display: block;
padding: 9px 25px;
}
.sf-menu>li.sfHover>a, .sf-menu>li.current>a, .sf-menu>li>a:hover {
color: #000;
background-color: blue;}
.sf-menu>li>a.sf-with-ul:after {
position: absolute;
content: '';
left: 50%;
margin-left: -3px;
width: 5px;
background: url(../images/arrows.png) 0 0 no-repeat;
height: 4px;
bottom: 10px;
pointer-events: none;
z-index: 999;
display: block;
}
.sf-menu>li>ul>li>a.sf-with-ul:after {
content: '';
font-family: 'FontAwesome';
position: absolute;
width: 5px;
font-size: 15px;
line-height: 13px;
font-weight: normal;
right: -15px;
color: #fff;
bottom: 3px;
pointer-events: none;
z-index: 999;
}
Mobile Menu Block
#media only screen and (max-width: 767px) {
.menu_block {
float: none !important;
padding: 20px 10px 25px !important;
clear: both;
min-height: 0px;
border: none;
}
.menu_block nav {
border: none !important;
float:none !important;
font:12px/15px Arial, Helvetica, sans-serif;
text-transform:uppercase;
color:#927c67;
margin: 0 auto;
padding-left: 0 !important;
}
header nav ul {
border: none;
}
.sf-menu {
display:none !important;
float: none;
}
#mm0 {
font:12px/15px Arial, Helvetica, sans-serif;
color:#202020;
width:100%;
margin: 0 auto;
float: none;
outline: none;
border:2px solid #fff;
}
}
I am not sure if you need more like the container_12 and grid_12 code. There was a lot of lines of code in them. And did not want to add a lot of not needed info . If you think they are needed I can post them.
Container_12 / some grid_12 CSS
https://pastebin.com/tup8Psis
Grid_12 CSS
https://pastebin.com/qxAswhVc
posted links to the css figured it was easier to read there...
You have your UL set to "Display None" at max-width 767px.
#media only screen and (max-width: 767px)
.sf-menu {
display: none !important;
/* float: none; */
That is why you do not have a menu, remove the "Display None" from your UL.

Setting text to stay above another element at all times

I have one regular box and I wish the text to float above it and resize the text's font size appropriately.
This is what I have done: https://jsfiddle.net/a87uo3t2/
#import url('https://fonts.googleapis.com/css?family=Share+Tech+Mono');
body {
margin: 0 auto;
overflow: hidden;
}
#content {
width: 100%;
height: 2527px;
background-image: url('../images/wallpaper.jpg');
}
#menu-container,
#button-container {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 30%;
height: 40%;
border: 1px line #ccc;
background-color: #ffffff;
background-image: url('../images/brick-wall.png');
box-shadow: 0 0 3em #ccc;
}
#button-container {
border: none;
box-shadow: none;
}
.button-sub-container {
display: inline-flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
h1 {
position: relative;
bottom: 120px;
left: 6px;
text-align: center;
font-family: 'Share Tech Mono', monospace;
font-size: 5vw;
text-transform: uppercase;
text-decoration: none;
letter-spacing: 15px;
}
/*BUTTONS*/
.main-button {
text-decoration: none;
font-family: 'Share Tech Mono', monospace;
font-size: 35px;
margin: 15px;
color: #000;
letter-spacing: 5px;
text-transform: uppercase;
transition: letter-spacing 0.5s, color 0.8s;
}
.main-button:hover {
letter-spacing: 15px;
color: red;
}
.main-button:active {
letter-spacing: 2px;
color: blue;
}
<div id="content">
<div id="menu-container">
<h1>welcome</h1>
<div id="button-container" class="button-sub-container">
<a class="main-button" href="about.html">about</a>
<a class="main-button" href="projects.html">projects</a>
<a class="main-button" href="contact.html">contact</a>
</div>
</div>
As you can see I have tried setting it on top by positioning it relatively yet this means upon resizing it shifts, I can fix this by using vw as font size to a point, since if one would have a very wide monitor, it would go over my small menu-container.
Side-Note: don't bring attention to the buttons-text breaking out of the box, I have a a media-key to fix that
A solution with flexbox
and changing only the font-size of the box
#import url('https://fonts.googleapis.com/css?family=Share+Tech+Mono');
html,
body {
height: 100%;
}
body {
margin: 0;
display: flex;
justify-content: center;
align-items: center;
}
.box {
font-family: 'Share Tech Mono', monospace;
max-width: 50%;
text-align: center;
/* Change to your needs */
font-size: 20px;
}
.box h1 {
text-transform: uppercase;
margin-top: 0;
}
.box ul {
list-style: none;
margin: 0;
padding: 15px;
border: 1px line #ccc;
background-color: #ffffff;
background-image: url('../images/brick-wall.png');
box-shadow: 0 0 3em #ccc;
}
.box a {
text-decoration: none;
color: #000;
text-transform: uppercase;
white-space: nowrap;
transition: letter-spacing 0.5s, color 0.8s;
}
.box a:hover {
letter-spacing: 3px;
color: red;
}
/* Change to your needs */
#media screen and (min-width: 600px) {
.box {
font-size: 20px;
}
}
/* Change to your needs */
#media screen and (min-width: 1200px) {
.box {
font-size: 30px;
}
}
<div class="box">
<h1>Heading</h1>
<!-- It's a list -->
<ul>
<li>Site 1</li>
<li>Site 2</li>
<li>Site 3</li>
</ul>
</div>

Why won't the z-index on my elements work?

I have my code set up so I have the hero image at the bottom and the overlay on top with the text and button in overlay. I also have the navigation bar with a z-index but for some reason the button for my resume in overlay isn't working.
HTML
<div id="header">
<a href="index.html"><div id="leftHeader">
<img src="assets/logo2.jpg" alt="Logo" style="width:65px;height:65px">
<h1>Amanda Farrington</h1>
</div>
<div id="nav">
<ul>
<li>About</li>
<li>Work</li>
<li>Contact</li>
<li>Notes</li>
</ul>
</div>
</div>
<div id="hero">
<div id="heroImage">
<img src="assets/trees.jpg" alt="trees" style="width:100%;height:10%">
</div>
<div id="overlay">
<h2>Amanda Farrington</h2>
<h3>Graphic Artist | Web Designer</h3>
View Resume
</div>
</div>
CSS
#header {
color: #D7DADB;
font-family: 'Roboto', sans-serif;
font-weight: 300;
font-size : 15px;
text-align: left;
width: 100%;
padding-left: 3em;
position: relative;
height: 15%;
box-sizing: border-box;
padding-top: 1em;
}
#header img
{
float: left;
padding-left: 3em;
}
h1{
width: 9em;
float: left;
padding-left: 0.5em;
color: #45CCCC;
padding-bottom: 1px;
}
#nav {
width: 50%;
margin:0;
padding:0;
text-align: right;
color: red;
font-size:20px;
float: right;
padding-right: 2em;
z-index: 99;
}
#nav ul {
padding: 1px;
}
#nav li {
display: inline;
padding: 38px;
}
#nav li a {
color: #2C3E50;
text-decoration: none;
}
#nav li a:hover {
color: #45CCCC;
}
/*----------hero image styles-------------*/
#hero{
padding-top: 25em;
width: 100%;
height: 30em;
position: relative;
z-index: -1;
}
#heroImage
{
top: 9%;
width: 100%;
z-index: 1;
position: absolute;
}
#overlay{
width: 34em;
top: -15%;
margin-left: 30%;
z-index: 2;
position: relative;
clear: left;
}
h2{
width: 100%;
position: relative;
font-family: 'Roboto', sans-serif;
font-weight: 300;
font-size: 60px;
float: center;
color: white;
opacity: 1.0;
text-shadow: 2px 2px 3px #000000;
text-align: center;
}
h3{
width: 100%;
position: relative;
font-family: 'Roboto', sans-serif;
font-weight: 300;
font-size: 30px;
color: #e5e5e5;
opacity: 1.0;
text-shadow: 2px 3px 2px #000000;
text-align: center;
}
a.down{
z-index: 100;
font-family: 'Roboto', sans-serif;
font-weight: 400;
text-decoration: none;
color: #181b1e;
background: #45CCCC;
position: relative;
padding: 0.6em 0.2em;
font-size: 1.2em;
-webkit-border-radius: 6px;
width: 30%;
position: relative;
display: block;
margin-left: auto;
margin-right: auto;
text-align: center;
}
a.down:hover{
text-decoration: underline;
color: white;
}
Because z-index works only on elements which are NOT set asposition: static. Bear in mind that every element is set as default to position:static.
Try set to position:absolute; or relative your element.
Also all other types of positioning, like position:fixed, position:sticky.
So I've taken a look at your code and the reason your button doesn’t work is because the div with the ID of #hero (which contains the button) is below the body because it has a z-index of -1.
Set the z-index for #hero to 0 or higher and the button will work.
#hero {
padding-top: 25em;
width: 100%;
height: 30em;
position: relative;
z-index: 0;
}
Check out this JS Fiddle I've created for you:
https://jsfiddle.net/8fqwr6ca/
Edit: Oh, and I forgot to mention–since you want the image to be below, set the #hero 's z-index to 1, set #heroImage to 0, and overlay to 2. That should do the trick (if what I think you want is correct).

Page Scrolls down when I click on Link

I'm trying to build a page that has a lightbox - but I don't want any javascript on it.
I found a tutorial on how to do this, but when I started to add it, I noticed that everytime I click on the link, it scrolls down ever so slightly, hiding the top border of the page.
How can I stop this? Because it ruins the look of the site
HTML
<div id="container">
<div id="header-row">
<div class="logo span4">
<h1>Title <span>.</span></h1>
</div>
</div>
<div id="content">
<p></p>
</div>
</div>
<ul id="lightboxes">
<li id="close"></li>
<li id="lightbox-form">
<div class="box">
<h3>About</h3>
<p>
</p>
x
</div>
<!--[if IE]>
<div class="ie-bg"></div>
<![endif]-->
</li>
</ul>
CSS
html, body {
background: #f8f8f8 url(../img/pattern.jpg);
height: 100%;
width: 100%;
margin: 0;
padding: 0;
border-top: 2px solid #e75967;}
strong { font-weight: 700; }
a:hover { text-decoration: none; }
::-moz-selection { background: #e75967; color: #fff; text-shadow: none; }
::selection { background: #e75967; color: #fff; text-shadow: none; }
.logo h1 {
margin-top: 7px;
padding-left: 50px;
font-family: 'Lobster', cursive;
font-size: 38px;
font-weight: 400;
color: #555;
}
.logo h1 span { color: #e75967; }
#container {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
overflow: auto;}
/* ---------------------------------------------------------- */
/* LIGHTBOXES
/* ---------------------------------------------------------- */
#lightboxes {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
list-style-type: none;
text-align: left;
overflow: hidden;}
#lightboxes li {
width: 100%;
height: 9999px;
position: relative;
background: rgba(0,0,0,.5);}
#lightboxes .box {
position: absolute;
width: 400px;
height: 400px;
left: 50%;
top: 50px;
border: 10px solid #999;
margin-left: -230px;
background-color: #fff;
padding: 20px;}
#lightboxes h3 {
font-weight: normal;
font-size: 1.8461em;
margin: 0 0 0.4583em 0;}
#lightboxes a.close {
position: absolute;
top: 20px;
right: 20px;
display: block;
width: 20px;
line-height: 20px;
text-align: center;
background-color: #ddd;
text-decoration: none;
font-weight: bold;
color: #999;
font-size: 1.2em;}
#lightboxes a.close:hover {
background-color: #999;
color: #fff;}
#lightboxes #close {
background-color: transparent;
z-index: -1;}
Here is a JSFiddle
Sorry for all the code - but it wont let me post it without it
x
using #close in a link like this makes your browser jump to that ID
Haven't pinpointed exactly on which elements it makes a difference, but you can simply add this your your CSS:
*
{
box-sizing: border-box;
-moz-box-sizing: border-box;
}
And it won't jump any more.