Absolute position in CSS - html

I'm new to CSS and I'm trying to place some dots at position 0,0 of it's parent div, but when I do so according to the below code, the dots disappear.
* CSS Code: *
.timeslot{
background-color: green;
border-top: solid gray;
}
.timeslot.selected{
border: #cc0000;
}
.timeslot.selected .dot{
background-color: #cc0000;
}
.timeslot .dot{
background-color: gray;
}
.dot {
position: absolute;
height: 25px;
width: 25px;
background-color: firebrick;
border-radius: 50%;
display: inline-block;
}
.square {
height: 25px;
width: 40px;
background-color: #555;
}
.dot .span {
padding-top: 8px;
}
.time-line-box {
height: 100px;
padding: 50px 0;
width: 100%;
/* background-color: burlywood;*/
}
.swiper-container {
width: 95%;
margin: auto;
overflow-y: auto;
}
.swiper-wrapper{
display: inline-flex;
flex-direction: row;
overflow-y:auto;
justify-content: center;
border-top-width: 20px;
}
.swiper-container::-webkit-scrollbar-track{
background:#a8a8a8b6;
}
.swiper-container::-webkit-scrollbar{
height: 2px;
}
.swiper-container::-webkit-scrollbar-thumb{
background: #4F4F4F !important;
}
.swiper-slide {
text-align: center;
font-size: 12px;
width: 50px;
height: 100%;
/*position: relative;*/
}
* HTML Code: *
<section class="time-line-box">
<div class="swiper-container text-center">
<div class="swiper-wrapper">
<div *ngFor="let time of dropDownArray" class="timeslot swiper-slide">
<div class="dot" [style.background-color]="getBackgroundColor(time)"><span>{{time.label}}</span></div>
</div>
</div>
</div>
</section>
I'm trying to place each dot at the absolute position of it's parent div timeslot . I might be missing something but I really tried everything I know. Hope to find some help.

Add position relative to your parent
.timeslot{
// ...
position: relative;
}

Related

How can I add a footer at the end of this website?

I am trying to create a footer at the end of this website but for some reason it appears above the products :
And when I change the browser size :
But I want a footer like this :
Here is my code :
HTML :
{% load static %}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="{% static 'main.css' %}">
</head>
<body style="background-color: #36454F;">
{% for i in p%}
<div class='card'>
<div class="number">{{i.Number}}</div>
<img src="{{i.image}}"></img>
<p id="id">{{i.description}}</p>
<a href="{{i.buy}}" target='_blank' rel='noopener noreferrer'>
<button><span class="price"> ${{i.price}}</span> buy</button>
</a>
</div>
{%endfor%}
<div class="footer">
<h3>hello</h3>
</div>
</body>
</html>
CSS :
.card {
max-width: 400px;
margin: 0auto;
text-align: center;
font-family: arial;
border-style: solid;
border-width: 6px;
position: relative;
top: 611px;
margin-bottom: 33px;
margin-right: 33px;
justify-content: center;
float: left;
}
.footer {
position: relative;
height: 130px;
clear: both;
background-color: red;
}
.card img {
height: 400px;
width: 400px;
vertical-align: middle;
}
.price {
background-color: #f44336;
font-size:22px;
border-radius: 3px;
position: absolute;
bottom: 0px;
right: 0px;
padding: 3px;
}
.card button {
border: none;
color: white;
background-color: #000;
position: relative ;
cursor: pointer;
width: 100%;
height: 100px;
font-size: 44px;
align-items: center;
}
.card button:hover {
opacity: .5;
background-color: #330;
}
#id {
background-color: palevioletred;
color: white;
margin: 0;
font-size: 17px;
}
.number {
width: 50px;
height: 50px;
background-color: #330;
color: yellow;
border-radius: 50%;
position: absolute;
top: -22px;
right: -22px;
justify-content: center;
align-items: center;
display: flex;
font-size: 22px;
}
#media (max-width: 1864px) {
.card {
max-width: 300px;
}
.price {
font-size:20px;
}
.card img {
height: 300px;
width: 300px;
}
}
I tried to set a negative bottom property to push it to the end :
.footer {
position: relative;
bottom: -674px;
height: 130px;
clear: both;
background-color: red;
}
But it didn't help. How can i solve the problem?
To set the footer to the bottom of the page, you need to use this CSS:
.footer {
position:absolute;
bottom:0;
width:100%;
height:60px; /* Height of the footer */
background:#6cf; /* Set your own background */
}
If you want it to stay at the bottom of the page and stretch along the bottom, I'd do something like this with the CSS
.footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
background-color: (whatever you want);
color: (color of the text, whatever you want);
text-align: center; /*unless you want the text aligned differently*/
}
Also look up how to use the grid-container if you want the items of the footer in rows like the example you gave.
You need the footer tag to do its job!
Read more about the footer tag here:
https://www.geeksforgeeks.org/html5-footer-tag/
Reference: https://code-boxx.com/keep-html-footers-at-bottom/
The easy ways to keep a footer at the bottom with modern CSS are:
Use footer { position: fixed} or footer { position: sticky } to
keep the at the bottom.
Use a flexbox layout that "stretches" the body section, keep the
footer at the bottom.
body{ display: flex; flex-direction: column; }
main{ flex-grow: 1; }
Lastly, use a grid layout to achieve the same "stretch body
section".
<header>HEAD</header> <main>MAIN</main> <footer>FOOT</footer>
html, body { height: 100%;}
body { disply: grid; grid-template-rows: auto 1fr auto; }

How to responsively roll down area in CSS

I'm trying to add a text area with a white background:
I wanted the white area to be lower and further to the right.
.grey-zone {
color: white;
width: 100%;
height: 70vh;
background-color: #2f3e4d;
}
.whoami {
color: black;
width: 25%;
background-color: #ffffff;
padding: .5%;
}
.whoami p {
padding-top: 5%;
font-size: 105%;
}
<div class="grey-zone">
<div class="whoami">
<h1>Qui suis-je?</h1>
</div>
</div>
Does someone know how to do that?
Thanks
If you want to play in white space, you can flex your main container and move the contents around as you wish.
.grey-zone {
color: white;
width: 100%;
height: 70vh;
background-color: #2f3e4d;
display: flex;
align-items: end;
justify-content: end;
}
If you add the last 3 css codes I added, you will fix the white box to the bottom right.
One way is using from padding for .grey-zone:
.grey-zone {
box-sizing: border-box; /*here*/
color: white;
width: 100%;
height: 100vh;
background-color: #2f3e4d;
padding: 20px 0 0 20px; /*here*/
}
.whoami {
color: black;
width: 25%;
background-color: #ffffff;
padding: .5%;
}
<div class="grey-zone">
<div class="whoami">
<h1>Qui suis-je?</h1>
</div>
</div>
You can add this to you class .whoami
.grey-zone {
color: white;
width: 100%;
height: 100vh;
background-color: #2f3e4d;
}
.whoami {
color: black;
width: 25%;
background-color: #ffffff;
padding: .5%;
position: absolute;
top: 50px;
left: 20px;
}
<div class="grey-zone">
<div class="whoami">
<h1>Qui suis-je?</h1>
</div>
</div>

How can I align the text in the center of the image

I'm trying to center a text inside a div, this div contains an image + another div which contains the text that needs to be centered.
See image the following image:
The problem I'm facing is that the image which is also in the div doesn't allow me to outline the text in the center.
I tried to apply padding and margins(even negatives ones) however with no results
So right now this is the code I have in my HTML & CSS files:
.destinations {
padding: 5px 15px;
}
.destinations img {
max-width: 100%;
max-height: 100%;
border-radius: 10px;
}
.flex-item {
width: 290px;
height: auto;
border-radius: 10px;
margin: auto;
}
.flex-item-title {
text-align: center;
color: white;
background-color: black;
opacity: 0.8;
}
<div class="destinations">
<div class="flex-item">
<img src="assets/img/wassenaar.jpg">
<div class="flex-item-title">Wassenaar</div>
</div>
</div>
I hope you can help me out
Here is one approach to vertically and horizontally center the text over the image:
.destinations {
padding: 5px 15px;
}
.destination {
width: 290px;
height: 290px;
display: flex;
border-radius: 10px;
margin: auto;
background-image: url("https://placekitten.com/500/500");
justify-content: center;
align-items: center;
}
.title {
text-align: center;
color: white;
background-color: black;
opacity: 0.8;
}
<div class="destinations">
<div class="destination">
<div class="title">Wassenaar</div>
</div>
</div>
You can get your porblem solve using following css .
.flex-item{
width:300px;
height:200px;
position: relative;
padding: 0;
margin: 0;
text-align: center;
}
.flex-item-title{
position: absolute;
top: 0; right: 0;
bottom: 0; left: 0;
width: 300px;
height: 200px;
text-align: center;
color: white;
display: inline-table;
vertical-align:middle;
line-height:100%;
}
Try changing your css to this css , it will work .

stack the 2nd element first and then the 3rd element

I have three divs. I want them to be in one line so I used inline-block. When I resize the window the third element (nav) stacks and then the 2nd element (searchBar). I want the 2nd element stacks first and then the 3rd one. For undoing, the 3rd element and then the 2nd element.
body {
margin: 0px;
padding: 0px;
}
header {
width: 100%;
min-eight: 48px;
position: fixed;
background: #ffffff;
padding-bottom: 5px;
border-bottom: 2px solid #fed700;
}
nav {
width: 489.7px;
height: 18px;
background: red;
display: inline-block;
}
#searchBar {
width: 330px;
height: 16px;
background: blue;
display: inline-block;
white-space: nowrap;
}
#logo {
width: 220px;
height: 32px;
background: green;
display: inline-block;
}
<header>
<div id=logo>logo
</div>
<div id=searchBar>searchBar
</div>
<nav>nav
</nav>
</header>
You could use an inline-block wrapper with a min-width, wrapping the nav and searchBar. That would give the result you wanted in with the code sample supplied, but might cause problems in the real world, depending on your requirements.
body {
margin: 0px;
padding: 0px;
}
header {
width: 100%;
min-height: 48px;
position: fixed;
background: #ffffff;
padding-bottom: 5px;
border-bottom: 2px solid #fed700;
}
.wrapper {
min-width: 50%;
display: inline-block;
}
nav {
width: 489.7px;
height: 18px;
background: red;
display: inline-block;
}
#searchBar {
width: 330px;
height: 16px;
background: blue;
display: inline-block;
white-space: nowrap;
}
#logo {
width: 220px;
height: 32px;
background: green;
display: inline-block;
}
<header>
<div id=logo>logo
</div>
<div class="wrapper">
<div id=searchBar>searchBar
</div>
<nav>nav
</nav>
</div>
</header>

My links are no more clickable because it is behind other element

I need to present a header menu with 3 elements:
one is left aligned
one is centered
one is right aligned
I would like a gray background for this menu.
The problem: if I have links in my left or right elements and it is not clickable because of the centered element.
How to prevent this problem? or another way of having this kind of menu?
Any idea is highly appreciated.
jsFiddle: http://jsfiddle.net/sxmf0Lve/
<div class="headerContainer">
<div class="headerLeft">
Left
</div>
<div class="headerTitle">Middle</div>
<div class="headerRight">
Right
</div>
</div>
.headerContainer {
padding-top: 10px;
padding-left: 0px;
padding-right: 5px;
max-width: 100%;
height: 30px;
background-color: #fcfcfc;
border-bottom: 1px solid #f6f6f6;
}
.headerTitle {
position: absolute;
/* z-index: -1; */
top: 10px;
width: 100%;
margin: auto;
text-align: center;
font-size: x-large;
font-weight: bold;
}
.headerLeft {
float: left;
}
.headerRight {
float: right;
}
Updated fiddle: http://jsfiddle.net/7mo7hyza/
Your z-index idea is good, but you didn't perform it well: z-index only works between elements that are both not in the normal workflow of the document (they have position: absolute/relative/..)
So you simply have to position your left/right containers with position: absolute instead of float, and make the big container relative so that you can position the other containers relatively to that one.
.headerContainer {
position: relative;
} .headerTitle {
z-index: 0;
} .headerLeft {
position: absolute;
left: 0;
z-index: 1;
} .headerRight {
position: absolute;
right: 0;
z-index: 1;
}
Make the left and right position relative and give them a higher z-index.
.headerContainer {
padding-top: 10px;
padding-left: 0px;
padding-right: 5px;
max-width: 100%;
height: 30px;
background-color: #fcfcfc;
border-bottom: 1px solid #f6f6f6;
}
.headerTitle {
position: absolute;
/* z-index: -1; */
top: 10px;
width: 100%;
margin: auto;
text-align: center;
font-size: x-large;
font-weight: bold;
}
.headerLeft,
.headerRight {
position: relative;
z-index: 2;
}
.headerLeft {
float: left;
}
.headerRight {
float: right;
}
<div class="headerContainer">
<div class="headerLeft">
Left
</div>
<div class="headerTitle">Middle</div>
<div class="headerRight">
Right
</div>
</div>
Try to avoid using float-ing elements or messing with the z-index. There are two more appropriate methods for what you're trying to achieve:
Method 1: CSS box model
.headerContainer {
padding-top: 10px;
padding-left: 0px;
padding-right: 5px;
max-width: 100%;
height: 30px;
background-color: #fcfcfc;
border-bottom: 1px solid #f6f6f6;
display: flex;
flex-wrap: nowrap;
}
.headerLeft,
.headerTitle,
.headerRight {
display: inline-block;
}
.headerLeft,a
.headerRight {
flex-grow: 0;
}
.headerTitle {
flex-grow: 1;
text-align: center;
font-size: x-large;
font-weight: bold;
}
<div class="headerContainer">
<div class="headerLeft">
Left
</div>
<div class="headerTitle">Middle</div>
<div class="headerRight">
Right
</div>
</div>
See JsFiddle
Method 2: Table layout
.row {
display: table-row;
width: 100%;
background-color: #eee;
}
.cell {
display: table-cell;
}
.middle {
width: 100%;
text-align: center;
}
<div class="headerContainer row">
<div class="cell">
Left
</div>
<div class="cell middle">
<h1>Middle</h1>
</div>
<div class="cell">
Right
</div>
</div>
See JsFiddle