"Button:active" moves all buttons instead of only clicked button - css

I know that it has something to do with margin's colliding or the layout but I can't figure it exactly out. My goal is to move a clicked (div) button by 5 pixels. The current way I do this is by setting the :active margin-top to 5.
I also can't figure out how to make all buttons take up the whole screen space. Using 100% or 100vh creates too much space.
CSS:
body{
margin: 0;
padding: 0;
font-family: Sans-Serif;
-webkit-animation: bgcolor 20s infinite;
animation: bgcolor 10s infinite;
-webkit-animation-direction: alternate;
animation-direction: alternate;
}
header{
background-color: rgba(0, 0, 0, 0.5);
color: white;
text-align: center;
font-size: 25px;
}
.container{
padding: 10px;
margin: 0 auto;
text-align: center;
}
.question{
font-size: 35px;
margin: 10px;
font-weight: bold;
color: white;
}
.buttons-container{
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-gap: 10px;
height: 100%;
}
.button{
padding: 25px;
background-color: green;
color: white;
font-size: 25px;
box-shadow: 0px 5px 0px #504f4f;
}
.button:active{
box-shadow: none;
margin-top: 5px;
}
#keyframes bgcolor {
0% {
background-color: #45a3e5
}
30% {
background-color: #66bf39
}
60% {
background-color: #eb670f
}
90% {
background-color: #f35
}
100% {
background-color: #864cbf
}
}
HTML
<?php
include 'header.php';
?>
<div class="wrapper">
<header>
Quiz
</header>
<div class="container">
<div class="question">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>
<div class="buttons-container">
<div class="button">
Opt 1
</div>
<div class="button">
Opt 2
</div>
<div class="button">
Opt 3
</div>
<div class="button">
Opt 4
</div>
</div>
</div>
</div>
</body>
</html>

A little further explanation from my comment: when you use margins, you are actually going to influence the document flow and that is causing the entire page to reflow and relayout.
If you want to preserve document flow but nudge the button around, you should consider using relative positioning, i.e. position: relative; top: -5px;.
ps: The default is position: static.

Related

Why is my image not displaying and how could I increase the room given also my animations don't work as well

Project Link
I'm trying to get my background image to be visible but it doesn't appear, Also my css animations don't work as well any information on how to correct this?
.bg-image {
/* The image used */
background-image: url("https://i.postimg.cc/Hn0vxz91/Bridge.jpg");
/* Add the blur effect */
filter: blur(8px);
-webkit-filter: blur(8px);
/* Full height */
height: 100%;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
border: solid 1px red;
object-fit: cover;
}
/* Position text in the middle of the page/image */
.bg-text {
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0, 0.4); /* Black w/opacity/see-through */
color: white;
font-weight: bold;
border: 3px solid #f1f1f1;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 2;
width: 80%;
padding: 20px;
text-align: center;
}
body{
background-color:#28282B;
}
/* Style the links inside the pill navigation menu */
.pill-nav a {
display: inline-block;
color: black;
text-align: center;
padding: 14px;
text-decoration: none;
font-size: 17px;
border-radius: 5px;
}
/* Change the color of links on mouse-over */
.pill-nav a:hover {
background-color: #ddd;
color: black;
}
/* Add a color to the active/current link */
.pill-nav a.active {
background-color: dodgerblue;
color: white;
}
pulse a:hover{
animation: pulse 1s infinite;
animation-timing-function: linear;
}
#keyframes pulse {
0% { transform: scale(1); }
50% { transform: scale(1.1);
100% { transform: scale(1); }
}
}
/* Style the container with a rounded border, grey background and some padding and margin */
.container {
border: 1px solid #ccc;
background-color: #eee;
border-radius: 5px;
padding: 16px;
margin: 16px 0;
}
/* Clear floats after containers */
.container::after {
content: "";
clear: both;
display: table;
}
/* Float images inside the container to the left. Add a right margin, and style the image as a circle */
.container img {
float: left;
margin-right: 20px;
border-radius: 50%;
}
/* Increase the font-size of a span element */
.container span {
font-size: 20px;
margin-right: 15px;
}
/* Add media queries for responsiveness. This will center both the text and the image inside the container */
#media (max-width: 500px) {
.container {
text-align: center;
}
.container img {
margin: auto;
float: none;
display: block;
}
}
.checked {
color: orange;
}
.card {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
max-width: 300px;
margin: auto;
text-align: center;
}
.title {
color: grey;
font-size: 18px;
}
button {
border: none;
outline: 0;
display: inline-block;
padding: 8px;
color: white;
background-color: #000;
text-align: center;
cursor: pointer;
width: 100%;
font-size: 18px;
}
a {
text-decoration: none;
font-size: 22px;
color: white;
}
#star{
background-color:#28282B;
}
.container{
background-color:#28282B;
}
.center {
background-color:white;
}
<header>
<title> Portfoilo</title>
<nav id="navbar">
<div class="pill-nav">
<div class="pulse">
<a class="active" href="#welcome-section">Home</a>
Projects
Certifications</nav> </div>
</div>
</header>
<main><section>
<div class="bg-image"></div>
<div class="bg-text">
<h1>I Am John Doe</h1>
<p>And I'm a Photographer</p>
</div>
</section>
<section id="welcome-section">
<h1 id="practice"> Welcome to My Practice Portfolio</h1></section>
<p>This is my practice portfolio to fune tune my skills when I am readyu to showcase my skills to the web I will link it to the actual one when it's ready and I am ready to share on the web thank you for reading this messgae.</p>
<section id="projects">
Tribute Page
Technical Documentation
</section>
<section id="Certifications">
Certifications</section>
</main>
<body>
<div class="container">
<img src="https://i.pinimg.com/originals/21/45/47/2145477174ea52cd79758af817b905b9.jpg" alt="Avatar" style="width:90px">
<p><span>Julie Jacobs.</span> CEO at Mighty Schools.</p>
<p>John Doe saved us from a web disaster.</p>
</div>
<div class="container">
<img src="https://www.byrdie.com/thmb/fLsxKLnkeZWgt54cWlUCw8ya1KE=/1716x1716/smart/filters:no_upscale()/Screen-Shot-2020-08-31-at-2.57.48-PM-ab7152b68d9042838d10c0ff58f8d3bf.jpg" alt="Avatar" style="width:90px">
<p><span >Rebecca Flex.</span> CEO at Company.</p>
<p>No one is better than John Doe</p>
<div id="star">
<span class="fa fa-star checked"></span>
<span class="fa fa-star checked"></span>
<span class="fa fa-star checked"></span>
<span class="fa fa-star checked"></span>
<span class="fa fa-star checked"></span>
</div>
</div>
</body>
<footer>
<!-- Add icon library -->
<div class="card">
<img src="https://i.guim.co.uk/img/media/9bb29e1304526b5aeb6378f485f16bd5310dff9e/0_236_4500_2700/master/4500.jpg?width=445&quality=45&auto=format&fit=max&dpr=2&s=b87889efa83846281e306c50ef9370db" alt="John" style="width:100%">
<h1 class="contact">John Doe</h1>
<p class="title">CEO & Founder, Example</p>
<p>Harvard University</p>
<i class="fa fa-dribbble"></i>
<i class="fa fa-twitter"></i>
<i class="fa fa-linkedin"></i>
<i class="fa fa-facebook"></i>
<p><button>Contact</button></p>
</div>
</footer>
I'm trying to get my image to display while having a shade of the background color add effect to the image and I have css animations that don't work any information on how to fix all that? So they both could become visible also the card section how to make one portion of it white.
Your background image is working fine for me right now.
About the animation; You mean div class pulse right?
Put <nav> inside <body> and see if it works or not.

CSS - change height to up by content

i have 3 boxes and i need change height by content but height must change to up (Lower margin aligned). Here is image how it should look:
<style>
.wrapper{
width: 100%;
height: 30px;
}
.wrapper .point{
width: 12px;
height: 12px;
background: #979797;
-moz-border-radius: 70px;
-webkit-border-radius: 70px;
border-radius: 70px;
float: left;
margin-top: 3px;
}
.wrapper .text{
width: 130px;
float: left;
border-bottom: 2px solid #979797;
color: #979797;
font-size: 11px;
min-height: 20px;
text-align: center;
padding-bottom: 20px;
margin-top: -12px;
}
</style>
<div class="wrapper">
<div class="point"></div>
<div class="text">Short</div>
<div class="point"></div>
<div class="text">Short</div>
<div class="point"></div>
<div class="text">Very long text. Lorem ipsum dolor sit amet</div>
<div class="point"></div>
</div>
How to do it? Thanks
try
height:auto,
width:100%
in your css
It's impossible with float:left (unless you know the exact height in advance and can set the margin-top according to it). But floats never were meant to do this type of layout anyways.
However, it can be easyly done with Flexbox:
.wrapper{
display: flex;
flex-flow: row wrap;
align-items: flex-end;
}
.wrapper .point{
width: 12px;
height: 12px;
background: #979797;
border-radius: 70px;
display: inline-block;
margin-top: 3px;
}
.wrapper .text{
width: 90px;
border-bottom: 2px solid #979797;
color: #979797;
font-size: 11px;
text-align: center;
padding: 20px;
background: #eee;
}
<div class="wrapper">
<div class="point"></div>
<div class="text">Short</div>
<div class="point"></div>
<div class="text">Short</div>
<div class="point"></div>
<div class="text">Very long text. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet</div>
<div class="point"></div>
</div>
Also, this can be done with inline-blocks, by setting vertical-align:bottom to their container. You can add this as a fallback to Flexbox solution (all you need for this is setting vertical-align:bottom to .wrapper and display:inline-block to points and texts). I'd not recommend to rely on inline-blocks only because they weren't meant to do the layout, like floats, and will need some sort of hacks to adjust the spaces between items, because they treat whitespace characters between tags as whitespace text characters. But as a fallback for non-Flexbox-supporting browsers (like IE10-) they would provide a decent experience (much better than nothing).

Length of <p> element changing position of parent?

I currently have a set of 'product' divs inside a wrapping containers. These product divs contain an image, header and p text. For some reason, the length of the p text is changing the position of the parent product div. Here is a screenshot: https://gyazo.com/9504729541e6bee17a27e4121af3a1c9
The p and h2 elements both have 0 padding and margins.
I will try to keep my code as minimal as possible.
HTML:
<div id="content" class="wrapper">
<div id="content-container">
<div id="product-container">
<div class="product-wrapper">
<div id="product" class="unhidden">
<div class="image-container">
<img src="assets/home-bg.jpg" class="thumbnail">
</div>
<div class="product-text">
<h2>Mexican Nachos - £6.99</h2>
<p>Tortilla chips and melted cheese with the option of salsa, jalapenos, ground meat, guacamole and tomatoes.</p>
</div>
</div>
<div id="product" class="unhidden">
<div class="image-container">
<img src="assets/enchilada.jpg" class="thumbnail">
</div>
<div class="product-text">
<h2>Enchiladas - £10.99</h2>
<p>Tortilla chips and melted cheese with the option of salsa, jalapenos, ground meat, guacamole and tomatoes.</p>
</div>
</div>
<div id="product" class="unhidden">
<div class="image-container">
<img src="assets/quesadilla.jpg" class="thumbnail">
</div>
<div class="product-text">
<h2>Quesadilla - £4.99</h2>
<p>Shorter length test</p>
</div>
</div>
<div id="product" class="unhidden">
<div class="image-container">
<img src="assets/shrimp.jpg" class="thumbnail">
</div>
<div class="product-text">
<h2>Shrimp Stir Fry - £10.99</h2>
</div>
</div>
</div>
</div> <!-- Product container -->
</div> <!-- Content container -->
</div> <!-- Content-wrapper container -->
CSS:
#content {
height: 100%;
padding-top: 100px;
}
.wrapper {
width: 65%;
margin: 0 auto;
}
#content-container {
display: inline-block;
width: 100%;
height: 100%;
background-color: white;
box-shadow: -20px 0px 25px -20px #000000, 20px 0px 25px -20px #000000;
overflow: scroll;
}
#product-container {
width: 100%;
height: 100%;
padding-top: 25px;
}
.product-wrapper {
width: 80%;
height: 100%;
margin: 0px auto;
text-align: center;
}
#product {
display: inline-block;
height: 352px;
width: 200px;
margin: 10px;
border: solid 2px black;
}
.image-container {
height: 200px;
width: 200px;
}
.product-text {
font-family: 'Open Sans Condensed';
height: 150px;
width: 100%;
text-align: center;
color: black;
border-top: solid 2px black;
background: #FFFFFF; /* Old browsers */
background: -moz-linear-gradient(top, #009641 0%, #a1d54f 96%, #80c217 100%, #7cbc0a 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(top, #009641 0%,#a1d54f 96%,#80c217 100%,#7cbc0a 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to bottom, #009641 0%,#a1d54f 96%,#80c217 100%,#7cbc0a 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
}
.product-text h2 {
font-size: 23px;
padding: 0;
margin: 0;
}
.product-text p {
font-style: italic;
font-weight: 700;
padding: 0;
margin: 0;
}
.thumbnail {
position: relative;
height: 200px;
width: 200px;
cursor: pointer;
z-index: 1200;
}
Your #product elements are display: inline-block. This means they will take inline level characteristics, one of which is baseline alignment (i.e., vertical-align: baseline).
Override the default setting with vertical-align: top.
(Also, you have multiple elements with id="product". ID values should be unique on a page. Consider switching to class="product" instead.)
add vertical-align:top to #product.
#product {
display: inline-block;
height: 352px;
width: 200px;
vertical-align: top;
margin: 10px;
border: solid 2px black;
}
And one more thing, its not a best practice to have same id's for different elements. Instead make it .product class.

Chrome/Firefox difference with negative margin bottom percentage

I have a difference of box sizing interpretation between webkit and Firefox using height 100% on a parent.
HTML:
<header>
Lorem ipsum dolor amet
</header>
<div class="wrapper">
<div class="content">
My background depends on my ancestor sibling
</div>
</div>
<div class="red">
<p class="white">
Amet ipsum dolor
</p>
</div>
CSS:
header {
height: 150px;
background: #fff;
}
.red {
background: red;
padding: 6em 0;
}
.content {
background: rgba(28,28,28, .3);
margin-bottom: -100%;
}
.wrapper {
position: relative;
height: 100%;
}
p.white {
background: #fff;
width: 70%;
margin: 0 auto;
}
JS fiddle here https://jsfiddle.net/m1fobvwv/
Result on Chrome (expected):
Wrong result on FF:
A colleague of mine found a workaround:
Add position: absolute; width: 100%; to .content
Updated fiddle https://jsfiddle.net/m1fobvwv/3/

CSS transition - only working in one direction, needs to be both

I have a CSS transition which takes place on hover of a link - the transition happens to some of the contents of this link.
My issue is that the transition (which primarily animates width and height properties) works fine when hovering over the link, but on stopping hover, the elements simply spring back to their unhovered state - rather than transitioning.
The styles defined are this:
a.transition {
display: block;
width: 300px;
height: 200px;
position: relative;
border: 1px solid #000;
color: #000'
}
a.transition .category_info_container {
position: absolute;
left: 0;
right: 0;
top: 0;
height: 70px;
transition: height 0.5s, width 0.5s, color 0.5s;
}
a.transition .category_info_container .category_info {
background-color: #aaa;
padding: 0 20px;
}
a.transition .category_info_container .category_info .category_name {
color: #fff;
text-transform: uppercase;
font-size: 18px;
line-height: 70px;
}
a.transition .category_info_container .category_info .category_desc {
display: none;
}
a.transition:hover .category_info_container {
background: #eee;
width: 48%;
height: 100%;
}
a.transition:hover .category_info_container .category_info {
position: absolute;
bottom: 20%;
background: none;
}
a.transition:hover .category_info_container .category_info .category_name {
color: #000;
line-height: 50px;
}
a.transition:hover .category_info_container .category_info .category_desc {
display: block;
}
And my markup:
<a href="#" class="transition">
<div class="category_info_container">
<div class="category_info">
<div class="category_name">
Test Name
</div>
<div class="category_desc">
Lorem ipsum dolar sit amet...
</div>
</div>
</div>
</a>
I have created a JSFiddle with my code.
I think, It will be better, if you use different blocks for elements:
checkout my example:
http://jsfiddle.net/bo5o3q18/3/
<a href="#" class="transition">
<div class="category_info">
<div class="category_name">
Test Name
</div>
</div>
<div class="category_info-add">
<div class="category_name">
Test Name
</div>
<div class="category_desc">
Lorem ipsum dolar sit amet...
</div>
</div>
</a>

Resources