I am really breaking my head here. When I look at the following bootstrap 3 card on my mobile, I can see that I can move the webpage to the left and right. I therefore conclude there is something wrong in my CSS.
I have been looking for hours now, but cannot understand where the error is. Can somebody help me out figure out this problem?
The demosite is here
I cut a lot of html away there is not relevant for the question. Therefore there is some css classes that is not used in the following html.
body {
background-color: #f5f5f5;
}
.index-content a:hover {
color: black;
text-decoration: none;
}
.index-content .row {
margin-top: 20px;
}
.index-content a {
color: black;
}
.index-content .card {
background-color: #FFFFFF;
padding: 0;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.14), 0 1px 10px 0 rgba(0, 0, 0, 0.12), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
}
.index-content .card:hover {
box-shadow: 0 16px 24px 2px rgba(0, 0, 0, 0.14), 0 6px 30px 5px rgba(0, 0, 0, 0.12), 0 8px 10px -5px rgba(0, 0, 0, 0.3);
color: black;
}
.index-content .card img {
width: 100%;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
/*height: 400px;*/
}
.index-content .card h4 {
margin: 20px;
}
.index-content .card p {
margin: 20px;
opacity: 0.65;
}
/* Set width between grid elements */
.small-padding.top {
padding-top:10px;
}
.small-padding.bottom {
padding-bottom:10px;
}
.small-padding.left {
padding-left:5px;
}
.small-padding.right {
padding-right:5px;
}
.margin_bottom {
margin-bottom: 10px;
}
.row [class*="col-"] {
padding-right: 5px;
padding-left: 5px;
}
.row {
margin-left: -5px;
margin-right: -5px;
}
.img-responsive {
height: 100%;
}
/* Position of buttons in a single grid element */
.inner-wrapper {
text-align: center;
background: none;
}
.centered {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.bottom-right {
position: absolute;
bottom: 8px;
right: 16px;
}
.bottom-left {
position: absolute;
bottom: 8px;
left: 16px;
}
.header-textbox-bottom-left {
position: absolute;
bottom: 8px;
left: 16px;
}
.card-content {
display: flex;
padding: 10px 10px;
justify-content: space-between;
align-items: flex-end;
}
.card-content__info {
display: flex;
flex-direction: column;
left: 3em;
position: relative;
}
.card-content__info > h4 {
padding: 0 !important;
margin: 5px 0 !important;
text-transform: uppercase;
}
.sub-headline {
color:#00a9ff !important;
text-transform: uppercase;
font-size:20px;"
}
/* Set full width on columns */
#media (max-width: 768px) {
.img-responsive {
width: 100%;
}
.index-content .card img {
height: 100%
}
.card-content__info {
flex-direction: column;
left: 0;
}
.card-content {
flex-direction: column;
left: 20px;
position: relative;
align-items: inherit;
}
/* Position button on banner with textbox */
.header-textbox-bottom-left {
position: static;
bottom: 8px;
left: 16px;
text-align: left;
padding-left: 20px;
padding-bottom: 5px;
}
.btn-custom {
position: static;
width: fit-content;
margin-top: 15px;
}
.btn-success {
width: fit-content;
}
}
#media (max-width: 991px) {
h3 {
font-size: 1.2em;
}
}
/* GRID ELEMENTS MEDIA QUERIES */
#media (min-width: 768px) {
.card {
position: relative;
}
.card-content {
position: absolute;
bottom: 0;
width: 100%;
background: rgba(0, 0, 0, 0.5);
}
.card-content h4,
.card-content p,
.card-content span {
color: white;
width: 100%;
float: left;
margin: 0 0 5px;
}
.card-content a {
float: right;
}
.index-content .card h4,
.index-content .card p {
padding: 15px 20px;
margin: 0;
}
.index-content .card p {
padding: 0 20px 15px;
margin: 0;
}
.card-content-textbox {
position: absolute;
top: 0;
left: 0;
background: rgba(255, 255, 255, 0.7);
/*right: 0;*//* top position on right*/
margin: 15px;
max-width: 300px;
height: 91%
}
}
<div class="container">
<!-- Partnerværksteder -->
<div class="row">
<div class="col-sm-12 small-padding right bottom">
<div class="index-content">
<div class="card">
<img src="https://s-media-cache-ak0.pinimg.com/originals/87/bf/cf/87bfcfb36780c0fec472d8d301be7a1c.jpg"></img>
<div class="card-content">
<div class="card-content__info">
<h4>Højt serviceniveau og kvalitet</h4>
<span class="sub-headline">Find nærmeste mercedes partnerværksted</span>
</div>
<button type="button" class="btn btn-success bottom-right btn-custom">Find et værksted</button>
</div>
</div>
</div>
</div>
</div>
</div>
Follow an image that show the div broken your layout.
You will need to change this parts of your css.
// Remove all comments styles
.card-content {
display: flex;
padding: 10px 30px;
justify-content: space-between;
/* align-items: flex-end; */
}
#media (max-width: 768px) {
.card-content {
flex-direction: column;
/* left: 20px; */
/* position: relative; */
/* align-items: inherit; */
/* max-width: 100%; */
/* width: 100%; */
}
}
Related
When I resize the page the searchbox starts resizing after the padding of the parent if zero. I want to resize the div with class-"searchbox", with resizing the page not after the parent's padding is off. Here is the code I'll be glad if you correct me anywhere.
.site-wrapper {
max-width: 86.5rem;
min-height: 28rem;
padding: 0 4.3rem;
margin: 0 auto;
overflow: hidden;
}
.navbar {
display: flex;
justify-content: end;
padding-top: 2.7rem;
}
#hamburger-button {
position: relative;
width: 32px;
height: 32px;
border-radius: 4px;
cursor: pointer;
}
#hamburger-button:hover {
background-color: #0000001f;
}
#hamburger {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border: none;
background-color: transparent;
background-image: url(/assets/menuicon.svg);
background-repeat: no-repeat;
background-size: contain;
padding: 9.2px;
margin: 0 auto;
cursor: pointer;
}
.header-content {
margin: 0 auto;
}
.header-content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.header-content-logo {
margin-top: 5rem;
margin-bottom: 2.3rem;
}
.header-content-logo svg {
width: 12.6rem;
}
.searchbox {
display: flex;
align-items: center;
border-radius: 6px;
width: 100%;
max-width: 38.7rem;
height: 2.7rem;
background-color: #fff;
box-shadow: 0px 2px 6px 1px rgba(0, 0, 0, 0.1);
overflow: hidden;
}
.searchbox:hover {
box-shadow: 0px 6px 20px 6px rgba(0, 0, 0, 0.1);
}
.searchbox input {
width: 92%;
border: none;
background-color: transparent;
font-size: 11.8pt;
font-family: inherit;
padding-left: 1rem;
}
.searchbox input:focus {
outline: none;
}
<div class="site-wrapper">
<div class="navbar">
<div id="hamburger-button">
<button id="hamburger"></button>
</div>
</div>
<div class="header-content">
<div class="header-content-logo">
<svg>
</div>
<div class="searchbox">
<input type="text" placeholder="Search without being tracked">
</div>
</div>
</div>
I have tried putting margin and even making another div before it and putting padding but seems that it didn't make it work. I am out of options.
This question already has answers here:
How do you get the footer to stay at the bottom of a Web page?
(32 answers)
Closed 3 years ago.
I am having an issue with my homepage - I do not have enough content for a fullpage and I am trying to set the position of this section above the footer at the bottom.
I had success with using positon: fixed; and bottom: 50px; to sit above my footer, however when I was opening the navigation on an ipad, the navigation would disappear behind the section.
I'm not sure how to tackle the problem, I was attempting to use vertical-align: bottom; but could not get it to work.
My CSS:
section.hero {
max-height: 400px;
text-align: center;
img.hero-responsive {
width: 100%;
height: 100px;
}
h2 {
width: 90%;
margin: 0 auto;
font-size: 1.5em;
top: -90px;
font-weight: 800;
position: relative;
}
h3 {
position: relative;
top: -60px;
font-weight: 800;
}
}
section.info {
background-color: #464646;
height: auto;
position: relative;
top: -50px;
width: 100vw;
padding: 0px;
left: -5px;
text-align: center;
color: white;
padding-bottom: 50px;
.row {
margin: 0px !important;
padding: 0px !important;
.col-lg-3 {
border-top: 2px solid rgba(160, 160, 160, 0.8);
margin-top: 5px !important;
padding: 0px !important;
i {
font-size: 40px;
padding: 10px;
margin: 25px !important;
padding: 0px !important;
}
i.laravel { color: #f05340; }
i.wordpress { color: #21759b; }
i.sass { color: #cd6799; }
img {
width: 50px;
height: 40px;
margin: 10px !important;
padding: 0px !important;
}
h2 {
margin: 0px !important;
padding: 0px !important;
}
p {
width: 95%;
margin: 0px auto 0px auto !important;
padding: 0px 0px 10px 0px !important;
}
}
}
}
#media only screen and (min-width: 768px) {
section.hero {
img.hero-responsive {
width: 450px;
}
h2 {
width: 400px;
top: -80px;
}
}
section.info {
top: auto;
position: absolute;
}
}
#media only screen and (min-width: 1000px) {
section.hero {
h3 {
top: -30px;
}
}
section.info {
min-height: 500px;
position: unset;
margin-left: -5px;
}
}
codepen: https://codepen.io/aparker611/pen/bGbQdqg
codep: https://codepen.io/aparker611/pen/bGbQdqg
<body class="Site">
<header>…</header>
<main class="Site-content">…</main>
<footer>…</footer>
</body>
.Site {
display: flex;
min-height: 100vh;
flex-direction: column;
}
.Site-content {
flex: 1;
}
You can try using flexbox. if you share a codepen or a full example it will more easy to help you
<body class="Site">
<header>…</header>
<main class="Site-content">…</main>
<footer>…</footer>
</body>
.Site {
display: flex;
min-height: 100vh;
flex-direction: column;
}
.Site-content {
flex: 1;
}
https://codepen.io/centrodph/pen/gOYQpBL
On my banner I have a picture with a lion and a textbox. I have positioned the button on the banner how I want it, but when I resize the screen to < 768 px the button is not staying inside the card. I do not understand why.
How can I make the button stay inside the card with a viewport < 768px, and without affecting all the other buttons?
See the demosite here
I have cutted away code there is not relevant for the question:
body {
background-color: #f5f5f5;
}
.index-content a:hover {
color: black;
text-decoration: none;
}
.index-content .row {
margin-top: 20px;
}
.index-content a {
color: black;
}
.index-content .card {
background-color: #FFFFFF;
padding: 0;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.14), 0 1px 10px 0 rgba(0, 0, 0, 0.12), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
}
.index-content .card:hover {
box-shadow: 0 16px 24px 2px rgba(0, 0, 0, 0.14), 0 6px 30px 5px rgba(0, 0, 0, 0.12), 0 8px 10px -5px rgba(0, 0, 0, 0.3);
color: black;
}
.index-content .card img {
width: 100%;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
height: 400px;
}
.index-content .card h4 {
margin: 20px;
}
.index-content .card p {
margin: 20px;
opacity: 0.65;
}
/* Set width between grid elements */
.small-padding.top {
padding-top:10px;
}
.small-padding.bottom {
padding-bottom:10px;
}
.small-padding.left {
padding-left:5px;
}
.small-padding.right {
padding-right:5px;
}
.margin_bottom {
margin-bottom: 10px;
}
.row [class*="col-"] {
padding-right: 5px;
padding-left: 5px;
}
.row {
margin-left: -5px;
margin-right: -5px;
}
.img-responsive {
height: 100%;
}
/* Position of buttons in a single grid element */
.inner-wrapper {
text-align: center;
background: none;
}
.centered {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.bottom-right {
position: absolute;
bottom: 8px;
right: 16px;
}
.bottom-left {
position: absolute;
bottom: 8px;
left: 16px;
}
.card-content {
display: flex;
padding: 30px 0px;
justify-content: space-between;
align-items: flex-end;
}
.card-content__info {
display: flex;
flex-direction: column;
left: 3em;
position: relative;
/* text-transform: uppercase; */
}
.card-content__info > h4 {
padding: 0 !important;
margin: 5px 0 !important;
}
/* Set full width on columns */
#media (max-width: 768px) {
.img-responsive {
width: 100%;
}
.index-content .card img {
height: 100%
}
.card-content__info {
flex-direction: column;
left: 0;
}
.card-content {
flex-direction: column;
left: 40px;
position: relative;
align-items: inherit;
}
}
#media (max-width: 991px) {
h3 {
font-size: 1.2em;
}
}
/* GRID ELEMENTS MEDIA QUERIES */
#media (min-width: 768px) {
.card {
position: relative;
}
.card-content {
position: absolute;
bottom: 0;
width: 100%;
background: rgba(0, 0, 0, 0.5);
}
.card-content h4,
.card-content p,
.card-content span {
color: white;
width: 100%;
float: left;
margin: 0 0 5px;
}
.card-content a {
float: right;
}
.index-content .card h4,
.index-content .card p {
padding: 15px 20px;
margin: 0;
}
.index-content .card p {
padding: 0 20px 15px;
margin: 0;
}
.card-content-textbox {
position: absolute;
top: 0;
left: 0;
background: rgba(255, 255, 255, 0.7);
/*right: 0;*//* top position on right*/
margin: 15px;
max-width: 300px;
height: 91%
}
}
<div class="row">
<a href="#">
<div class="col-sm-12 small-padding top bottom">
<div class="index-content">
<div class="card">
<img src="https://www.sardiustours.com/wp-content/uploads/2016/09/lion-1118467_1920-Copy.jpg"></img>
<div class="card-content-textbox flexbox-column">
<h4>BMW & HEADLINE 2018</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<div class="inner-wrapper bottom-left">
<button class="btn btn-success">Read More</button>
</div>
</div>
</div>
</div>
</div>
</a>
</div>
The buttons parent wrapping div .bottom-left is absolutely positioned. You will need to create a responsive style for it to remove the absolute positioning and let it flow with the rest of the content.
CSS:
#media (max-width: 768px)
.bottom-left {
position: static;
bottom: 8px;
left: 16px;
text-align: left;
padding-left: 20px;
padding-bottom: 5px;
}
html-
<div class="main">
<span class="badge">Best Seller</span>
</div>
css-
.main{
position: relative;
}
.badge{
position: absolute;
top:0;
right:0;
background-color: #2879FE;
}
can anyone please show me what is the easiest way to do like this with CSS?
Try this
.main {
position: relative;
top: 10px; right: 10px;
width: 200px;
height: 200px;
background: #ccc;
}
.badge {
position: absolute;
top: -10px;
right: -10px;
background-color: #2879FE;
padding: 20px;
border-radius: 10px 0 0 10px;
}
.badge:after {
position: absolute;
top: 100%;
right: 0;
width: 0;
height: 0;
border-bottom: 10px solid transparent;
border-left: 10px solid #2879FE;
content: '';
}
<div class="main">
<span class="badge">Best Seller</span>
</div>
You can do this with pure CSS. I believe this is called a CSS ribbon
I found a pen by ds729 and modified it to match your design a little but more.
/* Reset */
html,
body,
div,
span,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
font,
img,
ul,
li {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
}
body {
background: #333;
color: #999;
}
h2 {
font-style: italic;
font-weight: normal;
line-height: 1.2em;
}
div#container {
margin: 50px auto 0px auto;
/* centered */
width: 400px;
}
.bubble {
clear: both;
margin: 0px auto;
width: 350px;
background: #fff;
border-radius: 10px;
box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
position: relative;
z-index: 90;
/* the stack order: displayed under ribbon rectangle (100) */
}
.rectangle {
background: #2879fe;
height: 50px;
width: 30;
padding: 0 20px;
position: relative;
left: -15px;
top: -15px;
float: left;
box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.55);
z-index: 100;
border-radius: 0 20px 20px 0
}
.rectangle h2 {
font-size: 30px;
color: #fff;
padding-top: 6px;
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
text-align: center;
}
.triangle-l {
border-color: transparent #2879fe transparent transparent;
border-style: solid;
border-width: 15px;
height: 0px;
width: 0px;
position: relative;
left: -30px;
top: 20px;
z-index: -1;
/* displayed under bubble */
}
.info {
padding: 60px 25px 35px 25px;
}
.info h2 {
font-size: 20px;
}
.info p {
padding-top: 10px;
font-size: 14px;
line-height: 22px;
}
.info p a {
color: #c4591e;
text-decoration: none;
}
.info p a:hover {
text-decoration: underline;
}
<div id="container">
<div class="bubble">
<div class="rectangle">
<h2>Stack Overflow</h2>
</div>
<div class="triangle-l"></div>
<div class="info">
<h2>Hello</h2>
<br />
<p>
This is pure CSS
</p>
</div>
</div>
</div>
I am almost finish with building the skeleton of my simon game clone and the only left I want to do is set the container (which holds the game itself) to have a max height of 605px.
I was able to accomplish its width max when it reaches a certain threshold in the viewport but I am having hard time applying the same behavior but horizontally instead.
Any inputs will be greatly appreciated.
I've attached my code in CodePen as well:
http://codepen.io/neotriz/pen/RRxOJb
body {
background: skyblue;
font-family: 'Righteous', cursive;
box-sizing: border-box; }
.container {
width: 100%;
display: flex;
flex-wrap: wrap; }
.game {
display: flex;
flex-wrap: wrap;
width: 100%;
height: 70vh;
margin-top: 10px; }
.button {
position: relative;
display: block;
height: 50%;
width: 50%;
margin-bottom: 1px; }
#green {
background: #39d565;
border-top-left-radius: 25%;
box-shadow: 0 6px 0 #0d934b;
bottom: 6px;
transition: all 0.1s linear; }
#green:active {
bottom: 0px;
box-shadow: 0px 0px 0px #0d934b; }
#red {
background: #d23a51;
border-top-right-radius: 25%;
box-shadow: 0 6px 0 #711515;
bottom: 6px;
transition: all 0.1s linear; }
#red:active {
bottom: 0px;
box-shadow: 0px 0px 0px #711515; }
#blue {
background: #09f;
border-bottom-left-radius: 25%;
box-shadow: 0 6px 0 #06c;
bottom: 6px;
transition: all 0.1s linear; }
#blue:active {
bottom: 0px;
box-shadow: 0px 0px 0px #06c; }
#yellow {
background: #FD9A01;
border-bottom-right-radius: 25%;
box-shadow: 0 6px 0 #916828;
bottom: 6px;
transition: all 0.1s linear; }
#yellow:active {
bottom: 0px;
box-shadow: 0px 0px 0px #916828; }
.score {
width: 100%;
height: 10vh;
text-align: center;
color: #FFF;
text-shadow: 1px 3px 2px black;
margin-bottom: 5px; }
.control-panel {
text-align: center;
width: 100%;
display: flex;
flex-wrap: wrap;
position: relative;
height: 15vh;
align-items: center;
justify-content: center;
background: #aaaaaa;
border-radius: 10px; }
.control-panel #on-off-btn {
width: 33.3333%; }
.control-panel #level {
width: 33.3333%; }
.control-panel #start {
width: 33.3333%; }
.control-panel p {
margin: 8px 0px 0px 0px; }
.cmn-toggle {
position: absolute;
margin-left: -9999px;
visibility: hidden; }
.cmn-toggle + label {
display: block;
position: relative;
cursor: pointer;
outline: none;
user-select: none; }
input.cmn-toggle-round + label {
padding: 2px;
max-width: 90%;
height: 35px;
background-color: #dddddd;
border-radius: 60px;
margin-top: 9px;
margin-left: 5px; }
input.cmn-toggle-round + label:before,
input.cmn-toggle-round + label:after {
display: block;
position: absolute;
top: 1px;
left: 1px;
bottom: 1px;
content: ""; }
input.cmn-toggle-round + label:before {
right: 1px;
background-color: white;
border-radius: 60px;
transition: background 0.4s; }
input.cmn-toggle-round + label:after {
width: 38px;
background-color: #fff;
border-radius: 100%;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
transition: margin-left 0.4s; }
input.cmn-toggle-round:checked + label:before {
background-color: #8ce196; }
input.cmn-toggle-round:checked + label:after {
margin-left: 58%; }
.btn-round {
width: 50%;
height: 50px;
background: #ed2914;
border-radius: 100%;
outline: none;
box-shadow: 0 6px 0 #711515;
bottom: 6px;
transition: all 0.1s linear; }
.btn-round:active {
bottom: 0px;
box-shadow: 0px 0px 0px #711515; }
#media screen and (max-width: 311px) {
input.cmn-toggle-round:checked + label:after {
margin-left: 45%; } }
#media screen and (min-width: 426px) {
.container {
width: 426px;
margin-left: auto;
margin-right: auto; }
input.cmn-toggle-round:checked + label:after {
margin-left: 66%; } }
#media screen and (min-height: 605px) {
.container {
height: 605px; } }
<!DOCTYPE html>
<html lang="en">
<head>
<title>Simon Game FCC</title>
</head>
<body>
<div class="container">
<div class="game">
<div id="green" class="button"></div>
<div id="red" class="button"></div>
<div id="blue" class="button"></div>
<div id="yellow" class="button"></div>
</div>
<div class="score">
<h2>Score: 0 </h2>
</div>
<div class="control-panel">
<div id="on-off-btn">
<input id="on-off-slider"type="checkbox" class="cmn-toggle cmn-toggle-round">
<label for="on-off-slider"></label>
<p>Off/On</p>
</div>
<div id="level">
<input id="level-slider"type="checkbox" class="cmn-toggle cmn-toggle-round">
<label for="level-slider"></label>
<p>Level</p>
</div>
<div id="start">
<button class="btn-round"></button>
<p>(re)Start</p>
</div>
</div>
</div>
</body>
</html>
I think mixing vh heights and flex disposition is part of the problem because it makes the code a bit tricky to adjust. So I would suggest to remove all vh heights that are inside the container and replace them with a flex vertical positionning.
Here is the sccs I get (only the changed rules are here) :
.container {
width: 100%;
display: flex;
flex-wrap: wrap;
height: 100vh;
flex-direction: column;
justify-content: center; }
.game {
display: flex;
flex-wrap: wrap;
width: 100%;
margin-top: 10px;
flex: 1 1 auto; }
.score {
width: 100%;
text-align: center;
color: #FFF;
text-shadow: 1px 3px 2px black;
margin-bottom: 5px;
flex: 0 0 auto; }
.control-panel {
text-align: center;
width: 100%;
display: flex;
flex-wrap: wrap;
position: relative;
align-items: center;
justify-content: center;
background: #aaaaaa;
border-radius: 10px;
flex: 0 0 auto; }