I'm really not sure how to pose this question any other way, but I'm trying to load text on top of an image - which appears to be a tricky task in itself, but I've got it going using this tutorial. Unfortunately, the tutorial is slightly out of date and I can't figure out a way to dynamically change both the font size and the span size for mobile and still maintain the text in the correct place on top of the image.
When the window is resized the text and the box doesn't resize properly (it overflows outside of the image).
I've tried percentage sizing as well as other techniques with little luck. The CSS I'm using to display the text over the image with a background can be seen below.
What's the best practice for overlaying text on an image and how would one go about making it responsive? This is what I'm trying to use for desktop browsers right now:
.herotext span {
position: absolute;
top: 80%;
font-family: 'museo_slab500';
font-size: 150%;
color: #fff;
padding-left: 20px;
width: 40%;
line-height: 35px;
background: rgb(0, 0, 0);
background: rgba(0, 0, 0, 0.7);
}
Does anyone have some advice on how to handle this properly these days? The article I mention above is from 2009 and I suspect it's not the best way to overlay text.
Here are the changes I would make:
Position the span using bottom rather than top, so you always have a specific margin between the span and the bottom of the image.
Use a percentage-based line-height so that it will change proportionally to the font-size
Add some padding to the right of the span, so the text doesn't bump right up on the edge of the span
Updated CSS:
.herotext span {
position: absolute;
bottom: 20px;
font-family: 'museo_slab500';
font-size: 150%;
color: #fff;
padding: 0 20px;
width: 40%;
line-height: 150%;
background: rgb(0, 0, 0);
background: rgba(0, 0, 0, 0.7);
}
Related
Context:
I'm trying to use CSS to display playing cards for a game I'm designing on my free time
What I'm trying to do, specifically:
Nothing revolutionary, there's a place on my cards in which I need to write some text, and I want to center the text so that it looks good
What I did:
The relevant part of the HTML is simply this:
<div class = "card_header">
<div class = "card_cost">1</div>
</div>
And the relevant CSS:
.card_header {
position: relative;
top: 110px;
box-sizing: border-box;
width: 100%;
height: 75px;
}
.card_cost {
position: absolute;
top: 50%;
right: 165px;
transform: translateY(-50%);
font-size: 60px;
font-weight: bold;
}
What's the problem:
I expected the card_cost text to be vertically centered between the top and bottom borders of the card_header, but under the browser I was using (Firefox), the text was a bit too high. I tried to fix this by using top: calc(50% + 4px);, which looks like this (a bit better):
Since it felt a bit too tweaky for my taste, I went and checked how it looked like under another browser (Safari) to see whether it looked the same, and it looks like this:
which is the opposite problem: the text is too low.
I've tried adding border: 1px dotted gray; to get a better idea of what's happening, and here's what I see (safari on the left, firefox on the right):
The text seems to be vertically centered within card_cost in Safari (which means it would probably get centered properly if I simply used top: 50%; as I originally did), but in Firefox the box seems to be bigger and text way-high within the box.
What exactly is going on here? Why is this behaving differently depending on the browser? Is there a way to make this render the same? Or, more broadly, is there any browser-independent way for me to make the text vertically centered here?
Edit:
Since someone mentioned line-height in the comments, here's what it looks like when I add line-height: 1; for card_cost (again, Safari on the left and Firefox on the right):
With this, the text doesn't seem as centered as before under Safari, and it's even more clear that the text is way-high under Firefox
I usually take approach with invincible :before on parent with 100% of height and vertical-align: middle;. That way this :before justifies other inline-block content:
// I would apply this style everywhere
.card_header,
.card_header * {
font-family: arial;
box-sizing: border-box;
}
.card_header {
position: relative;
top: 110px;
width: 100%;
height: 75px;
text-align: center;
background-color: rgba(100, 0, 0, .1);
}
.card_header:before {
content: '';
height: 100%;
display: inline-block;
vertical-align: middle;
border-left: 1px solid blue;
}
.card_cost {
display: inline-block;
font-size: 60px;
height: 60px;
font-weight: bold;
vertical-align: middle;
background-color: rgba(0, 0, 100, .1);
}
<div class="card_header">
<div class="card_cost">1</div>
</div>
I'm making a plotted chart in react.js and have a tooltip div that is created from the absolute position of the plot point x/y coordinates. When the popover text is too long it collides with the browser only on the left side, for whatever reason it wraps properly on the right side as seen in the photo. How do I get the wrapping behavior to occur on both sides?
.tooltip {
position: absolute;
text-align: center;
padding: 2px;
font: 12px sans-serif;
background: white;
opacity: 0.8;
border: 0px;
border-radius: 3px;
pointer-events: none;
min-width: 60px;
}
I don't have the code, thus I cannot code it, but I assume you would do a #media query on some particular screen width and change the .tooltip css properties - the width for example.
Hope it helps!
I have a simple page with two offcanvas menus, one in which side, they both work normally when in english, but since I also need to support arabic, I use the dir="rtl" in the html tag, and with it the right offcanvas menu have some weird behaviour on Chrome, looks like a repaint issue, when I resize the window it goes to the right position (sometimes it goes randomly after a few seconds as well).
I'm using transform: translateX(); and transform: translate3d(); in the body to achieve this, and as far as I can see there's nothing wrong.
Here's a codepen example of the bug: http://codepen.io/Ghostavio/pen/WbgXXZ
Its a simple thing I did Hope This is your answer
What I did was made the body position Fixd
in body:
position: fixed
Your New CSS will look like this:
box-sizing: border-box
body
padding: 5%
position: fixed /*Changed Here*/
overflow-x: hidden
transition: .3s ease-in-out transform
&.left-offcanvas-active
transform: translateX(270px)
//transform: translate3d(270px, 0, 0)
&.right-offcanvas-active
transform: translateX(-270px)
//transform: translate3d(-270px, 0, 0)
header
text-align: center
position: relative
img, svg
vertical-align: middle
a
text-decoration: none
.logo img
width: 240px
max-width: 100%
.gc
fill: #8E8E8E
.content
text-align: justify
.hamburger-icon
position: absolute
top: 10px
left: 0
cursor: pointer
.second-icon
left: auto
right: 0
.left-offcanvas, .right-offcanvas
witdh: 270px
min-width: 270px
height: 100%
background-color: #BABACA
position: fixed
display: block
top: 5%
.left-offcanvas
left: -270px
.right-offcanvas
right: -270px
.offcanvas-links
display: block
padding: 20px
color: #117EBF
border-bottom: 1px solid #E1E1E1
font-weight: 800
text-decoration: none
span
background-color: #C80428
color: #FFF
padding: 0 5px
border-radius: 2px
font-weight: 400
float: right
Hope this helps you.
I had a similar issue creating a sticky header on a horizontal scrolling table for RTL. What I found is that in order to get position : sticky to work for RTL without JS, I had to assign z-index to both the sticky column (sticky header) and the scrollable columns.
At first I used JS to position everything and add offset padding to get the sticky header effect. But after a walking away in frustration and returning to it days later did I come up with a CSS only solution.
JSfiddle example
Would just like to ask what could possibly go wrong, I'm using wordpress and modified the theme css few years ago, I havent check the site for years and upon looking the hover for each element of circle was staying on hover effect even if it is not hovered. On its normal view, the inner circle which is dark gray together with the post title should not be visble until it is hovered please see the image:
Any thoughts? the site is -- --
Thanks
the h3 in the a tag has colour values
div.caption.boxcaption a.view h3 { color:Transparent; }
div.caption.boxcaption a.view:hover h3 { color:White; }
You need to position the background blocking image on the a.view instead of the div.boxcaption changing its position to off screen on a.view:hover
div.boxcaption {
background: url("images/circle_caption.png") no-repeat scroll center top rgba(0, 0, 0, 0);
height: 112px;
left: 0;
margin-left: 21px;
padding: 65px 10px;
position: absolute;
text-align: center;
top: 21px;
width: 210px;
z-index: 1000;
}
I'm trying to figure out the best way to create three 284x87 rounded rectangle boxes, which will contain an icon on the left and text to the right. Is it worth trying to pull this off purely with CSS, or is there no way to get out of using images? Here's what I have so far, using a background image of the entire image:
<style type="text/css">
.blurect {
background-image: url(blurect1.gif);
width: 284px;
height: 87px;
color: #FFF;
}
</style>
<div class="blurect">Test</div>
You can certainly use CSS. As cale_b said, set a background image with the appropriate position, then adjust the padding-left so that the text doesn't overlap the icon. Here's the appropriate CSS:
.rect {
background: url(path/to/image.png) 4px center no-repeat;
padding: 4px 4px 4px 24px;
width: 200px;
height: 20px;
line-height: 20px;
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
}
4px center in the background rule sets the image 4px from the left edge and centered vertically. The left padding is set to 24px to move the text away from the background icon
Here's a demo:
http://jsfiddle.net/6p8Rz/
The dimensions are obviously adjustable to suit your needs