I' m super new at html and css. I started to learn yesterday.
I want to top-centered a text in an image.
Here is my html and css codes but I don't figure it out how to do it.
HTML
<div class="button">
<a href="#" class="building">
<img src="{% static 'images/imal.svg' %}" alt="buildinglogo">
<h3>Lastik İmal</h3>
</a>
CSS
.building h3{
font-family: Montserrat;
font-style: normal;
font-weight: 600;
font-size: 40px;
line-height: 49px;
text-align: center;
align-items: center;
color: var(--white);
background-color: var(--black);
}
Here is my output:
This is what i want:
As suggested byMinal Chauhan you can use position: absolute; top: 50px; left: 50px;
.building h3{
font-family: Montserrat;
font-style: normal;
font-weight: 600;
font-size: 40px;
line-height: 49px;
text-align: center;
align-items: center;
color: var(--white);
background-color: var(--black);
position: absolute;
top: 50px;
left: 50px;
}
<div class="button">
<a href="#" class="building">
<img src="https://picsum.photos/300/400" alt="buildinglogo">
<h3>Lastik İmal</h3>
</a>
</div>
I changed the html and css codes like below and problem solved;
HTML
<div class="button">
<a href="#" class="building">
<img src="{% static 'images/imal.svg' %}" alt="buildinglogo">
<h3>Lastik İmal</h3>
</a>
CSS
.building h3{
position: absolute;
font-family: Montserrat;
font-style: normal;
font-weight: 600;
font-size: 40px;
line-height: 49px;
text-align: center;
color: var(--white);
background-color: var(--black);
margin-left: 25px;
margin-top: 47px;
}
Add position: absolute; to .building h3
.building img {
width: 100%;
}
.building h3 {
font-style: normal;
font-weight: 600;
font-size: 40px;
line-height: 49px;
text-align: center;
align-items: center;
position: absolute;
top: 0;
width: 100%;
}
<div class="button">
<a href="#" class="building">
<img src="https://www.w3schools.com/html/pic_trulli.jpg" alt="buildinglogo">
<h3>Lastik İmal</h3>
</a>
</div>
<p>Text content</p>
You should use relative on parent element to position child element.
I made comments in code.
a {
position: relative;
display: inline-block; // you need that for a tag's width / height value
}
a img {
position: relative; // you need that to position h3 properly
z-index: 1
}
a h3 {
position: absolute;
top: 15px;
left: 50%;
transform: translateX(-50%);
z-index: 2;
}
<a href="#">
<img src="//via.placeholder.com/250x400">
<h3>Lastik İmal</h3>
</a>
#image-text{
position:absolute;
left:25%;
top:5%;
}
<!-- HTML-->
<div id="container">
<img src="" alt="Image">
<div id="image-text"> Text </div>
</div>
The above snippet might help you to solve your problem. Adjust CSS left and top values according to your page structure. For further study read:
https://www.w3schools.com/howto/howto_css_image_text_blocks.asp
https://www.geeksforgeeks.org/how-to-place-text-on-image-using-html-and-css/
Related
The font-family and font-size of my project are being inherited even when I specify !important.
You can see the issue when you hover over the first link. There's a label in the top right corner, but I want the font to be times new roman, 12px, and white. So completely different than the font from the rest of the project.
However, when I edit the ".album-art .film" CSS selector, which should control the label, the font doesn't change.
https://codepen.io/cjk47/project/live/4fdb73a9558a26a6c1a0a31c6c31705d
.tracks {
margin-top: 46px;
}
li.track {
display: block;
font-family: "Poppins", sans-serif;
font-weight: 800;
font-size: 5rem;
margin-bottom: 15px;
}
li.track:hover {
color: transparent;
-webkit-text-stroke-color: #18181b;
-webkit-text-stroke-width: 3px;
}
li.track:hover .album-art {
display: block;
}
.album-art {
z-index: -10;
position: fixed;
left: 50%;
top: 50%;
width: 90%;
height: 50%;
max-height: 450px;
display: none;
opacity: 0.5;
overflow: hidden;
transform: translate(-50%,-50%);
}
.album-art img {
width: 100%;
position: relative;
}
.album-art .film {
position: absolute;
top: 5px;
right: 10px;
font-family: "Times New Roman", Times, serif !important;
font-size: 14px;
background: black;
padding: 5px 10px;
color: white !important;
border-radius: 10px;
}
a {
text-decoration: none;
color: inherit;
}
<head>
<link href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700,800,900&display=swap" rel="stylesheet">
</head>
<body>
<div class="logo">
<img src="/img/logo1.png" height="50" width="50">
</div>
<div class="tracks">
<ol>
<li class="track">
<a href="#" class="nav">
<div class="album-art"><img src="/img/king-princess.png"><span class="film">Film</span></div>
<p class="track-name">King Princess - 'Cheap Queen'</p>
</a>
</li>
<li class="track">
<a href="#" class="nav">
<div class="album-art"><img src="/img/charly-bliss.png"></div>
<p class="track-name">Charly Bliss - 'Capacity'</p>
</a>
</li>
<li class="track">
<a href="#" class="nav">
<div class="album-art"><img src="/img/julia-jacklin.jpg"></div>
<p class="track-name">Julia Jacklin - 'Good Guy'</p>
</a>
</li>
<ol>
</div>
</body>
I want the label text when hovering over the first link to be times new roman, 12px, and the color white. However, right now when I try to do this, my stylings are being overridden by the default fonts.
I would like to put 2 buttons div (register and login) on my banner and center. However I think that I already have a problem with my blocks on my html ??
Here is an overview of my website in below.
screenshot:
My first problem is that I don't can to use the margin-left or margin-right to move my button "register" or "login" for center.
My problem comes perhaps from code HTML, Is it a problem with my blocks ?
Here is my code HTML
<div class="my-banner">
<img class="banner" src="images/slider.jpg"/>
<div class="transparent"></div>
<img class="picture-logo" src="images/logo.png"/>
<div class="container">
<div class="myButtonRegister">REGISTER</div>
<div class="myButtonLogin">LOGIN</div>
<div class="topnav">
<a class="active" href="index.php">HOME</a>
ABOUT US
INVESTEMENT PLAN
NEWS
FAQS
RULES
CONTACT US
</div>
</div>
</div>
Here is my code CSS
.myButtonRegister{
margin-top: 342px;
float: left;
background-color: #C22312;
color: white;
height: 48px;
width: 168px;
text-align: center;
color: white;
font-family: 'Pridi', serif;
font-size: 26px;
padding-top: 10px;
word-spacing: 0px;
}
.myButtonRegister a {
color: #f2f2f2;
text-decoration: none;
}
.myButtonLogin{
margin-top: 342px;
float: left;
background-color: black;
color: white;
height: 48px;
width: 168px;
text-align: center;
color: white;
font-family: 'Pridi', serif;
font-size: 26px;
padding-top: 10px;
word-spacing: 0px;
}
Do you have an idea plase ?
Just add a father box to your buttons and use flex to align your buttons. Here is an example:
.container {
height: 200px;
width: 100%;
background: #eee;
}
.container .subcontainer {
display: flex;
height: 100%;
align-items: center;
justify-content: center;
}
<div class="container">
<div class="subcontainer">
<button>Login</button>
<button>Register</button>
</div>
<!--NAV-->
</div>
Try following code for good design and set maximum height & width image in banner no issues create for this type of design this is the right way.
.myButtonRegister{
float: left;
background-color: #C22312;
color: white;
height: 48px;
width: 168px;
text-align: center;
color: white;
font-family: 'Pridi', serif;
font-size: 26px;
padding-top: 10px;
word-spacing: 0px;
}
.myButtonRegister a {
color: #f2f2f2;
text-decoration: none;
}
.myButtonLogin{
float: left;
background-color: black;
color: white;
height: 48px;
width: 168px;
text-align: center;
color: white;
font-family: 'Pridi', serif;
font-size: 26px;
padding-top: 10px;
word-spacing: 0px;
}
.button-action {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
-webkit-transform: translate(-50%,-50%);
-moz-transform: translate(-50%,-50%);
-ms-transform: translate(-50%,-50%);
}
<div class="my-banner">
<div class="banner-image">
<img class="banner" src="images/slider.jpg"/>
<div class="button-action">
<div class="myButtonRegister">REGISTER</div>
<div class="myButtonLogin">LOGIN</div>
</div>
</div>
<div class="transparent"></div>
<img class="picture-logo" src="images/logo.png"/>
<div class="container">
<div class="topnav">
<a class="active" href="index.php">HOME</a>
ABOUT US
INVESTEMENT PLAN
NEWS
FAQS
RULES
CONTACT US
</div>
</div>
</div>
Using position:absolute remove margin-top and give parent div to height and position:relative
.my-banner{
position:relative;
height: 450px;
}
.btnBox{
position: absolute;
left: 0px;
right: 0px;
top: 0px;
margin: auto;
bottom: 0px;
height: 85px;
width: 336px;
}
.myButtonRegister{
float: left;
background-color: #C22312;
color: white;
height: 48px;
width: 168px;
text-align: center;
color: white;
font-family: 'Pridi', serif;
font-size: 26px;
padding-top: 10px;
word-spacing: 0px;
}
.myButtonRegister a {
color: #f2f2f2;
text-decoration: none;
}
.myButtonLogin{
float: left;
background-color: black;
color: white;
height: 48px;
width: 168px;
text-align: center;
color: white;
font-family: 'Pridi', serif;
font-size: 26px;
padding-top: 10px;
word-spacing: 0px;
}
<div class="my-banner">
<img class="banner" src="images/slider.jpg"/>
<div class="transparent"></div>
<img class="picture-logo" src="images/logo.png"/>
<div class="container">
<div class="btnBox">
<div class="myButtonRegister">REGISTER</div>
<div class="myButtonLogin">LOGIN</div>
</div>
<div class="topnav">
<a class="active" href="index.php">HOME</a>
ABOUT US
INVESTEMENT PLAN
NEWS
FAQS
RULES
CONTACT US
</div>
</div>
</div>
I have two divs that each have a paragraph link at the bottom right of the div. When I add the code bottom: 0; position: absolute;, it pulls both the links together into the far right div instead of keeping them in their own divs. How can I set this so that the link stays inside of it's own container at the bottom right corner?
.header-unit {
height: 300px;
position: relative;
margin-top: 5px;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
background-image: url("/images/liberty.jpg");
}
#messageContainer {
margin-left: 200px;
/* padding-top: 450px; */
position: relative;
display: inline-block;
}
h1 {
font-family: 'Montserrat', sans-serif;
font-size: 2em;
line-height: 1.15;
text-transform: uppercase;
}
#knowledge,
#practice {
padding: 25px;
width: 350px;
height: 300px;
display: block;
color: #fff;
}
.linksect {
bottom: 0;
right: 25px;
position: absolute;
}
#knowledge {
background: #8b8b8b;
}
#practice {
background: #554a58;
}
.indexheader {
font-family: 'Montserrat', sans-serif;
font-size: 2em;
line-height: 1.15;
text-transform: uppercase;
color: #554a58;
}
.firmvalues {
margin-top: 50px;
}
<link href="https://www.w3schools.com/w3css/4/w3.css" rel="stylesheet" />
<div class="header-unit">
<div id="messageContainer" class="w3-row">
<div id="knowledge" class="w3-col l6">
<h1>Knowledge. Experience. Commitment. </h1>
<p>The attorneys of ....</p>
<p class="linksect">Our Attorneys <span class="fa fa-angle-double-right" aria-hidden="true"></span></p>
</div>
<div id="practice" class="w3-col l6">
<h1>Practice Areas</h1>
<p>Business and Commercial Law<br> Insurance Coverage and Indemnity Law<br> Medical and Dental Malpractice<br> Probate Law and Practice<br> and more...</p>
<p class="linksect">Practice Areas <span class="fa fa-angle-double-right" aria-hidden="true"></span></p>
</div>
</div>
</div>
You can provide context for position:absolute by adding a non-static position property to the ancestor element you want the absolutely positioned element to be relative to. position:relative is usually a good choice because it keeps your element in the document flow. (Note that I added it to the #knowledge,#practice rule.)
.header-unit {
height: 300px;
position: relative;
margin-top: 5px;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
background-image: url("/images/liberty.jpg");
}
#messageContainer {
margin-left: 200px;
/* padding-top: 450px; */
position: relative;
display: inline-block;
}
h1 {
font-family: 'Montserrat', sans-serif;
font-size: 2em;
line-height: 1.15;
text-transform: uppercase;
}
#knowledge,
#practice {
padding: 25px;
width: 350px;
height: 300px;
display: block;
color: #fff;
position: relative;
}
.linksect {
bottom: 0;
right: 25px;
position: absolute;
}
#knowledge {
background: #8b8b8b;
}
#practice {
background: #554a58;
}
.indexheader {
font-family: 'Montserrat', sans-serif;
font-size: 2em;
line-height: 1.15;
text-transform: uppercase;
color: #554a58;
}
.firmvalues {
margin-top: 50px;
}
<link href="https://www.w3schools.com/w3css/4/w3.css" rel="stylesheet" />
<div class="header-unit">
<div id="messageContainer" class="w3-row">
<div id="knowledge" class="w3-col l6">
<h1>Knowledge. Experience. Commitment. </h1>
<p>The attorneys of ....</p>
<p class="linksect">Our Attorneys <span class="fa fa-angle-double-right" aria-hidden="true"></span></p>
</div>
<div id="practice" class="w3-col l6">
<h1>Practice Areas</h1>
<p>Business and Commercial Law<br> Insurance Coverage and Indemnity Law<br> Medical and Dental Malpractice<br> Probate Law and Practice<br> and more...</p>
<p class="linksect">Practice Areas <span class="fa fa-angle-double-right" aria-hidden="true"></span></p>
</div>
</div>
</div>
I've got three images that need to be displayed horizontally with no gaps between them and a link on top of each one they also need to be scalable to the window size. Currently there are gaps between them.
Here is all of the relevant code I've got so far:
.callout-container {
position: relative;
bottom: 480px;
right: 0px;
}
.callout {
position: relative;
float: left;
Width: 33.3%;
}
.button-1 {
position: absolute;
top: 160px;
right: 1420px;
color: white;
background-color: rgb(224, 99, 38);
padding: 10px;
padding-left: 100px;
padding-right: 100px;
font-family: Futura;
font-size: 20pt;
opacity: 0.9;
}
.button-2 {
position: absolute;
top: 160px;
right: 825px;
color: white;
background-color: rgb(224, 99, 38);
padding: 10px;
padding-left: 100px;
padding-right: 100px;
font-family: Futura;
opacity: 0.9;
font-size: 20pt;
}
.button-3 {
position: absolute;
top: 160px;
right: 220px;
color: white;
background-color: rgb(224, 99, 38);
padding: 10px;
padding-left: 100px;
padding-right: 100px;
font-family: Futura;
opacity: 0.9;
font-size: 20pt;
}
<div class="callout-container">
<div>
<div class="callout-one callout">
<img src="callout_1.png" alt="">
</div>
<div class="callout-two callout">
<img src="callout_2.png" alt="">
</div>
<div class="callout-three callout">
<img src="callout_3.png" alt="">
</div>
</div>
<div>
<div>
<a href="" class="button-1" style="text-decoration:none;">
Property Owner?
</a>
</div>
<div>
<a href="" class="button-2" style="text-decoration:none;">
City Visitor?
</a>
</div>
<div>
<a href="" class="button-3" style="text-decoration:none;">
Teacher?
</a>
</div>
</div>
</div>
Edit: also here is a screenshot of how it is currently displayed.
screenshot
if I understand well, you want the links to be aligned with the images?
I create a jsFiddle to test.
https://jsfiddle.net/mp9007/aL27fxm3/
I think i'm close to want you want:
<div class="callout-container">
<div>
<div class="callout-one callout">
Property Owner?
<!-- image -->
</div>
<div class="callout-two callout">
City visitor?
<!-- image -->
</div>
<div class="callout-three callout">
Teacher?
<!-- image -->
</div>
</div>
And then remove the absolute/right alignement from the css button class
.button-3{
position: absolute;
top: 160px;
//right: 220px;
color: white;
background-color: rgb(224, 99, 38);
padding: 10px;
padding-left: 100px;
padding-right: 100px;
font-family: Futura;
opacity: 0.9;
font-size: 20pt;
}
I have two graphical elements: One Badge for a Region (EUW) and a Sold Out Stamp. I want that the stamp is in front of the region badge. I always thought that this is something where I can use z-index but this just doesn't work for me.
Here is an image of my problem:
My CSS:
.region-badge {
position: absolute;
top: 26px;
right: 26px;
background: url(../images/region_badge.png) no-repeat;
height: 47px;
width: 47px;
display: block;
line-height: 47px;
text-align: center;
text-transform: uppercase;
color: #fff;
font-size: 12px;
font-weight: bold;
z-index: 1;
}
.sold-out {
position:relative;
}
.sold-out::before{
content: url(../images/sold_out_stamp2.png);
transform: scale(.5);
position:absolute;
z-index: 40;
top:-50px;
left:70px;
}
My HTML:
<div class="rotate sold-out">
<a href="images/packages/background01.jpg" rel="imagebox" title="SockMonkee">
<img src="images/packages/background01.jpg" alt=""/></a>
</div>
<div class="region-badge">euw</div>
try this.,
<div class="rotate sold-out">
<a href="images/packages/background01.jpg" rel="imagebox" title="SockMonkee">
<img src="images/packages/background01.jpg" alt=""/>
</a>
<div class="region-badge">euw</div>
</div>