Create an opaque Text box on top of an image? - css

I am a newbie to both html and css and for the life of me I cannot get this right. Can someone please assist me in coding this?
This is what I have done so far, but now I'm stuck and my image is not showing up at all..
<div class="image"></div>
<div id="box1">
<h2>Welcome to the home of</h2>
<h1>Oliver & Sons</h1>
<p title="Oliver & Sons - Exquisite Carpentry">
In my workshop patience, skill and immaculate precision are combined to produce items that is unique, of exquisite taste and quality and could very well be a heirloom in your family. Explore my gallery and contact me when you are ready to experience craftsmanship at it’s best.
</p>
</div>
#box1 {
width: 100%;
padding: 100%px;
border: 2px solid navy;
margin: 0px;
background-colour: white;
}
div.image {
background: url(Images/background.jpg);
background-size: 100% 100%;
background-repeat: no-repeat;
}

There are a several wrong things here:
When you set any CSS property like padding you should only use one kind of messure: px, %, em, rem... But not two, as you do in #box1. This is an error.
This is matter of style. When you set a property to 0 is better not set px, nor any kind of messurement units.
Now, your goal.
You want to get your #box1 inside of your .image so you should put one tag inside of another, as you could see on my code. Doing that you will be very close to your solution.
Next thing is centering you #box1. There are a lot of ways to do that, I put here my favourite, but, as always, the best way depends on the situation.
#box1 {
width: 50%;
border: 2px solid navy;
margin: 0 auto;
color: #FFF;
background: navy;
opacity: 0.8;
border-radius: 5px
}
div.image {
padding: 20px;
background: url(http://static.vecteezy.com/system/resources/previews/000/094/491/original/polygonal-texture-background-vector.jpg);
background-size: 100% 100%;
background-repeat: no-repeat;
}
<div class="image">
<div id="box1">
<h2>Welcome to the home of</h2>
<h1>Oliver & Sons</h1>
<p title="Oliver & Sons - Exquisite Carpentry">
In my workshop patience, skill and immaculate precision are combined to produce items that is unique, of exquisite taste and quality and could very well be a heirloom in your family. Explore my gallery and contact me when you are ready to experience craftsmanship
at it’s best.
</p>
</div>
</div>

Looks like the outer container will be a background image, then you will have another container to hold the text which will could use the the background-color: RGBA property.
html, body {
height: 100%;
padding: 0;
margin: 0;
}
.container {
height: 100%;
background: url(link/to/image) center center;
background-size: cover;
// Use prefixes
}
.inner-container {
background-color: rgba(255, 255, 255, 0.6);
color: #000;
width: 500px;
margin: 60px auto;
}
Please make sure you explain as much as possible in your example code, SO isn't here to code for you :)
Here is a pretty useful link explaining RBGA
https://css-tricks.com/rgba-browser-support/

Related

portrait images not displaying correctly - much too tall

I have several dynamic lightbox galleries on my site (this is for the revamp of our current site and is not live yet). Everything works, but for some reason, and I cannot for the life of me figure out why, my portrait images are coming out very tall compared to other images in the galleries. This seems to be much worse are very narrow images. Any help with this would be much appreciated.
I have tried to hardcode the height and width, and tried to create a special class in the css. Nothing I have tried has worked. I am using the lightbox2 from Lokesh Dhakar. I contacted him about this issue and he stated it was a css thing and suggested that I post something here for help. I do have screenshots of what I would consider an acceptable portrait image and an unacceptable portrait image.
here is the basic html for the section I am describing:
<div class="gallery1">
<img src="Halloween On The Farm 10-19-08/Photo10.jpg" alt="5th Grade Volunteers" width="185" height="155">
<img src="Halloween On The Farm 10-19-08/Thumbnails/Thumb11.jpg" alt="This 6th Grade Girl Made her Jack-In-The-Box Costume All By Herself">
<img src="Halloween On The Farm 10-19-08/Thumbnails/Thumb12.jpg" alt="This 6th Grade Girl Made her Jack-In-The-Box Costume All By Herself">
here's the css:
.gallery1 {
display: block;
border-radius: 25px 25px 25px 25px;
padding: 10px;
}
.gallery1 img {
border-radius: 25px 25px 25px 25px;
padding: 15px;
width: 200px;
transition: 1.0s;
cursor: pointer;
}
.gallery1 img:hover
{
transform: scale(1.1);
}
The expected results are that the images will display correctly and not much larger than anticipated. So far, my actual results have been no success.
This should do the job (it's the same as background-size: contain only for images instead of background-images):
.gallery1 {
object-fit: contain;
}
Edit: the question was unclear as to the desired result. The actual case was solved by setting a height to the images themselves:
.gallery1 {
display: block;
width: 100%;
border-radius: 25px 25px 25px 25px;
padding: 10px;
}
.gallery1 img {
border-radius: 25px 25px 25px 25px;
padding: 15px;
max-width: 100%;
height: 200px; /* max-height: 200px; */
transition: 1.0s;
cursor: pointer;
}

Block with image and text using Bulma CSS

I try to make this block image with text using Bulma CSS. I've tried a lot of things (relative, z-index, etc.) and I didn't succeed making something great for desktop or mobile. Every time, the text is overflowed or get outside the box. I can't set title character limit, so I try also to have a word-break at a second line if possible.
Here is a sample of what I'm looking for :
Here is my HTML :
<div class="block_article" data-overlay>
<img src="/static/img/{{ article.image }}" alt="" />
<span>{{ article.name }}</span>
</div>
And my current CSS (not working) :
.block_article {
position: relative;
width: 500px;
height: 250px;
}
.block_article span {
position: absolute;
top: 50px;
left: 5%;
width: 100%;
color: white;
text-shadow: 2px 2px black;
font-size: 1.3em;
}
Result :
Is there some tips for that kind of thing, or a Bulma extension for this ?
Thanks for your help !
When using Bulma, have a look at the .hero element: https://bulma.io/documentation/layout/hero/. This might be what you are looking for. As Viira mentioned, you could add your image to the background (using background-image).
Also, learning how to center things (https://www.w3.org/Style/Examples/007/center.en.html) might be useful to you.
Here's my final HTML and CSS for people who are in the same case. It's probably not perfect, but this is a good start...
<div class="hero block_article" style="background-image: url('/static/img/{{ article.image }}');">
<span>{{ article.name }}</span>
</div>
.block_article {
width: 500px;
height: 250px;
background-size: cover;
line-height: 230px;
text-align: center;
border-radius: 10px;
}
.block_article span {
color: white;
text-shadow: 2px 2px black;
font-size: 1.3em;
}
Result :

Replicate light effects with transparency

as a medium of learning I try to replicate some things I see in the Internet. A friend of mine that knows what am I doing, saw a template and asked me to replicate part of it for his web page, I already have most of what I needed from the template, but the thing he liked the most I tried and failed and I am not understanding what is the magic involved in this template...
What I need is to replicate the main sheet transparency and the light effect behind it, the transparency I made was with a black 1x1 png made on the GIMP(I can't buy the Photoshop) I also have a nice pattern like in the template since it is one of the things my friend asked...
this is the effect I want, I tried messing around with shadows, but didn't get what i wanted I ended up deleting the code, now all I have is this:
HTML:
<body>
<div id="box"></div>
<div id="light"></div>
CSS:
#light{
border:solid 0px white;
height:550px;
width:800px;
left:50%;
margin-top:130px;
margin-left:-400px;
z-index:-1000;
position:absolute;
box-shadow: 0px 0px 300px #929292;
border-radius:100px;
background-color:#929292;
opacity:0.4;
}
#box{
background-image:url(../images/shtr.png);
margin:0px auto 0px;
width:1060px;
height:auto;
border:solid 0px white;
}
i don't know if i need to use jquery or javascript, or if that would help in the page performance...
There are some CSS3 things you can do here.
The first thing you need to do is setup the divs with the texture and highlights. The div with the highlight should ideally be a child of the textured div.
HTML:
<div class="wrap">
<div class="transp"></div>
</div>
Next you need to apply the effects and backgrounds to the correct elements:
CSS:
.wrap
{
background: url(http://wallpoper.com/images/00/35/83/02/pattern-patterns_00358302.jpg);
height: 500px;
width: 500px;
}
.transp
{
position: relative;
top: 20px;
left: 30px;
background: rgba(0, 0, 0, .7);
height: 100px;
width: 100px;
box-shadow: 0px 0px 30px #fff;
}
http://jsfiddle.net/7fTAH/
I managed to get it done, i created a new div that casts a shadow, placed it outside of the screen(left:100%;) and the shadow is casted to the center with the color #CECECE the HTML code:
<div id="light"></div>
<div id="box">
( ... content ... )
</div>
in the CSS :
#light{
position: absolute;
background: rgba(0, 0, 0, 0);
height: 800px;
width: 840px;
z-index:-1000;
opacity:0.15;
}
#box{
background-image:url(../images/shtr.png);/*black 50-60% transparent 1x1 image*/
margin:0px auto 0px;
width:1060px;
height:auto;
border:solid 0px white;
}
and to cast the shadow I used a jQuery script, via only css it wasn't working i don't know exactly why... the code:
$(document).ready(function() {
myWidth = window.innerWidth;
myHeight = window.innerHeight;
var A = -myWidth - 49.5*myWidth/60
$("#brilho_grande").css("box-shadow", A+"px 0px 10000px 100px #CECECE");
$("#brilho_grande").css("left", 2*myWidth+"px");
$("#brilho_grande").css("top", "339px");
});

CSS Can't figure out why div disappears

I'm trying to make some tabs for a search bar, by using 2 images, inside 2 seperate divs, but for some reason it will only show one image. One or the other. If I comment out the home-searchbar-school id from the css, the professor tab shows, otherwise only the school will show, and it shows up where the professor tab should be. When I look to see where the divs are in google chrome's dev helper, it shows them in the right spot, so Im kind of stumped.
Here's the HTML:
<div id="home-searchbar">
<div id="home-searchbar-tabs">
<div id="home-searchbar-professor" class="home-searchbar-tab">
</div>
<div id="home-searchbar-school" class="home-searchbar-tab">
</div>
</div>
<div id="home-searchbar-container">
</div>
</div>
and the CSS:
#home-searchbar{
margin-left: 20px;
float: left;
height: 115px;
width: 980px;
background-color: green;
}
#home-searchbar-tabs{
float: left;
width: 980px;
height: 32px;
background-color: red;
}
.home-searchbar-tab{
background-color: yellow;
width: 190px;
height: 32px;
float: left;
}
#home-searchbar-professor{
background: url('../img/searchtabs.png') 0 0 no-repeat;
}
#home-searchbar-professor{
background: url('../img/searchtabsinactive.png') 0 -64px no-repeat;
}
#home-searchbar-container{
float: left;
width: 980px;
height: 83px;
background-color: purple;
}
the images are sprites, those are working correctly so I'll only upload one of them.
The other image is the same just different color scheme.
Also a random little question, is that good style for having a class and id in the divs? I'm still learning about CSS so was wondering if that was the correct way/optimal way to use both in a div?
Thanks a lot for any help or advice you can give!
Ok here is the answer:
"both background css uses the same id, #home-searchbar-professor"
ty the rep, and ur css is ok btw
#home-searchbar-professor{
background: url('../img/searchtabs.png') 0 0 no-repeat;
}
#home-searchbar-professor{
background: url('../img/searchtabsinactive.png') 0 -64px no-repeat;
}
both are called home-searchbar-professor, so rename one to home-searchbar-school

CSS - problem with fixed height div

Basically I can't get the div that holds all the content to move down with the content itself. If I take out the fixed height on the comborder div it disappears. The content remains in place, though over the bg image. Does anyone see any solution to this? I've tried a whole lot and can't come up with anything. I just want to base the height of the content div on the height of the content, like a div usually works. Thanks a bunch!
Here's the site: http://www.drdopamine.com/kineticaid/community.php?page=profile&id=1
Here's the relevant CSS:
.wrap {margin: 0 auto; }
.abs { position:absolute; }
.rel { position:relative; }
div.comborder {
width:900px;
height:600px;
background-image: url(http://www.drdopamine.com/kineticaid/pics/bg.jpg);
-moz-border-radius: 30px;
border-radius: 30px;
z-index: 10;
}
div.comcon {
background-color: white;
top: 25px;
right: 25px;
bottom: 25px;
left: 25px;
-moz-border-radius: 15px;
border-radius: 15px;
z-index: 11;
}
Here's the relevant HTML:
<div class="comborder wrap rel" style="margin-top:100px;opacity:0.9;z-index:80;">
<div class="comcon abs" style="opacity:none;">
<div class="comhold rel" style="height:100%;width:100%;border:1px solid transparent;">
<?php
if($_GET['page'] == "profile") {
include_once('profile.php');
}
if($_GET['page'] == "editprofile") {
include_once('editprofile.php');
}
?>
</div>
</div>
</div>
Do this:
body.combody {
background-attachment: scroll;
background-clip: border-box;
background-color: transparent;
background-image: url("http://www.psdgraphics.com/file/blue-sky-background.jpg");
background-origin: padding-box;
background-position: left center;
background-repeat: repeat;
background-size: 110% auto;
height: 100%;
}
div.comborder {
background-image: url("http://www.drdopamine.com/kineticaid/pics/bg.jpg");
border-radius: 30px 30px 30px 30px;
height: 100%;
width: 900px;
z-index: 10;
}
What is important to notice is that both the body and the div have a 100% height.
That might help you.
Absolute positioning removes the content div (and everything else) from the flow of the page. That makes it so the containers don't know the size of the inner elements.
Remove all the .abs classes from everything inside the container, and the white background will correctly stretch as you want. However, it also stretches over the black border, so you'd have to find different way to create it.
More general advice:
.wrap {margin: 0 auto; }
.abs { position:absolute; }
.rel { position:relative; }
These are just plain bad ideas. It looks like you saw or were told about always putting CSS into a CSS file and never in HTML; a good idea when done right, but classes should identify content, not styles. For example:
.sidebar-image { /* css here */ }
.sidebar-donate ( /* css here */ }
.sidebar-infobox { /* css here */ }
It creates duplicate position: tags and so on, but it's also much easier to understand and much easier to get the results you want, since fixing your current problem involves editing the HTML when it should be a CSS problem.

Resources