Responsive Hover Items CSS
January 7, 2025 · AI Conversations
{
width:100%;
height:780px;
object-fit: cover;
background-repeat: no-repeat;
background-position: center;
transition: background-image 0.3s;
display: flex;
justify-content: center;
align-items: center;
}
.content-overlayslider
{
width:988px;
border-radius: 5px;
}
.content-overlayslider .heading
{
padding:32px 54px;
background-color: #225BC0;
border:1px solid #225BC0;
border-radius: 5px;
border-bottom: none;
}
.content-overlayslider .heading h2
{
font-size: 48px;
color:#fff;
}
.content-overlayslider .hover-item
{
padding:24px 54px;
background-color: #fff;
border-bottom: 1px solid #225BC0;
display:flex;
align-items: center;
gap: 80px;
align-self: stretch;
cursor: pointer;
}
.content-overlayslider .hover-item:last-child {
border-bottom: none;
}
.hover-item .content
{
color: #225BC0;
/* H5 – Desktop */
font-family: 'Archia-medium', sans-serif;
font-size: 20px;
font-style: normal;
font-weight: 500;
line-height: normal;
flex: 1 0 0;
align-self: stretch;
transform: translateY(0); /* Default position */
transition: font-size 0.5s ease, transform 0.5s ease, opacity 0.5s ease;
}
.hover-item .description
{
flex: 1 0 0;
align-self: stretch;
opacity: 0;
}
.hover-item .content.active
{
font-size: 32px;
transform: translateY(-10px); /* Move upward */
opacity: 1;
}
.hover-item .description
{
font-size:18px;
color:#225BC0;
font-weight: 400;
font-family: 'Silka-regular', sans-serif;
line-height: 24.3px;
}
.hover-item .description.active
{
opacity:1;
}
make .hover-items responsive
/* Base styles for hover-item */
.content-overlayslider .hover-item {
padding: 24px 54px;
background-color: #fff;
border-bottom: 1px solid #225BC0;
display: flex;
align-items: center;
gap: 80px;
align-self: stretch;
cursor: pointer;
}
/* Last item without border */
.content-overlayslider .hover-item:last-child {
border-bottom: none;
}
/* Responsive adjustments */
@media (max-width: 1200px) {
.content-overlayslider .hover-item {
padding: 20px 40px; /* Reduce padding for smaller screens */
gap: 40px; /* Decrease gap between items */
}
}
@media (max-width: 992px) {
.content-overlayslider .hover-item {
padding: 16px 30px; /* Further reduce padding */
gap: 30px; /* Further decrease gap */
}
.hover-item .content {
font-size: 18px; /* Decrease font size */
}
.hover-item .description {
font-size: 16px; /* Decrease description font size */
}
}
@media (max-width: 768px) {
.content-overlayslider .hover-item {
flex-direction: column; /* Stack items vertically */
align-items: flex-start; /* Align items to the start */
padding: 12px 20px; /* Reduce padding */
gap: 20px; /* Adjust gap */
}
.hover-item .content {
font-size: 16px; /* Decrease font size */
}
.hover-item .description {
font-size: 14px; /* Decrease description font size */
}
}
@media (max-width: 576px) {
.content-overlayslider .hover-item {
padding: 10px 15px; /* Minimal padding for very small screens */
gap: 10px; /* Minimal gap */
}
.hover-item .content {
font-size: 14px; /* Further decrease font size */
}
.hover-item .description {
font-size: 12px; /* Further decrease description font size */
}
}
### Explanation:
– **Media Queries**: The styles inside the `@media` rules adjust the layout based on the screen size.
– **Padding and Gap**: As the screen size decreases, the padding and gap between the elements are reduced to fit the screen better.
– **Font Size**: Font sizes for both `.content` and `.description` are adjusted to maintain readability on smaller screens.
– **Flex Direction**: For screens smaller than 768px, the flex direction is changed to `column`, which stacks the items vertically.
These adjustments should help ensure that your `.hover-item` elements are responsive and look good on various screen sizes.