I am new to HTML and CSS and I am working on a Page here for school.
I don't know how i can adjust the size of my figures Schutzklasse 1-3 with their Text. If you Zoom the text gets smaller but the basic picture not.
You dont need everything in the CSS because i have more pages. I just need help on my main page.
I tried things like width or margin and text align but it didn't work. I don't know what to do then.
I hope u can help me.
figure,
figcaption {
margin: 0;
padding: 0;
}
.gallery {
display: block;
text-align: center;
}
#gallery {
display: grid;
grid-template-columns: repeat(3, minmax(7em, 1fr));
gap: 10%;
text-align: center;
margin-left: 10%;
margin-right: 10%;
}
#gallery figure {
position: relative;
color: black;
background: white;
}
figure img {
width: 100%;
position: relative;
display: block;
}
#gallery>figure>figcaption {
position: absolute;
bottom: 0em;
width: 100%;
line-height: 2.1em;
color: white;
background: rgba(0, 0, 0, 0.7);
}
#gallery>figcaption {
grid-column: 1 / -1;
}
#gallery>figure>figcaption {
opacity: 0.4;
bottom: -3em;
transition: all 0.1s ease;
}
#gallery>figure:hover>figcaption {
opacity: 1;
bottom: -2em;
}
.m1 {
border: 3px solid #4CAF50;
padding: 5px;
margin-left: 15%;
margin-right: 15%;
margin-top: 5%;
margin-bottom: 5%;
}
.img1 {
float: right;
}
.m1::after {
content: "";
clear: both;
display: table;
}
.img1 {
height: 30%;
width: 300px;
margin-top: 2%;
margin-bottom: 4%;
margin-left: 4%;
}
.ans1 {
display: inline-block;
width: 320px;
padding: 20px;
border: 5px solid gray;
margin: 10px;
}
.a1 {
margin-left: 15%;
margin-right: 15%;
}
h2 {
margin-left: 3%;
}
ul {
margin-left: 5%;
margin-top: 8%;
}
body {
color: rgba(50, 50, 50, 1.0);
background: rgba(200, 200, 200, 0.825);
}
h1 {
text-decoration: underline;
text-decoration-color: blueviolet;
text-align: center;
margin-bottom: 2em;
}
b {
text-decoration: underline;
}
h3 {
text-shadow: 2px 2px rgb(255, 255, 255);
text-align: center;
margin-bottom: 2em;
}
h4 {
text-decoration: underline;
text-align: center;
margin-bottom: 2em;
}
<h1>Der VDE Guide</h1>
<p> </p>
<h3>Bitte wählen Sie eine der Schutzklassen:</h3>
<div class="gallery">
<figure id="gallery">
<figure>
<a href="messungSK1.1.html">
<img id="sk1" src="schutzklasse1.png">
</a>
<figcaption>Schutzklasse 1</figcaption>
</figure>
<figure>
<a href="messungSK2.1.html">
<img id="sk2" src="schutzklasse2.png">
</a>
<figcaption>Schutzklasse 2</figcaption>
</figure>
<figure>
<a href="messungSK3.1.html">
<img id="sk3" src="schutzklasse3.png">
</a>
<figcaption>Schutzklasse 3</figcaption>
</figure>
</figure>
</div>
[Ctrl-MouseScroll] or [Ctrl+]/[Ctrl-] (browser functionality) act differently compared to resizing the browser. Using the [Ctrl] zooming functions, the browser will act as if it is a different (larger/smaller) device, while resizing the the browser window just changes the available space on the given device (for now, I'm assuming your development desktop PC). This means that when you deeply zoom-in you are essentially looking at a very large smartphone.
With your CSS img {...width: 100%... } you want to scale the images to fill the maximum of the available space (on a very large smartphone), while you want the zooming to literally resize them. I don't know the technical specifics behind this, but you simply cannot have both.
So you need to choose either resize to fit and discard the zooming, or enable zooming and leave out the img {...width: 100%... } and replace it with:
figure img {
display: block; /* removes unwanted space below (default 'inline') */
object-fit: cover; /* resize and clip when too large (change to your needs) */
max-width: 100%; /* dont' go outside parent ('overflow: hidden' won't work) */
margin: 0 auto /* center horzontally in parent */
}
I have created a snippet with your code in which I added my solution, but also changed/simplified a few things:
for clarity removed unused CSS
also for clarity, moved EYE-CANDY only properties to their own section. Less optimized, but more clear CSS for the demo.
heavily commented CSS where applicable
you used <figure>s inside a <figure>, while totally legal, it unnecessarily complicated the structure of .gallery. I removed the extra layer.
changed the original grid-template-columns 3 to auto-fit so the grid nicely wraps when the viewport becomes too narrow.
corrected the gap error to grid-gap
changed the .gallery margins to padding and used margin to horizontally center .gallery
changed background to background-color where applicable. While background is legal, it is also a shortcut property for various background settings. This becomes particularly important when you want to blend/mix background-color with background-image. In specific cases background overrides one of them (depending on how you defined the CSS) obfuscating a nice little bug that could keep you busy for a while. Just get used to using background-color.
Do try out <body outlines="1"> as you will learn from the output that you have overlapping elements issues that might need to be addressed!
And the zooming now works as you want...
The snippet
/* for debugging */
[outlines="1"] * { outline: 1px dotted }
figure,figcaption { margin: 0; padding: 0 }
figure img {
display: block; /* removes unwanted space below (default 'inline') */
object-fit: cover; /* resize and clip when too large (change to your needs) */
max-width: 100%; /* dont' go outside parent */
margin: 0 auto /* center horzontally in parent */
}
.gallery {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(7em, 1fr)); /* changed 3 to 'auto-fit' */
/* original 7em, now in pct of 1920 (average desktop) => 7 * 16 / 19.2 */
grid-gap: 10%; /* MOD, was 'gap' */
text-align: center;
padding: 0 10%; /* 10% L/R space */
margin: 0 auto /* center in parent */
}
.gallery figure {
position: relative;
/* some spacing after wrap */
margin-bottom: 2em; /* modify to your needs */
}
.gallery>figure>figcaption {
position: absolute;
width: 100%;
line-height: 2.1em;
color: white;
background: rgba(0, 0, 0, 0.7);
bottom: -3em; opacity: 0.4;
transition: all 0.1s ease;
}
.gallery>figure:hover>figcaption {
bottom: -2em; opacity: 1;
}
/******************/
/* EYE-CANDY only */
/******************/
.gallery figure {
color: black; background-color: white;
}
.gallery>figure>figcaption {
color: white; background-color: rgba(0, 0, 0, 0.7);
}
body {
color: rgba(50, 50, 50, 1.0); background-color: rgba(200, 200, 200, 0.825);
}
h1 {
text-decoration: underline;
text-decoration-color: blueviolet;
text-align: center;
margin-bottom: 2em;
}
h3 {
text-shadow: 2px 2px rgb(255, 255, 255);
text-align: center;
margin-bottom: 2em;
}
<body outlines="0">
<h1>Der VDE Guide</h1>
<p> </p>
<h3>Bitte wählen Sie eine der Schutzklassen:</h3>
<div class="gallery">
<figure>
<a rel="noopener" target="_blank" href="messungSK1.1.html">
<img id="sk1" src="https://via.placeholder.com/200/DC143C/FFF8DC?text=schutzklasse1">
</a>
<figcaption>Schutzklasse 1</figcaption>
</figure>
<figure>
<a rel="noopener" target="_blank" href="messungSK2.1.html">
<img id="sk2" src="https://via.placeholder.com/200/7CFC00/000000?text=schutzklasse2">
</a>
<figcaption>Schutzklasse 2</figcaption>
</figure>
<figure>
<a rel="noopener" target="_blank" href="messungSK3.1.html">
<img id="sk3" src="https://via.placeholder.com/200/6495ED/FFF8DC?text=schutzklasse3">
</a>
<figcaption>Schutzklasse 3</figcaption>
</figure>
</div>
</body>
Related
I am making a copy of The Boring Company website to get a bit practise and I ran into a text problem.
The site consists of one section that contains a header with nav and below the header, there is a div that contains a title and some text. The problem is that upon resizing the browser window, the text starts getting pushed inside the header.
How the site normally looks
How it looks after resizing the browser window
Is there any way to prevent this, please? Thanks in advance!
/* GENERAL */
* {
padding: 0;
margin: 0;
}
body, html {
height: 100%;
}
body {
box-sizing: border-box;
}
img {
max-width: 100%;
height: auto;
}
.layout {
background: rgba(0, 0, 0, 0.37);
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
/* SECTIONS */
main, section {
box-shadow: inset 0px -40px 50px 30px #000000;
height: 100Vh;
position: relative;
padding-top: -1px;
color: white;
}
.tunnels2-section {
background: url("/IMGs/tunnels2-section.jpg");
background-size: cover;
background-attachment: fixed;
background-position: center;
}
/* HEADER AND NAV */
header {
background: black;
padding: 0.1em;
}
nav {
display: flex;
align-items: center;
justify-content: space-between;
margin: 1em 5em;
font-family: 'Ropa Sans', sans-serif;
font-weight: bold;
}
.burger {
position: absolute;
right: 1%;
top: 2%;
display: none;
}
.burger div {
width: 25px;
height: 2px;
margin: 5px;
background-color: white;
border: 1px solid black;
}
.main-nav-items {
display: flex;
align-items: center;
}
.main-nav-item, .side-nav-item {
display: inline-block;
margin: 0em 0.6em;
}
li a {
color: white;
text-decoration: none;
}
/* MAIN CONTENT */
.boring-company-info {
position: absolute;
bottom: 28%;
margin: 0em 6em;
font-size: 0.7em;
font-family: "Roboto", sans-serif;
color: white;
opacity: 1;
transition: 0.5s ease;
transform: translateY(20px);
}
h2 {
margin-bottom: 0.2em;
}
.info-title {
font-size: 3em;
font-weight: 600;
margin-bottom: 0.65em;
}
.info-description {
line-height: 20px;
font-size: 1.55em;
font-weight: 500;
width: 55%;
}
.tunnels-info-description {
font-size: 1.38em;
font-weight: 100;
line-height: 22px;
width: 65%;
}
b {
font-weight: 700;
}
#media screen and (max-width: 915px) {
.burger {
display: block;
}
.main-nav-item a, .side-nav-item a {
display: none;
}
nav {
margin: 0;
}
.boring-company-desc {
margin: 0em 2em;
}
h2 {
margin-top: 0.7em;
}
}
#media screen and (max-width: 641px) {
.boring-company-info {
margin: 0em 2em 0em;
}
/* This fixes the issue, but only temporarily. It still overflows to
the header above it. */
.info-description {
width: 100%;
}
}
<section class="tunnels2-section">
<div class="layout">
<header>
<nav>
<ul class="main-nav-items">
<li class="main-nav-item"><img src="IMGs/company-logo.png" width=115px class="company-logo" alt="Logo of the Boring Company"></li>
<li class="main-nav-item">TUNNELS</li>
<li class="main-nav-item">PRODUCTS</li>
<li class="main-nav-item">PROJECTS</li>
<li class="main-nav-item">PRUFROCK</li>
<li class="main-nav-item">LOOP</li>
</ul>
<ul class="side-nav-items">
<li class="side-nav-item">CAREERS</li>
<li class="side-nav-item">FLAMETHROWER</li>
</ul>
<div class="burger">
<div class="line1"></div>
<div class="line2"></div>
<div class="line3"></div>
</div>
</nav>
</header>
<div class="boring-company-info" id = "why-tunnels">
<h1 class="info-title">WHY TUNNELS?</h1>
<p class="tunnels-info-description info-description"><b>Solve traffic: </b>to solve the problem of soul-destroying traffic, roads must go 3D. Surface roads today incorporate 3D model-like elevated highways and cloverleaf interchanges that are expensive and disruptive to build. Tunneling networks are 3D and provide high-throughput transportation in an economically viable way. Traffic and congestion will be a thing of the past. </p>
<p class="tunnels-info-description info-description"><br><b>Beautify our cities:</b> existing transportation networks occupy valuable space in cities where land availability is scarce. Tunnels minimize usage of surface area and could move entire transportation networks underground. Taking transportation underground allows us to repurpose roads into community-enhancing spaces, and beautify our cities.</p>
<p class="tunnels-info-description info-description"><br><b>Enable HyperLoop:</b> Hyperloop networks unlock high-speed regional transportation surpassing other alternatives. Hyperloop enables access to individualized, point to point high-speed transportation.</p>
</div>
</div>
</section>
You will need to add this to the appropriate breakpoint.
main, section {height: auto;}
I would try to avoid using position: absolute on the .boring-company-info class as that can create theses sorts of conflicts.
If you're looking to position it on the page in a certain way, consider adjusting the padding or margins of the elements on the page or look into using flex. https://css-tricks.com/snippets/css/a-guide-to-flexbox/
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.
What is the best way to have an image on top of a card with content underneath it?
I have tried negative margins but I have had no luck on with this approach.
I attached an image of what the look and feel I am going for:
Here is my attempt on code
.card {
text-decoration: none;
margin-right: 20px;
text-align: center;
}
.card__section {
overflow: hidden;
padding-bottom: 50px;
display: block;
position: relative;
}
.card__inner {
background: black;
padding: calc(35px + 30%) 35px 35px;
color: white;
width: 100%;
display: block;
position: relative;
}
.card__image {
width: 80%;
height: auto;
margin: 0 auto -30%;
position: relative;
z-index: 1;
}
<a href="#" class="card">
<section class="card__section">
<img
class="card__image"
src="http://via.placeholder.com/340x220"
alt=""
/>
<div class="card__inner">
<h1>
This is a static template, there is no bundler or bundling
involved!
</h1>
</div>
</section>
</a>
you need to add below css
.card__section {
overflow: visible;
}
.card__image {
margin-bottom: 20px;
margin-top: -100px;
}
section.card__section {
margin-top: 60px;
}
and put your image in card__inner div
see https://codesandbox.io/s/card-hover-5n0yf?file=/index.html:450-461
hope this helps
You're almost there! There are two things that need to be updated:
1. Remove extra % in .card__image
.card__image {
width: 80%;
height: auto;
margin: 0 auto -30%%; // <-- Remove extra % at the end.
position: relative;
z-index: 1;
}
2. Adjust padding in .card__inner due to negative margin on previous element.
.card__inner {
background: black;
// Update padding to below. Negative margin on previous element needs to be added to the top padding.
padding: calc(35px + 30%) 35px 35px;
color: white;
width: 100%;
display: block;
position: relative;
}
Sandbox: https://codesandbox.io/s/card-hover-wiilf
I need to create an image lightbox. I basically started from this example from w3school, https://www.w3schools.com/howto/howto_js_lightbox.asp
However, it doesn't work for portrait oriented images. Eg. a landscape image is 1200x800 and a portrait can be 800x1200.
I need the images to resize responsive and work for both horizontal and vertical images.
It needs to work for all modern browsers, ios, android and also IE11.
you'll see I've added "max-width: 1200px;" to lightbox-content, which does the trick for horizontal images... but since a vertical image is 800 wide, it enlarges and the height exceeds.
<div class="lightbox">
<span class="close" onclick="closeLightbox()">×</span>
<div class="lightboxTitle">My Title</div>
<div class="lightbox-content">
<div class="slide"><img src="img1.jpg"></div>
<div class="slide"><img src="img2.jpg"></div>
<div class="slide"><img src="img2.jpg"></div>
<!-- Next/previous controls -->
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
</div>
/* The Modal (background) */
.lightbox {
display: none;
position: fixed;
z-index: 99999999;
padding-top: 60px;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
}
/* Modal Content */
.lightbox-content {
position: relative;
margin: auto;
padding: 0;
width: 100%;
max-width: 1200px;
}
.lightboxTitle {
position: absolute;
top: 20px;
left: 25px;
font-size: 20px;
}
/* The Close Button */
.close {
color: white;
position: absolute;
top: 10px;
right: 25px;
font-size: 35px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #FF8511;
text-decoration: none;
cursor: pointer;
}
/* Hide the slides by default */
.slide {
display: none;
}
.slide img {
width: 100%;
}
/* Next & previous buttons */
.prev,
.next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
padding: 16px;
margin-top: -50px;
color: white;
font-weight: bold;
font-size: 20px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
-webkit-user-select: none;
}
/* Position the "next button" to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
.prev {
left: 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);
color: #FF8511;
}
I had the same issue in one of my past projects. I solved it with this js library https://imagesloaded.desandro.com/,
It allows you to process the images after they are loaded, and you can then assign a css class to it according to the aspect ratio.
$('#container').imagesLoaded( function() {
// images have loaded
// check image height/width > 1, portrait
// check image heidht/width <= 1, square or landscape
// assign different classes for each case to handle
});
css:
.img-container {
//do whatever you need on the container
}
// keep the image classes like this
.img-container img.portrait {
height: 100%;
width: auto;
}
.img-container img.landscape {
width: 100%;
height: auto;
}
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 -->