I'm trying to put two text blocks over an image, one in the top left and the another in the bottom right. The text in the top left it's ok, but I can't put the text in the bottom right.
Here is the html code:
<section class="feed">
<div class="section">
<img src="">
<p class="text1"><span>Text 1</span></p>
<p class="text2"><span>Text 2</span></p>
</div>
<div class="section">
<img src="">
<p class="text1"><span>Text 3</span></p>
<p class="text2"><span>Text 4</span></p>
</div>
</section>
And now the CSS:
.section {
position: relative;
width: 65%;
margin: 3.375em 0 0 5%;
}
img {
width: 100%;
}
.text1 {
position: absolute;
top: 7.5%;
width: 100%;
}
.text1 span {
color: white;
font: 1.5em Helvetica, Sans-Serif;
font-weight: 300;
background: rgb(0, 0, 0);
/* fallback color */
background: rgba(0, 0, 0, 0.7);
padding: 0.625em;
}
.text2 {
/* don't know how to put this one in the bottom right */
}
.text2 span {
color: white;
font: 1em Helvetica, Sans-Serif;
font-weight: 300;
background: rgb(241, 91, 87);
/* fallback color */
background: rgba(241, 91, 87, 0.7);
padding: 0.625em;
}
Thanks.
You could just position it absolute, but starting from the bottom right, in stead of the top left you did with the first text block. Something like this:
.text2 {
position: absolute;
bottom: 0;
right: 0;
}
To see the code in action: http://jsfiddle.net/KzFDx/
here is one ez way to do this.
<div style="background= your image here no repeat, width height.....">
<p style="position, size,.... ></P>
<p style="position, size...."></P>
</div>
Related
The MSN has news cards recommendation on its website. The image overlay color and the bottom color of the card sink in well, the text is displayed over it. The cards has various colors and looks good. How to create similar effect with HTML and CSS? The below code is similar but it doesn't look as good as MSN.
HTML
<ul class="card-wrapper">
<li class="card">
<img src='https://images.unsplash.com/photo-1611916656173-875e4277bea6?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MXwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHw&ixlib=rb-1.2.1&q=80&w=400' alt=''>
<h3>The image above needs to have transparent overlay on the top</h3>
<p>But has to mingle smoothly with bottom white/black/#cee4e4 color card footer.</p>
</li>
<li class="card">
<img src='https://images.unsplash.com/photo-1611083360739-bdad6e0eb1fa?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MXwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHw&ixlib=rb-1.2.1&q=80&w=400' alt=''>
<h3>The text can be get into the bottom of the image</h3>
<p>where the color gets faded away to show clear image.</p>
</li>
<li class="card">
<img src='https://images.unsplash.com/photo-1613230485186-2e7e0fca1253?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MXwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHw&ixlib=rb-1.2.1&q=80&w=400' alt=''>
<h3>The card just needs to look like the MSN news cards</h3>
<p>Just like in the example image - https://i.imgur.com/sU6Kofb.png.</p>
</li>
</ul>
SCSS
.card {
--card-gradient: rgba(0, 0, 0, 0);
--card-gradient: #1c00ff00, #cee4e4;
// --card-gradient: tomato, orange;
--card-blend-mode: overlay;
// --card-blend-mode: multiply;
background-color: #fff;
border-radius: 0.5rem;
box-shadow: 0.05rem 0.1rem 0.3rem -0.03rem rgba(0, 0, 0, 0.45);
padding-bottom: 1rem;
background-image: linear-gradient(
var(--card-gradient),
white max(9.5rem, 27vh)
);
overflow: hidden;
img {
border-radius: 0.5rem 0.5rem 0 0;
width: 100%;
object-fit: cover;
// height: max(10rem, 25vh);
max-height: max(10rem, 30vh);
aspect-ratio: 4/3;
mix-blend-mode: var(--card-blend-mode);
// filter: grayscale(100);
~ * {
margin-left: 1rem;
margin-right: 1rem;
}
}
> :last-child {
margin-bottom: 0;
}
&:hover,
&:focus-within {
--card-gradient: #dbdbdb max(8.5rem, 10vh);
}
}
/* Additional demo display styles */
* {
box-sizing: border-box;
}
body {
display: grid;
place-content: center;
justify-items: center;
min-height: 100vh;
margin: 0;
padding: 1rem;
line-height: 1.5;
font-family: -apple-system, BlinkMacSystemFont, avenir next, avenir,
helvetica neue, helvetica, Ubuntu, roboto, noto, segoe ui, arial, sans-serif;
color: #444;
background-color: #e1faf1;
}
.card h3 {
margin-top: 1rem;
font-size: 1.25rem;
}
.card a {
color: inherit;
}
.card-wrapper {
list-style: none;
padding: 0;
margin: 0;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(30ch, 1fr));
grid-gap: 1.5rem;
max-width: 100vw;
width: 120ch;
padding-left: 1rem;
padding-right: 1rem;
}
View on Codepen
The above code gives similar effect but it doesn't look as good as MSN news cards. The above card doesn't display a clear transparent image and doesn't look as good as MSN news cards.
Live example at MSN
Here is a snippet, using position, you need to wrap div around h3 and p
.card-wrapper {
list-style: none;
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 20px
}
.card {
position: relative
}
.card div {
/* Note: this variables are from msn dark mode - change to the values you prefer */
--gradient-mid-color: rgba(46, 46, 46, .8);
--gradient-color: #2e2e2e;
--radial-gradient-color: rgba(46, 46, 46, 0);
position: absolute;
z-index: 1;
bottom: 0;
right: 0;
left: 0;
padding: 10px;
background: linear-gradient(180deg, transparent 0%, var(--gradient-mid-color) 62.5%, var(--gradient-color) 100%);
color: #fff;
width: 100%;
box-sizing: border-box;
}
.card img {
width: 100%;
aspect-ratio: 1;
object-fit: cover;
}
.card a {
color: inherit;
text-decoration: none
}
<ul class="card-wrapper">
<li class="card">
<img src='https://images.unsplash.com/photo-1611916656173-875e4277bea6?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MXwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHw&ixlib=rb-1.2.1&q=80&w=400' alt=''>
<div>
<h3>The image above needs to have transparent overlay on the top</h3>
<p>But has to mingle smoothly with bottom white/black/#cee4e4 color card footer.</p>
</div>
</li>
<li class="card">
<img src='https://images.unsplash.com/photo-1611083360739-bdad6e0eb1fa?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MXwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHw&ixlib=rb-1.2.1&q=80&w=400' alt=''>
<div>
<h3>The text can be get into the bottom of the image</h3>
<p>where the color gets faded away to show clear image.</p>
</div>
</li>
<li class="card">
<img src='https://images.unsplash.com/photo-1613230485186-2e7e0fca1253?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MXwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHw&ixlib=rb-1.2.1&q=80&w=400' alt=''>
<div>
<h3>The card just needs to look like the MSN news cards</h3>
<p>Just like in the example image - https://i.imgur.com/sU6Kofb.png.</p>
</div>
</li>
</ul>
I am trying to get the Texas icon directly centered between the span and h1 element.
Here is the Screen Capture
I tried googling but I think I might be phrasing what I need poorly. Is it that I have to adjust the padding and margin in css? I just want to move the icon down the y-axis.
Thank you
<header id="top" class="main-header">
<span class="title">Keep it Weird in</span>
<div>
<img class="texas-icon" src="https://image.ibb.co/cGRVFG/texasicon_1.png" alt="texasicon_1" border="0"></a>
</div>
<h1>Austin</h1>
.main-header {
padding-top: 170px;
height: 850px;
background: linear-gradient(lightblue, transparent 90%),
linear-gradient(0deg, #fff, transparent),
#ffa949 url('https://media.giphy.com/media/3ohs7I9ho0H4dfeP7y/giphy.gif') no-repeat center;
background-size: cover;
}
.title {
color: white;
font-size: 1.625rem; /* 26px/16px */
letter-spacing: .065em;
font-weight: 200px;
padding-bottom: 10px;
}
h1 {
font-size: 12.5rem; /* 90px/16px */
color: rgba(255, 255, 255, 1);
text-transform: capitalize;
font-weight: normal;
text-align: center;
line-height: 1.3;
margin: 12px 0px 0px;
}
I think text-align:center is enough in your case, then simply play with margin of elements to create the spaces :
header {
background: blue;
text-align: center;
color: #fff;
max-height: 380px;
padding: 50px 25px 0px;
}
.title {
margin: 5px 0;
font-size: 1.3rem;
border: none;
display: inline-block;
}
h1 {
margin: 10px 0;
font-size: 5rem;
line-height: 1.1;
}
<header id="top" class="main-header">
<span class="title">Keep it Weird in</span>
<div>
<img class="texas-icon" src="https://image.ibb.co/cGRVFG/texasicon_1.png" alt="texasicon_1" border="0">
</div>
<h1>Austin</h1>
</header>
Thank you for the support. Unfortunately, none of the solutions worked but I decided just to change the line height of the h1 element and was able to get the result I wanted. I learned so many new things from the responses to my question. Again, thank you.
Updated Screen Capture
Hey I've created a navbar and I've added an illusionary marker effect under it.
Basically what I want it to do is for when i hover over the image for an arrow to display under it.
Unfortunately I can't quite get it to work.
In the illustration below, I want to showcase. This is how the arrows are placed. Basically, I've set the second one on visibility: hidden; and for illustration purposes left the rest visible.
The one that has black background shows the one I'm hovering my cursor over (showcasing the selection works, there just must be something wrong with my css implementation). I've set the background as #000 (black) only for illustration purposes of the hover. As for the actual code, i just wish for the image to be visible.
So once again, what I want is for the arrows to stay hidden unless you hover over them. My code looks something like this
<div class = "arrows">
<img src="" class="1" alt =""><img src="" class="2" alt =""
<img..et cetera>
</div>
As for the actual CSS, I have some margin and padding set up which is not really of importance.
Basically the important part is:
.arrows img {
position: relative;
bottom: 20px;
}
and now for the specific arrows
img.1 {
visiblity:hidden;
margin, padding and few other properties
}
img.1:hover {
visibility: visible;
}
However, when I hover over the image, it just remains invisible. Any ideas how to solve this?
EDIT: Added code snippet/jsfiddle
* {
box-sizing: border-box;
/* Opera/IE 8+ */
}
body,
div,
span,
h1,
h2,
h3,
h4,
h5,
h6,
p,
a {
font-family: Arial;
margin: 0;
padding: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
text-decoration: none;
}
/*
====================================================
NAVIGACNY PANEL
====================================================
*/
.navbar {
background-color: #3c1f0a;
width: 100%;
height: 40px;
}
.navbar ul {
z-index: -1;
text-align: center;
display: inline-block;
list-style: none;
margin-left: 175px;
padding: 0px;
}
.navbar li {
width: 80px;
display: inline-block;
font-family: Helvetica;
font-size: 13px;
padding: 0 5px;
}
.navbar a {
text-decoration: none;
color: #FFF;
}
.navbar li:hover {
background-color: #602401;
}
/*
=============================================================
KRATKY POPIS - Index
=============================================================
*/
.ITW {
width: 100%;
height: auto;
padding-bottom: 20px;
background: rgb(252, 255, 251);
background: linear-gradient(to bottom, rgba(252, 255, 251, 1) 0%, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 250, 1) 1%, rgba(255, 253, 255, 1) 1%, rgba(252, 252, 252, 1) 20%, rgba(250, 250, 250, 1) 21%, rgba(248, 248, 248, 1) 31%, rgba(246, 246, 246, 1) 32%, rgba(247, 247, 247, 1) 35%, rgba(233, 233, 233, 1) 73%, rgba(234, 234, 234, 1) 75%, rgba(232, 232, 232, 1) 76%, rgba(227, 227, 227, 1) 100%);
}
.ITW img {
visibility: hidden;
position: relative;
padding: 30px 15px 10px 17px;
bottom: 20px;
}
.ITW img:hover {
position: relative;
visibility: visible;
}
img.move-image {
margin-left: 190px;
}
img.ma {
padding-left: 30px;
margin-left: 30px;
}
img .ma:hover {
visibility: visible;
}
img.mb {
padding-left: 20px;
padding-right: 30px;
margin-left: 20px;
}
img.mc {
padding-right: 30px;
margin-left: 15px;
}
img.md {
padding-right: 20px;
margin-left: 25px;
}
img.me {
margin-left: 30px;
}
img.mf {
margin-left: 30px;
padding-right: 15px;
}
.ITW h2 {
font-family: Helvetica;
font-size: 19px;
padding: 10px 0px 15px 0px;
color: #b15e23;
margin-left: 200px;
}
.ITW p {
font-family: Helvetica;
font-size: 12px;
color: #656565;
margin-left: 200px;
}
<body>
<div class="navbar">
<ul>
<li>Index
</li>
<li>O predmete
</li>
<li>Prednášky
</li>
<li>Výsledky
</li>
<li>Cvičenia
</li>
<li>Kontakt
</li>
<li>Related
</li>
</ul>
</div>
<div class="ITW">
<img src="icons/menu_bullet.gif" class="move-image" alt="moved-bullet">
<img src="icons/menu_bullet.gif" class="ma" alt="index-bullet">
<img src="icons/menu_bullet.gif" class="mb" alt="index-bullet">
<img src="icons/menu_bullet.gif" class="mc" alt="index-bullet">
<img src="icons/menu_bullet.gif" class="md" alt="index-bullet">
<img src="icons/menu_bullet.gif" class="me" alt="index-bullet">
<img src="icons/menu_bullet.gif" class="mf" alt="index-bullet">
</div>
Grabs wrench*, tingling sounds*
Background music with low volume rock {ace of spades};
Try and set the navbar with:
z-index:2;
position: relative;
Set the arrows with:
Z-index:1;
position: relative;
By setting a higher value of Z-index your creating a layer type logic: the higher the value the upper the layer will be set;
all objects affected with z-index must have position attribute;
To summarize, I've realized that if I set the visibility to hidden; you can't hover over the element since it's hidden from you.
The easiest solution instead of using the visibility: attribute, use the opacity: attribute is well and switch it between 0 and 1(hover).
I am Trying to create this One page containing different divs with 100% width.
But, when I insert a 'h2' at top of div, itcreates gap between two div's.
assigning top margin removes this gap, but I want the 'h2' at top only.
here's JSFiddle
HTML:
html,
body {
height: 100% !important;
width: 100% !important;
margin: 0px;
padding: 0px;
}
.mainDiv {
height: 500% !important;
width: 100% !important;
}
.page {
height: 20% !important;
width: 100% !important;
text-align: center;
}
#headerDiv {
height: 15%;
position: fixed;
background-color: #7f4c76;
width: 100%;
box-shadow: 0px 5px 5px rgba(0, 0, 0, 0.4);
}
#div1 {
padding-top: 5%;
background-color: #334960;
}
#div2 {
background-color: #f17c72;
}
#div3 {
background-color: #32ac97;
}
#div4 {
background-color: black;
}
#div5 {
background-color: yellow;
}
h1 {
color: #E6E6E6;
margin-left: 50px;
font-family: "MS Sans Serif", Geneva, sans-serif;
font-size: 300%;
text-shadow: 0px 5px 5px rgba(0, 0, 0, 0.4);
}
h2 {
color: #E6E6E6;
font-weight: normal;
font-family: 'Signika', sans-serif;
font-size: 300%;
}
<div class="mainDiv">
<div id="headerDiv">
<h1>CSS3 Demo </h1>
</div>
<div id="div1" class="page">
<h2>Text Effects Demo</h2>
</div>
<div id="div2" class="page">
<h2>Transition Demo</h2>
</div>
<div id="div3" class="page">
<h2>Animation Demo</h2>
</div>
<div id="div4" class="page">
<h2>Multiple Columns</h2>
</div>
<div id="div5" class="page">
<h2>Multiple Columns</h2>
</div>
</div>
Please Help.
Edit screenshot added:
Add this to your h2
h2 {
margin:0;
}
You issue is that your div has a default margin, of which can be overwritten using this styling
If I understood you correctly, you want the <h1>from the headerDivto have margin-top:0px; if this is what you want then the fix is quite simple:
#headerDiv h1 {
margin-top:0px;
}
Or if you want it to be only the direct descendants from the headerDiv you could do the following:
#headerDiv > h1 {
margin-top:0px;
}
Here you can find the fiddle updated: http://jsfiddle.net/s0p8ogdb/3/
After seeing the screenshot recently added you can fix this simply by making the page class display:inline-block, here's an updated fiddle: http://jsfiddle.net/s0p8ogdb/4/
Try this :
h2 {
color: #E6E6E6;
font-weight: normal;
font-family: 'Signika', sans-serif;
font-size: 300%;
margin-top:0;
}
#div1 h2 {
padding-top: 1em
}
I have in general 3 areas in a WEB page (title and subtitle, 2 text columns and test in left and image at right). I would like to get following result:
However I do not know how to make it, I think it has to do with z-index of wine image, but how to do it?
I have this:
my current code is:
<header>
<div class="inner-header">
<h1><a title="title">titlw</a></h1>
<h2>subtitle</h2>
</div>
</header>
<section id="tagline">
<div id="tagline-content">column 1 and its text.</div>
<div id="tagline-content-middle">column 2 and its text.</div>
</section>
<section id="product">
<article class="product">
<img src="http://hmimexico.com/noir.png" alt="Girl" />
<h3>title</h3>
<p>Lorem Ipsum .</p>
</article>
</section>
css:
header {
margin-top: -40px;
height: 165px;
}
header .inner-header {
height:165px;
text-align:center;
}
header h1{
padding-top: 45px;
text-shadow: 0 -1px 1px rgba(0, 0, 0, 0.25);
margin-bottom:0;
}
header h2 {
color:#111111;
font-size: 19px;
line-height: 22px;
font-weight: bold;
letter-spacing: 1px;
margin-top:-2px;
text-shadow: 0 -1px 1px rgba(0, 0, 0, 0.15);
text-transform:uppercase
}
#tagline {
padding: 10px 0 10px 0;
background:#111 ;
text-shadow: 0 -1px 1px rgba(0, 0, 0, 0.25);
}
#close-open-top {
margin: -9px auto;
text-align: center;
width: 50px;
}
#close-open-top a {
width:100px
}
#close-open-top:hover {
margin-top:-11px;
padding-bottom:2px
}
#tagline-content {
color: #FFFFFF;
text-align:left;
font-size: 10px;
font-weight: normal;
letter-spacing: 1px;
line-height: 100px;
text-transform: uppercase;
}
#tagline-content-middle {
color: #FFFFFF;
text-align:center;
font-size: 10px;
font-weight: normal;
letter-spacing: 1px;
line-height: 100px;
text-transform: uppercase;
}
#product {
text-align:center;
margin:16px auto;
padding-top:10px;
width:960px;
}
#product img {
float: right;
margin-left: 15px;
}
.product {
width:100%;
display:block;
margin:0;
text-align:left;
}
.product p {
color: #4F4F4F;
font-size: 16px;
line-height: 21px;
margin-bottom:38px
}
please take a look at the fiddle:
http://jsfiddle.net/2aEGp/1/
How can I get result as shown in image 1?
I believe this is what you are looking for (jsFiddle). I used a combination of the following:
width:33.3% and float:left on your columns. I set the first 2 to 33.3% even though there is not a third column but the product image takes the place of the third column.
overflow:hidden on the column containers, since the columns are now floating we need to set overflow on it wrapping #tagline div.
Negative margin-top on the product image, so that it goes above the column wrapper. There was no need to add z-index.
You can also view the jsFiddle fullscreen to see how it would look like in a browser window.
Here's a fiddle for you image on top
and here's the css and html code
<header>
<div class="inner-header">
<h1><a title="title">titlw</a></h1>
<h2>subtitle</h2>
<div class='imgCont'>
<img src="http://i.stack.imgur.com/Ava65.png" alt="Girl" />
</div>
</div>
</header>
<section id="tagline">
<div id="tagline-content">column 1 and its text.</div>
<div id="tagline-content-middle">column 2 and its text.</div>
</section>
<section id="product">
<!-- Main content area -->
<article class="product">
<h3>title</h3>
<p>Lorem Ipsum .</p>
</article>
</section>
css
header {
margin-top: -40px;
height: 165px;
}
header .inner-header {
height:165px;
text-align:center;
}
header h1{
padding-top: 45px;
text-shadow: 0 -1px 1px rgba(0, 0, 0, 0.25);
margin-bottom:0;
}
header h2 {
color:#111111;
font-size: 19px;
line-height: 22px;
font-weight: bold;
letter-spacing: 1px;
margin-top:-2px;
text-shadow: 0 -1px 1px rgba(0, 0, 0, 0.15);
text-transform:uppercase
}
#tagline {
padding: 10px 0 10px 0;
background:#111 ;
text-shadow: 0 -1px 1px rgba(0, 0, 0, 0.25);
}
.imgCont{
height:100%;
width:30%;
float:right;
}
#close-open-top {
margin: -9px auto;
text-align: center;
width: 50px;
}
#close-open-top a {
width:100px
}
#close-open-top:hover {
margin-top:-11px;
padding-bottom:2px
}
#tagline-content {
color: #FFFFFF;
text-align:left;
font-size: 10px;
font-weight: normal;
letter-spacing: 1px;
line-height: 100px;
text-transform: uppercase;
width:100%;
}
#tagline-content-middle {
color: #FFFFFF;
text-align:center;
font-size: 10px;
font-weight: normal;
letter-spacing: 1px;
line-height: 100px;
text-transform: uppercase;
width:100%;
}
#product {
text-align:center;
margin:16px auto;
padding-top:10px;
width:auto;
}
#product img {
float: right;
}
.product {
width:100%;
display:block;
margin:0;
text-align:left;
}
.product p {
color: #4F4F4F;
font-size: 16px;
line-height: 21px;
margin-bottom:38px
}
.product img{
position:relative;
}
I adjusted some designs with % so that it can get a bit responsive. You can try it in browser since fiddle uses and iframe so it some how behaves a little different than atual page in responsiveness.
I believe you should use css positioning to achieve this. Take a look at the following example
http://jsfiddle.net/2aEGp/5/
The css which makes this happen is the following
.product img {
position: absolute;
right: 50px;
top: 100px;
}
I have also rearranged the product section like the this
<section id="product">
<!-- Main content area -->
<article class="product">
<h3>title</h3>
<p>Lorem Ipsum .</p>
<img src="http://hmimexico.com/noir.png" alt="Girl" />
</article>
</section>
I think we can solve the above problem by applying float:left to #tagline-content and to #tagline-content-middle divs and using either clear:both(after the two divs in an empty div) or overflow:hidden(to parent div) to clear the floats.
We can also put the image at the apporpriate position using negative top margin or setting position as absolute and giving right and top values(keeping article position:relative;)