Firstly I attempted the only way I can think of to add 3 different
colours for the background, but now it won't allow me to display my
text.
I tried to use the position feature but it doesn't work and I am not sure what I am doing wrong or is there a better way to do the 3 colour background?
* {
margin: 0;
padding: 0;
}
div {
height: 1500px;
position: relative;
}
.a {
background: black;
}
.b {
background: #1e1d1d;
}
.a:after,
.c:before,
.c:after {
content: '';
width: 100%;
height: 100%;
top: 0;
right: 0;
bottom: 200px;
display: block;
position: relative;
font-family: Arial;
}
.a:after {
background: black;
}
.c:before {
background: #1e1d1d;
right: 0;
height: 100%;
}
.c:after {
background: white;
right: 0;
height: 100%;
}
p {
position: fixed;
font-family: Arial;
color: white;
}
<div class="a">
<h1>DeadTreeStudios</h1>
</div>
<div class="b" style="position:absolute;">
<h1>
-I'm James, a freelance software developer & designer.
</h1>
<p>
I've always had a keen interest in design and development. Allthough there is always alot to learn, my skills are broad: from front end to back end development to app development. I enjoy it all!
</p>
<p>
I'm avaliable for remote work, or if you like to build somthing together, please get in touch.
</p>
</div>
<div class="c"></div>
<article></article>
There were multiple things wrong with your css that broke it, check this out.
You don't need position: absolute to do stuff like this
with height: 100vh; width: 100%; i make sure a section is filling the screen from top to bottom left to right
note that you could also use width:100vw; to fill it horizontally but in some cases it adds a horizontal scroll bar
* {
box-sizing: border-box;
margin: 0;
padding: 0;
width: 100%;
}
body {
font-family: arial;
}
section {
width: 100%;
height: 100vh;
}
#first {
background-color: black;
color: white;
padding-top: 48vh;
}
#second {
background-color: grey;
color: white;
}
#first h1 {
text-align: center;
vertical-align: middle;
}
<section id="first">
<h1>DeadTreeStudios</h1>
</section>
<section id="second">
<h1>
-I'm James, a freelance software developer & designer.
</h1>
<p>
I've always had a keen interest in design and development. Allthough there is always alot to learn, my skills are broad: from front end to back end development to app development. I enjoy it all!
<br> I'm avaliable for remote work, or if you like to build somthing together, please get in touch.
</p>
</section>
<section id="third">
</section>
I just fiddled your stuff.
I removed the
position:absolute;
inline style....
and gave .a and .b a color ofc you cant see black on black....
https://jsfiddle.net/nabrzovg/
I can't really understand what you are trying to do here. I removed all positions and changed colors to see whats happening.
* {
margin: 0;
padding: 0;
}
div {
height: 1500px;
}
.a {
background: red;
}
.b {
background: yellow;
z-index:22;
}
.a:after, .c:before, .c:after {
content: '';
width: 100%;
height: 100%;
top: 0;
right: 0;
bottom: 200px;
display: block;
font-family: Arial;
}
.a:after {
background: black;
}
.c:before {
background: purple;
}
.c:after {
background: white;
}
p{
font-family: Arial;
color: white;
}
h1{
color: white;
}
Related
I am working out a page that will have a quick-paced shuffle of images on one side, and would like to put bold and visually-attractive text that will lay over a corner of it as a mask and invert the colours of whatever is behind it. Are there any ways to style the text to do this in css?
I haven't been able to find any common solutions or workarounds for what I'm looking to achieve, only how to invert a selected colour.
This should work. mix-blend-mode: difference; makes the trick. I attached a working snippet.
.container {
position: relative;
height: 300px;
width: 400px;
display: flex;
}
.color-1 {
width: 33%;
background-color: red;
}
.color-2 {
width: 33%;
background-color: violet;
}
.image {
width: 33%;
background-image: url(https://picsum.photos/200/300);
}
p {
margin: 0;
width: 100%;
position: absolute;
font-family: 'Helvetica', sans-serif;
font-weight: 600;
text-align: center;
font-size: 50px;
top: 100px;
left: 0;
right: 0;
color: white;
mix-blend-mode: difference;
}
<div class="container">
<div class="color-1"></div>
<div class="color-2"></div>
<div class="image"></div>
<p>Inverting Text</p>
</div>
use a background color for the text
add a shadow below the text to enhance the contrast https://www.w3schools.com/cssref/tryit.php?filename=trycss3_text-shadow
h1 {
text-shadow: 1px 1px red;
}
Find a color that works well with all the images
Use mix-blend-mode: difference; https://css-tricks.com/methods-contrasting-text-backgrounds/
<!DOCTYPE html>
<html>
<head>
<style>
* { margin: 0; padding: 0 }
header {
overflow: hidden;
height: 100vh;
background: url(https://cdn.britannica.com/70/191970-050-1EC34EBE/Color-wheel-light-color-spectrum.jpg) 50%/ cover
}
h2 {
color: white;
mix-blend-mode: difference;
font: 900 35vmin/35vh cookie, cursive;
text-align: center
}
</style>
</head>
<body>
<header>
<h2 contentEditable role='textbox' aria-multiline='true'>And stay alive...</h2>
</header>
</body>
</html>
The following code is a simplified version of the problem im facing, know that the text has to be a separate div which will be placed on top using positioning, in short the text needs to be visible to user but should not affect anything on the website.
body {
margin: 0px;
padding: 0px;
font-family: Arial, Helvetica, sans-serif;
}
#box {
width: 600px;
height: 200px;
background-color: yellow;
}
#box:hover {
background-color: blue;
}
#text {
position: relative;
bottom: 50px;
}
<body>
<div id="box"></div>
<div id="text">i still want the color of the box to change even when im hovering over this text</div>
</body>
Add pointer-events: none to the text div.
body {
margin: 0px;
padding: 0px;
font-family: Arial, Helvetica, sans-serif;
}
#box {
width: 600px;
height: 200px;
background-color: yellow;
}
#box:hover {
background-color: blue;
}
#text {
position: relative;
bottom: 50px;
pointer-events: none;
}
<body>
<div id="box"></div>
<div id="text">i still want the color of the box to change even when im hovering over this text</div>
</body>
This can not be possible with CSS alone, there is no way to select a parent element in css from child and update the style.
So, You can write a but of JS to do that. Here is the updated code.
body {
margin: 0px;
padding: 0px;
font-family: Arial, Helvetica, sans-serif;
}
#box {
width: 600px;
height: 200px;
background-color: yellow;
}
#box:hover {
background-color: blue;
}
.blue{
background-color: blue !important;
}
#text {
position: relative;
bottom: 50px;
}
<body>
<div id="box"></div>
<div id="text" onmouseout="update(false)" onmouseover="update(true)">i still want the color of the box to change even when im hovering over this text</div>
<script>
function update(updateColor){
let box = document.getElementById('box');
if(updateColor){
box.classList.add("blue");
}else{
box.classList.remove("blue");
} }
</script>
</body>
I'm a newbie and I have been struggling positioning text and Image as the pictures show below. If I use "relative" and "absolute" positioning the text container would position itself over the next content of the page. What would be the best way to make the layout like this?
Desktop Version
Mobile version
I did this while ago and if you open in it Firefox you should see what I'm aming for. Idk why it's not working on Chrome. (If you look at the mobile size, everything is like I want it to be)
https://helaris.github.io/lns/
and code is here: https://github.com/helaris/lns
You can use z-index.
You have to make the image upper.
Managed to get it like on the images above. Not sure If this is the easiest way or not but it works.
Codepen link
HTML -
> <div class="container">
<section class="welcome-section">
<div class="welcome-text-container">
<h1>Welcome to LNS</h1>
<p>We are priviliged to be able to teach you the Norwegian language,
and thereby open the doors to the society around you.
We aim to facilitate your transition to life here in Norway in a
smooth manner. A wise man once said:
Speak to a person in their language, and you speak to their heart.
We also pride ourselves in working on engaging and keeping you
involved in Stavanger life. We know that classroom courses will teach
you how to speak Norwegian, and we provide you just that!
<br>Welcome to class!</p>
</div>
<div>
<img src="images/welcome-image.jpg" alt="">
</div>
</section>
</div>
CSS:
> body {
background-color: #f5f5f5;
}
.container {
position: relative;
max-width: 1200px;
margin: 50px auto;
}
.container img {
position: relative;
width: 80%;
height: 100%;
right: -200px;
}
.welcome-text-container {
z-index: 1;
position: absolute;
max-width: 380px;
background-color: #fff;
line-height: 1.9;
text-align: left;
padding: 1rem;
bottom: 0;
}
.welcome-text-container h1 {
font-family: 'Frank Ruhl Libre', serif;
font-size: 2rem;
font-weight: 400;
padding: 1rem;
border-bottom: 1px solid #a8bfff;
}
.welcome-text-container p {
font-family: 'Montserrat', sans-serif;
padding: 40px 5px 10px 5px;
font-size: 16px;
}
#media screen and (max-width: 901px) {
.welcome-section {
display: flex;
flex-direction: column;
align-items: center;
}
.welcome-text-container {
position: relative;
order: 2;
bottom: 100px;
margin: 0px 15px;
max-width: 35rem;
}
.container img {
order: 1;
width: 100%;
position: initial;
}
.welcome-text-container p {
font-size: 0.9rem;
}
}
I am trying to do some basic web development, but for some reason, there is a huge whitespace between the opening body tag and the first div. How do I move the div to the top /or remove whitespace/ without using 'position: fixed;'?
body {
width: 100%;
height: auto;
margin: 0;
padding: 0;
}
.top_bar {
margin: 0;
padding: 0;
text-align: center;
background-color: black;
color: rgb(179, 0, 0);
width: 100%;
height: auto;
font-size: 200%;
position: absolute;
}
<div class="top_bar">
generic string
<br>
<br>
<br>
</div>
That is because html, by default has 8px margin. To remove it, use the code below.
* {
margin: 0px;
padding: 0px;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.top_bar {
margin: 0;
padding: 0;
text-align: center;
background-color: black;
color: rgb(179, 0, 0);
width: 100%;
height: auto;
font-size: 200%;
position: absolute;
}
<div class="top_bar">
generic string
<br>
<br>
<br>
</div>
Try It Once
html,body{
margin:0px;
padding:0px;
}
Sorry to post, but apparently I forgot to remove the extra newlines from the header that I send with CGI. It worked out properly.
CSS:
html,
body {
margin: 0;
padding: 0;
height: 100%;
background-color: #E6E6E6;
}
#header {
background-color: black;
width: 100%;
margin-top: 50px;
margin-bottom: 50px;
}
#content {
padding-bottom: 80px;
text-align: center;
}
#footer {
width: 100%;
height: 80px;
position: absolute;
bottom: 0;
left: 0;
background-color: black;
color: #898989;
}
I'm using a really common method to keep the footer at the bottom of the page, and it only half works. I learnt about it through a blog, and it was really helpful at first, however at some point editing my website it became broken. It displays a very small portion of the footer div, and while the rest is there, you have to scroll down to see it.
Without scrolling: http://i.imgur.com/lKH5Byc.png
With scrolling: http://i.imgur.com/GrGKpzm.png
I don't know what I'm missing here, it just isn't working.
EDIT: So I know this was a terrible question, I left out a lot of stuff because it's a company website and I was just worried about what I included. The culprit turned out to be the margins on the #header element. Removing those made everything work like a charm.
So I know this was a terrible question, I left out a lot of stuff because it's a company website and I was just worried about what I included. The culprit turned out to be the margins on the #header element. Removing those made everything work like a charm.
I have changed only the bottom part
html,
body {
margin: 0;
padding: 0;
height: 100%;
background-color: #E6E6E6;
}
#header {
background-color: black;
width: 100%;
margin-top: 50px;
margin-bottom: 50px;
}
#content {
padding-bottom: 80px;
text-align: center;
}
#footer {
width: 100%;
height: 80px;
position: absolute;
bottom: -100px;
left: 0;
background-color: black;
color: #898989;
}
<div id="header">
.
</div>
<div id="content">
.
</div>
<div id="footer">
.
</div>
does that help?