Edit: here is a CodePen with CSS / HTML
I spend the weekend creating a CSS card for a website, only to realize that it's not responsive, at all. I'm not very well versed in CSS or responsive design, so I am hoping someone with more experience can help me out. So far, I've tried playing around with the #media tag, but I have not had any success. This is the relevant CSS:
#import url('https://fonts.googleapis.com/css?family=Muli&display=swap');
* {
box-sizing: border-box;
}
body {
background: #ffffff;
font-family: 'Muli', sans-serif;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
min-height: 100vh;
margin: 0;
}
.courses-container {
}
.course {
background-color: #fff;
border-radius: 10px;
box-shadow: 0 10px 10px rgba(0, 0, 0, 0.2);
display: flex;
max-width: 100%;
margin: 20px;
overflow: hidden;
width: 1300px;
}
.course h6 {
opacity: 0.6;
margin: 0;
letter-spacing: 1px;
text-transform: uppercase;
}
.course h2 {
letter-spacing: 1px;
margin: 10px 0;
}
.course-preview {
background-color: #2a265f;
color: #fff;
padding: 30px;
max-width: 250px;
}
.course-preview a {
color: #fff;
display: inline-block;
font-size: 12px;
opacity: 0.6;
margin-top: 30px;
text-decoration: none;
}
.course-info {
padding: 30px;
position: relative;
width: 100%;
}
.right-container {
padding: 30px;
background-color: #fff;
width: 30%;
line-height: 200%;
}
.progress-container {
position: absolute;
top: 30px;
right: 30px;
text-align: right;
width: 150px;
}
.progress {
background-color: #ddd;
border-radius: 3px;
height: 5px;
width: 100%;
}
.progress::after {
border-radius: 3px;
background-color: #2a265f;
content: '';
position: absolute;
top: 0;
left: 0;
height: 5px;
width: 10%;
}
.progress-text {
font-size: 10px;
opacity: 0.6;
letter-spacing: 1px;
}
This is a simple suggestion, using CSS Grid. It's a two column card (as yours): the left column width-fixed (300px), the right column width-fluid. I've applied a little gap between them just to make my example clearer.
.card {
max-width: 1000px;
display: grid;
grid-template: "left right" / 300px 1fr;
background-color: #fed330;
border-radius: 10px;
height: 300px;
}
.card>* {
padding: 20px;
}
.left {
grid-area: left;
}
.right {
grid-area: right;
}
#media screen and (max-width: 700px) {
.card {
grid-template: "left" "right" / 100%;
}
}
<div class="card">
<div class="left">
Lorem ipsum....
</div>
<div class="right">
Lorem ipsum...
</div>
</div>
It could be a useful starting point.
#gaston
A good way to test and learn about CSS is to use the browser's "Inspect" feature, with which you can test the css behavior in real time.
Activating, Deactivating features, changing values, and adding new ones.
You see the result in real time.
Then just adjust your code according to your tests.
Just right-click on the area you want to inspect. and then Inspect.
You will see an area with HTML and another with CSS.
Click on the areas in HTML and see the corresponding css.
***** Then just test to find the desired result.
That's how I found the solution in your code:
In the ".course" class of your css you added the "width" property twice.
"max-width: 100%;"
"width: 1000px;"
However, the last property entered has priority over the previous ones.
"width: 1000px;" is defining that your card will ALWAYS have 1000px.
SOLUTION:
Just remove: "max-width: 100%;"
And Modify "width: 1000px;" for "max-width: 1000px;"
So your card will have a maximum of 1000px, the minimum will be defined according to the width of the window
It will look like this:
.course {
background-color: #fff;
border-radius: 10px;
box-shadow: 0 10px 10px rgba (0, 0, 0, 0.2);
display: flex;
margin: 20px;
overflow: hidden;
max-width: 1000px;
}
The #media function will set the css when the screen is adjusted to a minimum or maximum width chosen by you.
What is defined within #media will have priority over other css. but only when the window meets the width you set.
You can use this to change the shape of your card completely to very small screens, placing the purple part on top of the card for example.
If you've solved your problem, mark the right answer to help others.
Good luck.
Related
Been attempting to layer and image over the top left corner of a div container; iv achieved it once but it didn't stick to position if the page was adjusted!
^^ This is what im redesigning
^^ This is what ive managed to design myself
I have come across different posts and answers suggesting that I try to use:
display: block, relative
position: block, relative
margins, float: start
In the end I am stumped an have resorted to removing most displays besides for the p tags an its composed container:
This is the CSS I have been trying to use to make this happen
.roadmap__section__container {
display: flex;
flex-direction: column;
width: 100%;
height: 100%;
min-height: 100%;
max-height: 100%;
background-color: #383636;
align-items: center;
}
.roadmap__header {
font: 3rem "Nunito";
margin: 3% 50% 3% 50%;
}
.roadmap__phase__one {
width: 100%;
height: 100%;
}
.phase__one__img {
width: 10%;
position: absolute;
margin-left:10%;
}
.phase__one__data {
display: flex;
flex-direction: column;
width: fit-content;
height: fit-content;
align-items: flex-start;
justify-content: center;
text-align: center;
padding: 25px;
margin: 0% 5% 5% 15%;
box-shadow: 1px 1px 40px #ff00e6;
outline-color: #ff00e6;
outline-offset: 0px;
outline-style: solid;
outline-width: 3px;
border-radius: 25px;
}
.phase__one__data p {
font-size: 1.75rem;
color: #fff;
font-family: "Nunito", serif;
padding: 5px 10px;
}
Here is the HTML Code used for my redesign:
<section class="roadmap__section__container">
<h1 class="roadmap__header">Roadmap</h1>
<div class="roadmap__phase__one">
<img class="phase__one__img" src="images/CasinoWRLD__dice1" alt="">
<div class="phase__one__data">
<p>- Working To Perfect The NFT Artwork.</p>
<p>- Finalise The Marketing Plan.</p>
<p>- Plan And Develop Casino WRLD.</p>
</div>
</div>
</section>
.phase__one__img {
grid-column: 3;
width: 11%;
position: absolute;
top: 157.5%;
right: 32%;
}
.phase__zero__img {
grid-column: 1;
width: 11%;
position: absolute;
margin-left: 5%;
top: 119.75%;
}
I've found this to work currently but it is not a 100% answer, if the browser height is adjust the settings regarding ''top:157.5%'' needs to be adjusted accordingly or it will not line up with the top-left corner of the div container
The difference in the two is pertaining to it switches back and forth going down the page
I am trying to create a part of my website,
Here is the code:
import React from 'react';
import './stylesheets/BeyondHelloWorld.css';
import BHW from './assets/bhw.png';
function BeyondHelloWorld() {
return (
<div className="mainDiv">
<div className="card">
<div className="cardContainer">
<div style={{height: "100%", display: "block"}}>
<img src={BHW} className="bhwImage"/>
</div>
<div class="bhwText">
<span className="bhwTitle">BeyondHelloWorld</span>
<span className="fadedTitle">Beyond</span>
<span className="bhwDescription">BeyondHelloWorld is a learning community for budding programmers. It is aimed at equipping amateurs with easy knowledge of the tech world through engaging content like New Tech information, tips & tricks & BTS of a developers life!</span>
<span className="bhwDescription">A lot of community problems can be solved using technology. BeyondHelloWorld aims to influence non-programmers into the world of programming.</span>
</div>
</div>
</div>
</div>
)
}
export default BeyondHelloWorld
If you see the span bhwDescription, it is inside bhwText div which is inside cardContainer.
Now I have a picture on the left with classname bhwImage
When the text exceeds the height of this image, the text starts from the left of the cardContainer, but I want it to start from the starting edge of the bhwText.
Example:
But with my code, What it looks like:
What am I doing wrong?
Also, if you notice, the fadedTitle and bhwTitle are not exactly aligned. I want them all to start where the picture starts. But something is going off. Even if I keep the padding/margin same, even then they have different starts.
Here is the css:
.mainDiv {
width: 100%;
padding: 50px;
background-color: #1e3512;
}
.card {
background-color: #1e3512;
box-shadow: 5px 5px 20px 0px rgba(0, 0, 0, 0.48);
padding: 0;
overflow: hidden;
}
.cardContainer {
margin: 0;
padding: 0 20px 0 0;
width: 100%;
}
.bhwImage {
height: 18vh;
object-fit: contain;
margin: 40px;
border: 5px solid #fff;
float: left;
}
.bhwText {
margin-top: 20px;
color: #ffffff;
}
.bhwTitle {
font-size: 3.5rem;
font-weight: 600;
display: block;
margin-bottom: 20px;
}
.fadedTitle {
position: absolute;
top: 25px;
font-size: 150px;
line-height: 75px;
opacity: 0.1;
font-weight: 900;
}
.bhwDescription {
display: block;
margin-bottom: 20px;
font-size: 1.8rem;
font-weight: 500;
word-wrap: break-word;
}
Add display:flex to your .cardContainer class
.cardContainer {
margin: 0;
padding: 0 20px 0 0;
width: 100%;
display: flex;
}
and remove width:100% from .mainDiv class
.mainDiv {
/* width: 100%; */ remove this
padding: 50px;
background-color: #1e3512;
display: flex;
}
Live Demo
The reason why the content runs underneath the image is because its style is float: left;, and your .bhwText class has a width of 100% because it's a block element. div elements are generally display: block; by default. This means .bhwText width is 100% of the parent container by default. The text will fill up space where available in it's container; including below the image.
To fix this issue, add left padding to the .bhwText class. Something like this example here.
.bhwText {
margin-top: 20px;
color: #ffffff;
padding: 0 0 0 200px;
}
I am making an accordion menu whereby I am adding a PDF inside an object element. However I just cannot get the object to show 100% of its height, therefore it makes it difficult to use.
All I would like is to know how to make the PDF file inside of the object div to show it's full height. I remember having similar issues with footers..
Thanks.
if( jQuery(".toggle .toggle-title").hasClass('active') ){
jQuery(".toggle .toggle-title.active").closest('.toggle').find('.toggle-inner').show();
}
jQuery(".toggle .toggle-title").click(function(){
if( jQuery(this).hasClass('active') ){
jQuery(this).removeClass("active").closest('.toggle').find('.toggle-inner').slideUp(200);
} else {
jQuery(this).addClass("active").closest('.toggle').find('.toggle-inner').slideDown(200);
}
});
body {
color: #4B4B4B;
font-family: ARIMO;
}
body a {
cursor: pointer;
color: #4B4B4B;
text-decoration: none;
}
body section {
margin-bottom: 90px;
}
body section h1 {
text-transform: uppercase;
text-align: center;
font-weight: normal;
letter-spacing: 10px;
font-size: 25px;
line-height: 1.5;
}
object{
width: 100%;
height: 100%;
display: block;
position: relative;
min-height: 100%;
}
/* Styles for Accordion */
.toggle{
background: #eee;
border-top: solid 1px #3b7c8e;
margin-bottom: 50px;
width: 80%;
height: 100%;
}
.toggle .toggle-title {
position: relative;
display: block;
margin-bottom: 6px;
}
.toggle .toggle-title h3 {
font-size: 20px;
margin: 0px;
line-height: 1;
cursor: pointer;
font-weight: 200;
}
.toggle .toggle-inner {
padding: 7px 25px 10px 25px;
display: none;
margin: -7px 0 6px;
max-width: 100%;
max-height: 100%;
min-height: 100%;
}
.toggle .toggle-inner div {
max-width: 100%;
max-height: 100%;
min-height: 100%;
}
.toggle .toggle-title{
display: block;
padding: 25px 25px 14px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="toggle">
<div class="toggle-title">
<h3>
<div class="title-name">Example title</div>
</h3>
<p>Example call for paper</p>
<p>Astronomers face an embarrassing conundrum: they don't know what 95% of the universe is made of. Atoms, which form everything we see around us, only account for a measly 5%. Over the past 80 years it has become clear that the substantial remainder is comprised of two shadowy entities – dark matter and dark energy. The former, first discovered in 1933, acts as an invisible glue, binding galaxies and galaxy clusters together. Unveiled in 1998, the latter is pushing the universe's expansion to ever greater speeds. Astronomers are closing.</p>
</div>
<div class="toggle-inner">
<object height="100" data="http://prototypes.infopro-insight.com/test/MW/call_for_papers.pdf"></object>
</div>
</div><!-- END OF TOGGLE -->
As part of my HTML5/CSS3 app, I need to implement zoomable image popup. When the user clicks on a small image, a full-screen popup appears containing that image in the middle with a title above it and a button to close the popup below it. Clicking on the image then removes any scaling and puts it full-size inside a box in the middle to allow scrolling - with title and "close" button staying above and below.
I'm using flex (for several reasons, including vertical centering content). The overall popup works and looks fine. Clicking on the image does increase it in size, but it resizes the box so that the "done" button is pushed below the overall popup.
Here's the jsfiddle demonstrating the issue
I don't mind the fact that the box resizes - the more room to view/scroll the larger image - but I need to ensure that the button at the bottom stays put relative to the bottom edge of the popup.
My HTML looks like this (I used a random image for demonstration):
<div id="overlay" class="hidden">
<div id="alsg">
<div class="intro">Assist with ALS</div>
<div class="box scrollable">
<img src="http://upload.wikimedia.org/wikipedia/commons/8/8c/Male_monarch_butterfly.JPG" class="fit" />
</div>
<div class="popup-buttons">
<div id="button-alsg-done" class="button button-state-action button-green right">Done</div>
<div class="clear"></div>
</div>
</div> <!-- alsg -->
</div>
With the javascript being
$('img', '#alsg').on('click', function(e) {
$(this).toggleClass('fit');
});
There's a lot of CSS, unfortunately. You'll note that there's a pretty bad mix of flex and old-school positioning. This is because the app initially didn't use flex at all and I'm in a slow process of migrating/cleaning up now.
div#overlay {
position: absolute;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
z-index: 104;
display: flex;
align-items: center;
justify-content: center;
}
div#overlay > div {
position: relative;
width: calc(100% - 40px);
margin: 10px auto;
background-color: #A9A9A9;
border-radius: 8px;
text-align: center;
padding: 10px;
display: flex;
flex-direction: column;
}
div#alsg {
max-height: calc(100% - 40px) !important;
}
div#overlay div.intro {
color: #FFF !important;
font-size: 12pt;
margin-bottom: 10px;
}
div#overlay div.box, div.template div.box {
padding: 3px 5px;
overflow: hidden;
font-weight: bold;
position: relative;
flex-grow: 1;
}
div#alsg div.box {
text-align: center;
position: relative;
overflow: auto !important;
margin: 10px 0px 0px !important;
}
div.box {
background-color: #FFF;
color: #27374A;
border-radius: 8px;
border: 3px solid #FBE96E;
position: relative;
margin: auto;
flex-shrink: 1;
}
.fit {
max-width: calc(100% - 4px) !important;
max-height: calc(100% - 4px) !important;
}
div.popup-buttons {
margin-top: 10px;
}
#overlay .button.right {
margin-left: 10px;
}
#button-alsg-done {
margin-top: 10px;
flex-basis: 25px;
}
div.button-green {
background-color: #2CC55D;
color: #FFF;
font-weight: bold;
}
div.button-state-action {
height: 25px;
padding: 0px 5px;
line-height: 25px;
text-align: center;
border-radius: 4px;
font-size: 10pt;
font-weight: normal !important;
width: 60px;
cursor: pointer;
margin-bottom: 5px;
}
div.button {
height: 22px;
padding: 0px 2px;
line-height: 22px;
text-align: center;
border-radius: 4px;
font-size: 9pt;
width: 42px;
cursor: pointer;
white-space: nowrap;
overflow: hidden;
}
.right {
float: right;
}
.clear {
clear: both;
}
So I have this code here: http://jsfiddle.net/nUwgX/ which has a little arrow at the bottom. What I'd like to happen is when the window get's resized is to keep the arrow about 15% from the bottom of the screen but I'm not sure how I'd do that. Any help would be appreciated.
HTML:
<div class = "container">
<div class = "top-wrapper">
<a id = "name" href = "#">Bigfoot Games</a>
</div>
<div class = "bottom-wrapper">
<p>Content</p>
</div>
</div>
CSS:
.container {
width: 100%;
height: 100%;
margin: 0 auto;
position: relative;
padding: 0;
text-align: center;
}
.top-wrapper {
position: relative;
background: #0f0f0f;
height: auto;
height: 100%;
max-height: 900px;
width: 100%;
margin: 0 auto;
padding: 0;
display: table;
}
.top-wrapper:after {
top: 100%;
left: 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
border-color: rgba(15, 15, 15, 0);
border-top-color: #0f0f0f;
border-width: 30px;
margin-left: -30px;
}
#name {
display: table-cell;
text-align: center;
vertical-align: middle;
padding: 20px;
color: white;
font-size: 80px;
text-decoration: none;
margin: auto 0;
}
.bottom-wrapper {
background: white;
margin: 0 auto;
padding: 20px;
}
Edit: Okay, so saying that I wanted the arrow about 15% above is not what I meant! Ha! What I mean is, I want the .top-wrapper to be 100% so that it covers the whole window, and you scroll down to see the .bottom-wrapper - however when the screen is resized (other than my 1920 x 1080 resolution) the arrow get's hidden just out of sight, what I'd like is the arrow to be visible regardless of resolution and have the look (in terms of padding/distance) as a 1920 x 1080 resolution.
Change the css of .top-wrapper to only take up 85%, that leaves 15% for the "arrow" on the bottom to take up.
.top-wrapper {
...
height: 85%;
...
}
see the jsfiddle:
http://jsfiddle.net/nUwgX/1/
Change your .top-wrapper height to 85%
I changed just that in the jsfiddle and it maintains when the screen is resized. If that isn't what you are looking for, please elaborate on the question.
Good Luck!
If you want to keep your bottom-wrapper at the bottom fixed position ...
Replace your .bottom-wrapper class with below
.bottom-wrapper {
position:fixed;
bottom: 0px;
height: 15%;
width: 100%;
background-color: white;
margin: 0 auto;
}
.bottom-wrapper p{
padding-top: 20px;
}
Then change .top-wrapper:after to .bottom-wrapper:before