I'm building a website for a side project and I need to have 2 cards, presenting someone with an image on the left and some text + another image on the right.
I want that card to be 1.1 times scaled when hovered or focused but when I do the usual method (as in the snippet), somehow the image on the right shifts a bit to the top.
/* GÉNÉRAL */
:root {
--color-accent: #4e6eff;
--color-accent-dark: #3a56d3;
--color-black: #252728;
--color-white: #fdfdff;
--color-blacker: #0c0d0d;
}
html {
scroll-behavior: smooth;
scroll-padding-top: 0;
}
body::-webkit-scrollbar {
display: none;
}
* {
font-family: Arial, Helvetica, sans-serif;
margin: 0;
padding: 0;
box-sizing: border-box;
}
*::selection {
background-color: #4e6effba;
}
body {
background-color: var(--color-black);
color: var(--color-white);
}
/* COMMON STYLE */
.bg-accent {
background-color: var(--color-accent);
color: var(--color-white);
}
a {
color: var(--color-white);
text-decoration: none;
}
img {
width: 100%;
}
/* */
.select-membres__row--2 {
display: flex;
justify-content: space-evenly;
}
.membre-carte {
display: flex;
padding: 1em;
width: 400px;
height: 200px;
gap: 8%;
border-radius: 25px;
background-color: var(--color-blacker);
text-align: center;
scale: 1;
transition: scale 100ms ease-out;
}
.membre-carte:hover {
scale: 1.1;
transition: scale 150ms cubic-bezier(0.22, 0.47, 0.35, 0.92);
border: 3px solid var(--color-accent);
}
.membre-carte>* {
width: 50%;
}
.membre-carte .carte-pp {
border-radius: calc(25px - 0.5em);
}
.perso-cont {
display: flex;
flex-direction: column;
justify-content: space-between;
}
.carte__nom {
font-size: 1.2rem;
}
.perso-cont .img-cont {
width: 120px;
margin-inline: auto;
display: flex;
}
<div class="select-membres__row--2">
<a href="#">
<div class="membre-carte">
<img src="https://source.unsplash.com/random/50x50" class="carte-pp">
<div class="perso-cont">
<h4 class="carte__nom">image 1</h4>
<p class="carte__surnom">lorem</p>
<div class="img-cont">
<img src="https://source.unsplash.com/random/40x40">
</div>
</div>
</div>
</a>
<a href="#">
<div class="membre-carte">
<img src="https://source.unsplash.com/random/50x50" class="carte-pp">
<div class="perso-cont">
<div>
<h4 class="carte__nom">image 2</h4>
<p class="carte__surnom">lorem</p>
</div>
<div class="img-cont">
<img src="https://source.unsplash.com/random/40x40">
</div>
</div>
</div>
</a>
</div>
The border in .membre-carte:hover consumes an extra 6px (top 3px and bottom 3px) from the total height of the cart leaving less room for the content to fit in.
Add a transparent border like .membre-carte { border: 3px solid transparent } to you CSS and the movement will disappear, because now both the unhovered vs. hovered state consume the same amount of space again.
Be aware that you will lose 6px of the carts spaces for their content to fit in.
Related
I have a css grid container I use to have a image slider and some text on the right. I have everything working except for getting the image to actually stretch across the whole container.
How I have it set up is (trunicated):
<div class="slideshowGrid">
<div class="slideshow-container">
<div class="mySlides fade">
<img src="{{ module.slide.slide_image.src }}" alt="{{ module.slide.slide_image.alt }}" {{ loadingAttr }} {{ sizeAttrs }}>
</div>
</div>
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
<div class="textboxes">
<div class="text">
<h3 class="headerText">{% inline_text field="slide.heading_text" value="{{ module.slide.heading_text }}" %}</h3>
<div class="bodyText">
{% inline_rich_text field="slide.body_text" value="{{ module.slide.body_text }}" %}
</div>
</div>
<div class="linkBox">
<div class="linkingText">
Book Now
</div>
</div>
</div>
</div>
I guess my question is; is there anyway to stretch the image div to fill the available column in the grid without forcing the image to be a background image? I know background image is a way to do it, but I feel like it would require some significant code changes to do that. Here's my css:
code:
* {box-sizing:border-box}
.slideshowGrid{
display: grid;
grid-template-columns: 75% 25%;
justify-content: center;
align-content: center;
justify-items: stretch;
}
.textboxes{
display: grid;
justify-items: center;
}
.linkBox{
align-self: flex-end;
justify-self: center;
}
/* Slideshow container */
.slideshow-container {
max-width: 100%;
height: 500px;
position: relative;
margin: auto;
}
.slideshow-container img{
height: 500px !important;
width: 1200px !important;
object-fit: cover !important;
}
/* Hide the images by default */
.mySlides {
display: none;
}
/* Next & previous buttons */
.prev, .next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
margin-top: -22px;
padding: 16px;
color: white;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
}
/* Position the "next button" to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
/* On hover, add a black background color with a little bit see-through */
.prev:hover, .next:hover {
background-color: rgba(0,0,0,0.8);
}
/* Caption text */
.text {
color: black;
font-size: 15px;
padding: 8px 12px
width: 100%;
align-self: center;
justify-self: center;
}
/* Number text (1/3 etc) */
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}
/* Fading animation */
.fade {
animation-name: fade;
animation-duration: 1.5s;
}
#keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
/* On smaller screens, decrease text size */
#media only screen and (max-width: 300px) {
.prev, .next,.text {font-size: 11px}
}
Thanks!
Okay, I see what you're doing. You've explicitly defined the height of the container for the images and then applied attributes to the images inside of that container. So, the easiest fix is to just apply the same height to your images, give them a width of 100% so they fill the container horizontally, and use object-fit: cover; to crop them into the container and maintain their aspect ratio. https://jsfiddle.net/astombaugh/ad4kb2v5/46/ You may need to tweak the results in the context of your entire project but this should at least get your image container moving in the right direction.
let slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
let i;
let slides = document.getElementsByClassName("mySlides");
let dots = document.getElementsByClassName("dot");
let headers = document.getElementsByClassName("headerText");
let bodies = document.getElementsByClassName("bodyText");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slides[slideIndex-1].style.display = "block";
}
* {
box-sizing: border-box;
}
body {
background-color: grey;
}
.slideshowGrid {
display: grid;
grid-template-columns: 75% 25%;
justify-content: center;
align-content: center;
justify-items: stretch;
}
.textboxes {
display: grid;
justify-items: center;
}
.linkBox {
align-self: flex-end;
justify-self: center;
}
/* Slideshow container */
.slideshow-container {
height: 500px;
position: relative;
}
.slideshow-container img {
height: 500px;
width: 100%;
object-fit: cover;
}
/* Hide the images by default */
.mySlides {
display: none;
}
/* Next & previous buttons */
.prev,
.next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
margin-top: -22px;
padding: 16px;
color: white;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
}
/* Position the "next button" to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
/* On hover, add a black background color with a little bit see-through */
.prev:hover,
.next:hover {
background-color: rgba(0, 0, 0, 0.8);
}
/* Caption text */
.text {
color: black;
font-size: 15px;
padding: 8px 12px;
width: 100%;
align-self: center;
justify-self: center;
}
/* Number text (1/3 etc) */
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}
/* The dots/bullets/indicators */
.dot {
cursor: pointer;
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}
.active,
.dot:hover {
background-color: #717171;
}
/* Fading animation */
.fade {
animation-name: fade;
animation-duration: 1.5s;
}
#keyframes fade {
from {
opacity: .4
}
to {
opacity: 1
}
}
/* On smaller screens, decrease text size */
#media only screen and (max-width: 300px) {
.prev,
.next,
.text {
font-size: 11px
}
}
<div class="slideshowGrid">
<div class="slideshow-container">
<div class="mySlides fade">
<img src="https://2822935.fs1.hubspotusercontent-na1.net/hubfs/2822935/rw_phaseII.jpg">
</div>
<div class="mySlides fade">
<img src="https://2822935.fs1.hubspotusercontent-na1.net/hubfs/2822935/Riverwalk_Day-View_CYMK-web.jpg">
</div>
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
<div class="textboxes">
<div class="text">
<h3 class="headerText">TEST</h3>
<div class="bodyText">
adsfasdfasfadsfds
</div>
<h3 class="headerText">
Test 2
</h3>
<div class="bodyText">
werrererewrwereewrwer
</div>
</div>
<div class="linkBox">
<div class="linkingText">
TEST
</div>
</div>
</div>
</div>
This is my HTML and CSS:
html, body {
height: 100%;
width: 100%;
margin: 0;
font-family: 'Open Sans';
background: radial-gradient(#484646, #212020);
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 15px;
display: flex;
}
.product-info {
background-color: rgba(28, 28, 28, 0.4);
}
.product-info h2 {
font-family: 'Montserrat';
color: white;
padding: 5px;
}
.product-info p {
font-size: 18px;
color: white;
text-decoration: none;
padding: 5px;
}
<div class = "container">
<div class = "product-img">
<img src="https://via.placeholder.com/200x200.png" alt = "Image">
</div>
<div class = "product-info">
<h2>Product name</h2>
<p>Description: Product description</p>
<p>Price: $2000</p>
<p>Color: Black</p>
</div>
</div>
In my browser, the image and the texts look like this which appears very huge but I want to make them look smaller instead. Is there a way to go about with this?
You can set the width & height of the div.product-img to 200x200. And then set the width and height of the image to 100% (both). That means even if your image is 1920x1080, it will fit its parent completely.
You're using max-width: 1200px;. This means the container will increase the width until it reaches 1200px and then it will not increase anymore. Instead of using max-width, I recommend you using only width so it won't increase the width as much as possible.
html,
body {
height: 100%;
width: 100%;
margin: 0;
font-family: 'Open Sans';
background: radial-gradient(#484646, #212020);
}
.container {
/* EDITED HERE */
/* max-width: 1200px; */
width: 600px;
margin: 0 auto;
padding: 15px;
display: flex;
}
/* ADDED HERE PART1 */
.product-img {
width: 200px;
height: 200px;
}
/* ADDED HERE PART2 */
.product-img img {
width: 100%;
height: 100%
}
.product-info {
background-color: rgba(28, 28, 28, 0.4);
}
.product-info h2 {
font-family: 'Montserrat';
color: white;
padding: 5px;
}
.product-info p {
font-size: 18px;
color: white;
text-decoration: none;
padding: 5px;
}
<div class="container">
<div class="product-img">
<img src="https://picsum.photos/200/200" alt="Image">
</div>
<div class="product-info">
<h2>Product name</h2>
<p>Description: Product description</p>
<p>Price: $2000</p>
<p>Color: Black</p>
</div>
</div>
I am trying to use custom icons (3 of them) be located in their own cell in a table with the cell directly beside them being the text that goes along with them. I want the text to be close to the image. The image is to enlarge slightly when hovered over as it will also be a hyperlink. I can't seem to get code to ensure it is aligned center of the page and formatted correctly. Also the scale isn't working when I set it to enlarge on hover.
I have already tried multiple codes but none seem to be working within sharepoint.
.demo-problem,
.demo-solution {
font-size: 1.5em;
}
body {
padding: 30px;
}
.outer-div {
padding: 30px;
}
.inner-div {
margin: 0 auto;
width: 100%;
height: 100%;
}
.demo-solution--flexbox {
display: flex;
align-items: center;
}
img3 {
width: 25%;
height: auto;
display: block;
}
img3:hover {
transform: scale(3);
}
a:hover {
text-decoration: none;
color: black;
font-weight: bold;
}
<div class="demo-solution demo-solution--flexbox">
<div class="outer-div">
<img src="https://ontariopowergeneration.sharepoint.com/:i:/r/sites/powernet/support/res/PublishingImages/Pages/Real%20Estate/Icons/ICON_Real-Estate.png?csf=1&e=acVaiZ" alt="" class="img3">
</div>
<div class="inner-div"><span><blockquote>Corporate Real Estate & Workplace</blockquote></span></div>
</div>
The img3 is a class so u need to specify
.img3 whereas you have done just img3.
If you change it to .img3 scale works
.demo-problem,
.demo-solution {
font-size: 1.5em;
}
body {
padding: 30px;
}
.outer-div {
padding: 30px;
}
.inner-div {
margin: 0 auto;
width: 100%;
height: 100%;
}
.demo-solution--flexbox {
display: flex;
align-items: center;
}
.img3 {
width: 25%;
height: auto;
display: block;
}
.img3:hover {
transform: scale(3);
}
a:hover {
text-decoration: none;
color: black;
font-weight: bold;
}
<div class="demo-solution demo-solution--flexbox">
<div class="outer-div">
<img src="https://www.slipperelectrical.co.nz/wp-content/uploads/2015/12/dummy-image.jpg" alt="" class="img3">
</div>
<div class="inner-div"><span><blockquote>Corporate Real Estate & Workplace</blockquote></span></div>
</div>
I started doing a website and I have a problem.
I started making my navigation bar, here's the code:
<div class="navGrid">
<div class="first">ZENZZEX </div>
<div class="span-col-4 second">
<button>Services</button>
<button>About us</button>
<button>Contact us</button>
</div>
<div class="third"><button>Get Started</button></div>
</div>
and the problem is that this <a> tag is taking space outside my button area. Here's a full code on Codepen:
https://codepen.io/MareGraphics/pen/GwqpOy
What I want is to contain A tag to fit 100% inside my button, not outside od it.
Thank You
The reason you cannot adjust the height and width of your <a> is because anchor elements are inline-elements.
An inline element does not start on a new line and only takes up as much width as necessary.
If you want to adjust the height and width you would need to specify another display property, e.g.
a { display: inline-block; }
For what it's worth, it's better to omit the button inside the anchor tag, just style the anchor tag as your button to make it act like a button.
e.g. if you are using bootstrap, you can do
Get Started
Use this code:
<a style="padding:50px;background-color:gray;width100%;line-height:70px;" class="btn btn-info">Buttons</a>
Remove your buttons from navgrid div and change the CSS like this
body {
margin: 0;
}
.navGrid {
display: grid;
grid-template-columns: repeat(6, 1fr);
position: fixed;
width: 100%;
top: 0;
background-color: white;
box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.3);
}
.span-col-4 {
grid-column: span 4 / auto;
}
.navGrid .first {
color: black;
text-align: center;
font-family: 'Dosis', sans-serif;
font-size: 1.2em;
font-weight: 800;
background-color: white;
border-right: 1px solid rgba(0, 0, 0, 0.2);
display: flex;
align-items: center;
justify-content: center;
transition: .5s;
}
.navGrid .first:hover {
cursor: pointer;
font-size: 1.31em;
}
.navGrid {
height: 40px
}
.navGrid .second {
display: flex;
padding-left: 50px;
border-style: none;
background-color: white;
font-family: 'Dosis', sans-serif;
text-transform: uppercase;
transition: .5s;
}
.navGrid .second a {
padding: 10px;
}
.navGrid .second a:hover {
background-color: rgba(0, 0, 0, 0.2);
text-decoration: none;
}
.navGrid .second:hover {
cursor: pointer;
}
.navGrid .third {
display: flex;
padding-left: 50px;
border-style: none;
background-color: rgb(0, 26, 255);
font-family: 'Dosis', sans-serif;
text-transform: uppercase;
transition: .5s;
color: white;
}
.navGrid .third a {
padding: 10px;
}
.navGrid .third:hover {
background-color: rgb(3, 25, 219);
cursor: pointer;
}
.navGrid .third {
border-left: 1px solid black;
}
.content {
background-color: green;
height: 2000px;
}
<div class="navGrid">
<div class="first">ZENZZEX </div>
<div class="span-col-4 second">
Services
About us
Contact us
</div>
<div class="third">Get Started</div>
</div>
I think this may help you.
Here is the outcome
What I want to achieve are
A gray circle surrounding the '<' with the letter in the center
It and 'untitled' aligns vertically to the center
However despite setting the width and height to the same size, the 'circle' still ends up in an oval shape.
The use of flex's align-items: center; also fails to achieve the alignment.
How can I fix the css? Here is a link to the sample code
html
<div class='flex-container'>
<div class='arrow-container'>
<a class='btn-icon' href='#'>
<span class='square-btn icon icon-back'></span>
</a>
</div>
<div class=title>
<a href='#'>Untitled
</a>
</div>
</div>
css
.flex-container {
display: flex;
align-items: center;
}
.icon {
font-size: 50px;
}
.icon-back::before {
content: '<';
}
.title {
margin-left: 5px;
font-size: 50px;
}
.square-btn {
height: 50px;
width: 50px;
}
.btn-icon {
padding: 5px;
border-radius: 50%;
background-color: gray;
text-decoration: none;
}
This seems to work. No changes to HTML.
.flex-container {
display: flex;
align-items: center;
}
.icon {
font-size: 50px;
}
.icon-back::before {
content: '<';
}
.title {
margin-left: 5px;
font-size: 50px;
}
.square-btn {
height: 50px;
width: 50px;
border-radius: 50%; /* new */
background-color: gray; /* new */
display: flex; /* new */
align-items: center; /* new; align arrow vertically */
justify-content: center; /* new; align arrow horizontally */
}
.btn-icon {
/* padding: 5px; <-- remove */
/* border-radius: 50%; <-- remove */
/* background-color: gray; <-- remove */
text-decoration: none;
}
<div class='flex-container'>
<div class='arrow-container'>
<a class='btn-icon' href='#'>
<span class='square-btn icon icon-back'></span>
</a>
</div>
<div class=title>
<a href='#'>Untitled
</a>
</div>
</div>
jsFiddle
This can be done with a single html element and pseude-elements. One neat advantage of making everything depend on the font-size is, that the icon scales proportionally with the font size of the link.
.link {
font-size: 50px;
margin-left: 1.1em;
}
.icon {
position: relative;
}
.icon-back::before {
content: '<';
position: absolute;
left: -.9em;
display: inline-block;
z-index: 2;
}
.icon-back::after {
content: '';
border-radius: 50%;
background-color: gray;
width: 1em;
height: 1em;
position: absolute;
top: 50%;
left: -1.1em;
/* Use translateX() and translateY()
if you care about old browsers */
transform: translate3d(0, -45%, 0);
}
<a class="link icon icon-back" href="#">Untitled</a>
Grouping classes makes things harder, also, use unicode in css content when it's not alpha-numerical text, try this:
<div class="flex-container">
<div class="arrow-container">
<a class="btn-icon" href="#">
<span class="icon-back"></span>
</a>
</div>
<div class="title">
<a href="#">Untitled
</a>
</div>
</div>
<style type="text/css">
.flex-container {
display: flex;
align-items: center;
}
.btn-icon {
font-size: 50px;
text-decoration: none;
}
.icon-back::before {
content: "\003c";
border-radius: 50%;
background-color: gray;
font-size: 40px;
height:40px;
width:40px;
vertical-align:middle;
display:inline-block;
margin-bottom:5px;
text-align:center;
}
.title {
margin-left: 5px;
font-size: 50px;
}
</style>