I'm trying to make a card with a title and description but when I set a background image on that image, my card title disappeared but not my description. It happens even if I do the same code for both of them.
I know I don't have to write here animation codes too but I really don't have any idea why this is happening.
Image:
z-index doesn't work I guess.
.index {
width: 400px;
height: 400px;
background-color: white;
float: left;
margin-right: 30px;
border-radius: 10px;
overflow: hidden;
position: relative;
color: white;
cursor: pointer;
}
.index_img {
width: 100%;
height: 100%;
z-index: -1;
}
.index_html {
background-image: url(web_image_html.jpeg);
background-position: center;
background-size: cover;
z-index: -1;
}
.index a {
color: #fff;
text-decoration: none;
}
.index_title {
text-align: center;
font-family: 'Roboto', sans-serif;
font-size: 30px;
}
.index_description {
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
font-family: 'Inter', sans-serif;
width: 100%;
font-size: 18px;
}
.index_title,
.index_description {
background-color: rgba(82, 81, 81, 0.56);
height: 80px;
margin: 0;
display: flex;
align-items: center;
justify-content: center;
z-index: 1;
}
.index_html:hover {
animation: index-animate 3s ease-in-out;
}
#keyframes index-animate {
0% {
transform: scale(1);
}
100% {
transform: scale(1.3);
}
}
<div class="index">
<a href="">
<div class="index_img index_html"></div>
<h2 class="index_title">HTML</h2>
<p class="index_description">Lorem ipsum dolor sit amet.</p>
</a>
</div>
Remove overflow hidden from the below code
.index {
width: 400px;
height: 400px;
background-color: white;
float: left;
margin-right: 30px;
border-radius: 10px;
position: relative;
color: white;
cursor: pointer;
}
You're on the right track! But you're fumbling a little with the usage of display: flex; and position: absolute;. display: flex; should be used on the parent to see the result on the child(ren), you're using it directly on the children (.index_title and .index_description).
For trying to position 2 elements together with position: absolute; I'd recommend wrapping them together, so you only have to position 1 element!
.index {
width: 400px;
height: 400px;
background-color: white;
float: left;
margin-right: 30px;
border-radius: 10px;
overflow: hidden;
position: relative;
color: white;
cursor: pointer;
}
.index_img {
width: 100%;
height: 100%;
z-index: -1;
}
.index_html {
background: url(web_image_html.jpeg) red;
background-position: center;
background-size: cover;
z-index: -1;
}
.index a {
color: #fff;
text-decoration: none;
}
.index_content {
width: 100%;
height: 80px;
position: absolute;
bottom: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background-color: rgba(82, 81, 81, 0.56);
}
.index_title {
font-family: 'Roboto', sans-serif;
font-size: 30px;
color: #000;
}
.index_description {
font-family: 'Inter', sans-serif;
font-size: 18px;
}
.index_title,
.index_description {
width: 100%;
margin: 0;
text-align: center;
}
.index_html:hover {
animation: index-animate 3s ease-in-out;
}
#keyframes index-animate {
0% {
transform: scale(1);
}
100% {
transform: scale(1.3);
}
}
<div class="index">
<a href="">
<div class="index_img index_html"></div>
<div class="index_content">
<h2 class="index_title">HTML</h2>
<p class="index_description">Lorem ipsum dolor sit amet.</p>
</div>
</a>
</div>
Related
I'm not knowing how to increase the height of vitaminpic, which is under container. I'm still new to development, and I know this seems like an amateur mistake. I tried everything I can but it's not working. I believe it has to do with with the fact that it is under the container. I'm trying to make a website that sells vitamins, still new to it but I'm still trying.
#import url('https://fonts.googleapis.com/css2?family=Syne+Mono&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: sans-serif;
}
.background {
width: 100%;
height: 100vh;
background-color: #e0d1cb;
position: relative;
overflow: hidden;
z-index: 2;
}
.nav {
position: fixed;
top: 0;
width: 100%;
display: flex;
justify-content: space-around;
align-items: center;
min-height: 8vh;
background-color: #e0d1cb;
font-family: 'Syne Mono', monospace;
z-index: 3;
}
.nav-links {
display: flex;
justify-content: space-around;
width: 30%;
font-family: 'Syne Mono', monospace;
}
.nav-links li {
list-style: none;
font-family: 'Syne Mono', monospac
}
.nav-links a {
color: rgb(0, 0, 0);
text-decoration: none;
letter-spacing: 2px;
font-weight: bold;
font-size: 14px;
font-family: 'Syne Mono', monospac
}
.burger {
display: none;
}
.burger div {
width: 25px;
height: 3px;
background-color: rgb(226, 226, 226);
margin: 5px;
transition: all 0.3s ease;
}
#media screen and (max-width: 1024px) {
.nav-links {
width: 60%;
}
}
#media screen and (max-width: 768px) {
body {
overflow-x: hidden;
}
.nav-links {
position: fixed;
right: 0px;
height: 92vh;
top: 8vh;
background-color: #e0d1cb;
display: flex;
flex-direction: column;
align-items: center;
width: 20%;
transform: translateX(100%);
transition: transform 0.5s ease-in;
}
.nav-links li {
opacity: 0;
}
.burger {
display: block;
cursor: pointer;
}
}
.nav-active {
transform: translateX(0%);
}
#keyframes navLinkFade {
from {
opacity: 0;
transform: translateX(50px);
}
to {
opacity: 1;
transform: translateX(0);
}
}
.toggle .line1 {
transform: rotate(-45deg) translate(-5px, 6px);
}
.toggle .line2 {
opacity: 0;
}
.toggle .line3 {
transform: rotate(45deg) translate(-5px, -6px);
}
#import url('https://fonts.googleapis.com/css2?family=Syne+Mono&display=swap');
.logo {
resize: both;
font-family: 'Syne Mono', monospace;
}
.link::after {
content: '';
display: block;
width: 0;
height: 2px;
background: #000000;
transition: width .3s;
}
.link:hover::after {
width: 100%;
transition: width .3s;
}
.header {
width: 100%;
background-color: rgba(0, 0, 0, 0.5)
}
.header ul {
text-align: center;
}
.header ul li {
list-style: none;
display: inline-block;
}
.header ul li a {
display: block;
text-decoration: none;
text-transform: uppercase;
color: white;
font-size: 100%;
letter-spacing: 2px;
font-weight: 600;
padding: 25px;
transition: width .3s;
}
.content {
color: #fbfcfd;
position: absolute;
top: 50%;
left: 8%;
transform: translateY(-50%);
z-index: 2;
}
.heading1 {
font-size: 300%;
margin-bottom: 10px 0 30px;
background: transparent;
position: relative;
animation: text 5s 1;
left: 120%;
}
#keyframes text {
0% {
color: transparent;
margin-bottom: -40px;
}
30% {
letter-spacing: 4px;
margin-bottom: -40px;
}
85% {
letter-spacing: 3px%;
margin-bottom: -40px;
}
}
.welcome {
font-size: 30px;
position: relative;
}
.container {
position: absolute;
height: 80%;
width: 30%;
background: #dfcac1;
top: 50%;
left: 35%;
transform: translate(-43%, -60%);
}
.container img {
size: ;
}
.vitaminpic {
width: 100%;
transform: translate(10%, 80%);
padding: 0 10;
}
<head>
<link rel="stylesheet" href="home.css">
</head>
<header class="site-header"></header>
<div class="background">
<div class="nav">
<h1 class="logo">Realvite</h1>
<ul class="nav-links">
<li>
<a href="#" class="link1">
<div class="link1">Home</div>
</a>
</li>
<li>Shop</li>
<li>Contact</li>
</ul>
<div class="burger">
<div class="line1"></div>
<div class="line2"></div>
<div class="line3"></div>
</div>
</div>
</nav>
<div class="container">
<img src="/images/capsule-1079838_1920.jpg" alt="" class="vitaminpic">
</div>
<p style="font-size: 1px;">قيل قديقال</p>
<div class="content">
<small class="welcome"></small>
<h1 class="heading1"></h1>
</div>
</div>
<script src="script.js"></script>
If I were you I would use Bootstrap columns, because not only are these easily configurable, but importing bootstrap also allows you to use a wide variety of HTML, CSS and Javascript libraries which are widely supported. Here's the link - https://getbootstrap.com
In the meantime though, I would recommend removing this:
.container img {
size: ;
}
and changing your container width to 50% to see if that works, because currently you've set your container to 30% width, whereas your image is larger than that, so it isn't fitting inside the container. If 50% doesn't work then try a few different values to try and get it to fit, but as mentioned I would recommend Bootstrap, then you can use "col-md-4" and set the background for that, would probably be much more convenient for you in the long run! :)
I´m currently building my first website. I have a Button in the middle and some text above. I dont get the responsive desing 100% correct. I added some media querys to make the design adapt to different browser sizes. The biggest problem is that when I zoom in the whole layout gets messed up. Maybe you can take a quick look at my code and give me some hints.
body,
html {
min-height: 100%;
}
body {
color: #fff;
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
line-height: 1.6em;
margin: 0;
height: 100%;
overflow: hidden;
}
.bild {
background-repeat: no-repeat;
background-size: cover;
}
#caption {
font-size: 14px;
margin-left: 3%;
font-family: 'Quicksand', sans-serif;
}
#main-footer {
width: 100%;
height: 40px;
background-color: #0005;
position: fixed;
left: 0;
bottom: 0;
line-height: 10px;
padding-left: 3%;
}
#main-footer p {
font-family: 'Quicksand', sans-serif;
float: left;
}
#main-footer a {
font-family: 'Quicksand', sans-serif;
float: right;
color: #fff;
padding-right: 5%;
text-decoration: none;
margin-top: 16px;
}
#spruchErstellen {
font-family: 'Architects Daughter', cursive;
text-align: center;
margin-top: 25%;
font-size: 45px;
margin-left: 25%;
margin-right: 25%;
}
.container {
width: 80%;
margin: auto;
overflow: hidden;
position: relative;
}
.block {
width: 100%;
font-size: 30px;
position: relative;
}
.button {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50% -50%);
margin-top: -40px;
margin-left: -120px;
font-family: 'Architects Daughter', cursive;
}
.button {
background: none;
color: #ccc;
width: 240px;
height: 80px;
border: 2px solid #fff;
font-size: 24px;
border-radius: 4px;
transition: .6s;
overflow: hidden;
font-style: bold;
color: #fff;
}
button:focus {
outline: none;
}
button:before {
content: '';
display: block;
position: absolute;
background: rgba(255, 255, 255, .5);
width: 60px;
height: 100%;
left: 0;
top: 0;
opacity: .5s;
filter: blur(30);
transform: translateX(-130px) skewX(-15deg);
}
button:after {
content: '';
display: block;
position: absolute;
background: rgba(255, 255, 255, .2);
width: 30px;
height: 100%;
left: 30px;
top: 0;
opacity: 0;
filter: blur (30px);
transform: translate(-100px) scaleX(-15deg);
}
button:hover {
background: #cc0000;
cursor: pointer;
}
button:hover:before {
transform: translateX(300px) skewX(-15deg);
opacity: .6;
transition: .7s;
}
button:hover:after {
transform: translateX(300px) skewX(-15deg);
opacity: 1;
transition: .7s;
}
#media only screen and (min-width:1101px) {
#spruchErstellen {
font-family: 'Architects Daughter', cursive;
text-align: center;
margin-top: 7%;
font-size: 45px;
margin-left: 25%;
margin-right: 25%;
line-height: 50px;
}
.button {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50% -50%);
margin-top: -40px;
margin-left: -120px;
}
}
I have media querys but I didnt insert all to make the code more clear.
As i allready mentioned I´d like to make it more responsive.
Try to avoid using px. Try to use %.
Also, you can use an CSS framework like Bootstrap to do it for you: https://getbootstrap.com/
So i'm trying to center my button and my image so when the page gets smaller it should still be aligned in the middle. Also my button is not centering.
i'm trying to make it look like : https://www.unrealengine.com
Try moving the page around and see what happens.
.header {
width: 100%;
height: auto;
}
.header img {
width: 100%;
height: auto;
z-index: -1;
}
.header h1 {
margin: 0;
height: auto;
width: auto;
position: absolute;
top: 20%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
color: white;
}
.myButton {
display: inline-block;
text-align: center;
position: relative;
height: auto;
background-color: #10b4f5;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
border-radius: 2px;
display: inline-block;
cursor: pointer;
color: #ffffff;
font-family: Arial;
font-size: 17px;
padding: 16px 31px;
text-decoration: none;
}
.myButton:hover {
background-color: #008fc7;
}
.myButton:active {
position: relative;
top: 1px;
}
<div class="header">
<img src="images/background2.jpg" alt="background">
</div>
EXPLORE
The easiest way to center something vertical and horizontal is using display flex. With align-items and justify-content this can be done quite easily. For more information see: A Complete Guide to Flexbox
header {
display: flex;
flex-direction: column;
text-align: center;
align-items: center;
justify-content: center;
height: 100vh;
width: 100vw;
}
<header>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<button>CTA Here</button>
</header>
EDIT:
This code snippet is based on OP's own code. There is no need to use a div with a header class when you can use the HTML5 header tag.
header {
background-image: url(images/background2.jpg);
display: flex;
flex-direction: column;
text-align: center;
align-items: center;
justify-content: center;
height: 100vh;
width: 100vw;
}
.myButton {
background-color: #10b4f5;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
border-radius: 2px;
cursor: pointer;
color: #ffffff;
font-family: Arial;
font-size: 17px;
padding: 16px 31px;
text-decoration: none;
}
.myButton:hover {
background-color: #008fc7;
}
<header>
<h1>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</h1>
EXPLORE
</header>
Try this code.
HTML
<div class="header-wrap">
<div class="header">
<img src="images/background2.jpg" alt="background">
</div>
EXPLORE
</div>
CSS
.header-wrap {
text-align: center;
}
.header {
width: 100%;
height: auto;
}
.header img {
width: 100%;
height: auto;
z-index: -1;
}
.header h1 {
margin: 0;
height: auto;
width: auto;
position: absolute;
top: 20%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
color: white;
}
.myButton {
display: inline-block;
text-align: center;
position: relative;
height: auto;
background-color: #10b4f5;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
border-radius: 2px;
display: inline-block;
cursor: pointer;
color: #ffffff;
font-family: Arial;
font-size: 17px;
padding: 16px 31px;
text-decoration: none;
}
.myButton:hover {
background-color: #008fc7;
}
.myButton:active {
position: relative;
top: 1px;
}
The alignment of text is specified in the element the text is contained in, so in this case you should specify text-align: center;in the element which contains the button. Like so:
<div class="button-container">
EXPLORE
</div>
and in the CSS
.button-container {
text-align:center;
}
I am trying to hover a text in an image. If I set a background color for the text it is not working. It will work if I use position: absolute; but it is hovering my header too.
.comimg {
width: 100%;
height: 75%;
}
.tren {
margin-top: -250px;
margin-bottom: -300px;
text-align: center;
margin-left: auto;
margin-right: auto;
background-color: aqua;
overflow: none;
}
.trust p {
margin-top: -19;
font-size: 10px;
font-weight: bolder;
color: #424242;
}
.comimg p {
font-family: 'Open Sans', sans-serif;
width: auto;
height: auto;
font-size: 2em;
color: aliceblue;
background-color: aqua;
font-weight: 900;
}
.comimg img {
width: 100%;
height: 100%;
}
<div class="comimg">
<img src="img/6042013705_eb32ce58fa_o.jpg" />
<div class="tren">
<p>#trending</p>
</div>
</div>
Based on my understanding you can achieve that effect using CSS and HTML.
I'm using :hover selector on the .wrapper div, in order to apply different styles based on the result I want to achieve.
EXAMPLE
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
font-family: Helvetica, sans-serif;
}
main {
width: 600px;
margin: 0 auto;
}
.wrapper {
height: 100vh;
width: 100%;
background: url('http://lorempixel.com/500/500/abstract') no-repeat;
background-size: cover;
display: table;
}
.wrapper:hover {
background: #fda;
}
.wrapper:hover p {
background: #345;
display: block;
}
p {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: #fff;
font-size: 2.4em;
display: none;
}
<main>
<div class="wrapper">
<p>
#trending
</p>
</div>
</main>
I am trying to get my <a> tags centered in div#teacherpageoptions. They are centered in Microsoft Expression Web, but not when I view the page in a browser. What am I doing wrong?
#blackbar {
background-color: chartreuse;
padding: 10px;
height: 57px;
}
html {
height: 100%;
}
body,
#teacherpage {
min-height: 100%;
background-color: #f4f4f4;
}
hr {
visibility: hidden;
}
.center {
padding-bottom: 50px;
padding-top: 50px;
}
.button {
display: block;
width: 115px;
height: 25px;
background: chartreuse;
padding: 10px;
text-align: center;
border-radius: 5px;
color: white;
font-weight: bold;
}
.button1 {
display: block;
width: 115px;
height: 25px;
background: #008dde;
padding: 10px;
border-radius: 5px;
color: white;
font-weight: bold;
position: absolute;
}
p {
color: white;
font-weight: bold;
line-height: 40px;
}
.auto-style1 {
/* Make username hang a little to the left. */
margin-left: 53px;
}
#teacherpage {
height: 327px;
background-color: gray;
}
#teacherpageoptions {
margin-left: auto;
margin-right: auto;
height: auto;
}
.auto-style2 {
margin-right: 0px;
}
.wrapper {
text-align: center;
}
.auto-style3 {
margin-bottom: 0px;
}
a {
height: 100%;
opacity: 0.5;
width: 100%;
}
a:hover {
opacity: 1;
-webkit-transform: scale(3);
-ms-transform: scale(3);
transform: scale(3);
}
<div id="blackbar" class="auto-style3">
Logout
<p style=" float:right; height: 36px;" class="auto-style1">Username
<?php session_start(); echo $name=$ _SESSION[ 'name'] ?>
</p>
</div>
<hr>
<div id="teacherpageoptions">
<div class="wrapper" style="height:100px "> Make Questions
<div class="center"></div>
Make Exam
</div>
</div>
Remove the position: absolute; from the .button1 and add margin: 0 auto; instead.
#blackbar {
background-color: chartreuse;
padding: 10px;
height: 57px;
}
html {
height: 100%;
}
body,
#teacherpage {
min-height: 100%;
background-color: #f4f4f4;
}
hr {
visibility: hidden;
}
.center {
padding-bottom: 50px;
padding-top: 50px;
}
.button {
display: block;
width: 115px;
height: 25px;
background: chartreuse;
padding: 10px;
text-align: center;
border-radius: 5px;
color: white;
font-weight: bold;
}
.button1 {
display: block;
width: 115px;
height: 25px;
background: #008dde;
padding: 10px;
border-radius: 5px;
color: white;
font-weight: bold;
/* position: absolute; */
margin: 0 auto;
}
p {
color: white;
font-weight: bold;
line-height: 40px;
}
.auto-style1 {
/* Make username hang a little to the left. */
margin-left: 53px;
}
#teacherpage {
height: 327px;
background-color: gray;
}
#teacherpageoptions {
margin-left: auto;
margin-right: auto;
height: auto;
}
.auto-style2 {
margin-right: 0px;
}
.wrapper {
text-align: center;
}
.auto-style3 {
margin-bottom: 0px;
}
a {
height: 100%;
opacity: 0.5;
width: 100%;
}
a:hover {
opacity: 1;
-webkit-transform: scale(3);
-ms-transform: scale(3);
transform: scale(3);
}
<div id="blackbar" class="auto-style3">
Logout
<p style=" float:right; height: 36px;" class="auto-style1">Username
<?php session_start(); echo $name=$ _SESSION[ 'name'] ?>
</p>
</div>
<hr>
<div id="teacherpageoptions">
<div class="wrapper" style="height:100px "> Make Questions
<div class="center"></div>
Make Exam
</div>
</div>
You can delete the "position:absolute" and put "margin:0 auto" instead.
Let me know how it worked.