I am wanting to implement an svg using the ::after pseudo-element. When I run my code, it works perfectly in Firefox,
but in Chrome the svg (down arrow) is non-existent.
There were quite a few questions and answers regarding this problem, but every one of them addressed a code issue that others were having and did not pertain to me.
My code follows:
HTML
<div class="select-box">
<div class="acronym">DRY</div>
<div>Don't Repeat Yourself</div>
</div>
CSS
.select-box {
position: relative;
display: flex;
padding: 8px 25px;
font-family: 'Catamaran', 'Arial', sans-serif;
font-size: 20px;
background-color: none;
border: solid 1px black;
border-radius: 12px;
color: black;
cursor: pointer;
& .acronym {
width: 55px;
color: #c29b69;
}
}
.select-box::after {
content: "";
display: block;
background: url("/arrow.svg");
background-size: contain;
background-repeat: no-repeat;
position: absolute;
height: 22%;
width: 3.2rem;
top: 20px;
right: 0;
transform: rotateX(180deg);
}
I appologize. I wanted to include a codepen of the issue, but that would involve asset hosting to include the svg, which is a Pro plan. I am not a professional - just an amateur passionate about coding. Thanks for any help you can offer-up.
This snippet works - albeit with a different arrow SVG - on Chrome/Edge/Firefox on Windows 10. SO (imgur) does not allow SVGs to be loaded so the pointer SVG is hosted as a temporary one and won't be there forever.
.select-box {
position: relative;
display: flex;
padding: 8px 25px;
font-family: 'Catamaran', 'Arial', sans-serif;
font-size: 20px;
background-color: none;
border: solid 1px black;
border-radius: 12px;
color: black;
cursor: pointer;
}
.select-box .acronym {
width: 55px;
color: #c29b69;
}
.select-box::after {
content: "";
display: block;
background: url("https://ahweb.org.uk/temp2.svg");
background-size: contain;
background-repeat: no-repeat;
position: absolute;
height: 22%;
width: 3.2rem;
top: 20px;
right: 0px;
transform: rotateX(180deg);
}
<div class="select-box">
<div class="acronym">DRY</div>
<div>Don't Repeat Yourself</div>
</div>
So what can be the problem? The only thing I can think of is that there is some problem either with using a 3d rotation on your particular SVG (?backface-visibility - though the default should be set at visible) or the rotation about the X axis is flipping the SVG out of the containing element.
Could you try first not having any transform on the pointer to see if it is visible, and then trying a rotate(180deg) instead (i.e. about the z-axis) so there's no worry about what is happening, or not, in 3D and so that the image stays in place rather than moving down.
As A Haworth pointed out, it was a reference issue. I was applying the svg via the background:url(); property for the first time. It worked well with just an html and css file with background: url("img/arrow.svg"). But the trouble was that I was trying to reference the svg the same way when using node/sass. The proper way to reference it in that case was background: url("../img/arrow.svg"). Thanks for the heads-up A Hawthorn. That led me to the answer here,
Related
I am a novice as best please pardon me, but I'm learning.
I can illustrate what I need with an image.
Vertical Navigation 'White Curved Tab as Selector':
This is my CSS now, it's vertical and I can rotate the text, the way it should be, I'm not too concerned now about the visual appearance, I just need to have the functionality..
I would like the title of the pages in the navigation bar, to have an overlay icon, SVG or png, to hover over it when the mouse moves over and to continue following the mouse cursor within in the bounds of the nav bar, not like an ordinary overlay image, and if page is selected to leave that image or icon there as the highlight, so the final result will look something like the image above.
Here is my CSS thus far:
`.body{}
`.mobile-menu-nav.moved {
max-width: 75px;
width: 75px`
}
#head{
min-width: 100%;
padding:0px;
margin-left: -200px;
margin-right: -200px;
position:cover
}
#main-wrapper{
min-width: 100%;
padding:0px;
margin-left: -200px;
margin-right: -200px;
position:cover
}
.menu {
width: 60px;
height: 100%;
position: left;
border-radius: 15px;
border: 1px solid #00F;
}
.mobile-menu-nav li a {
font-family: Arial, sans-serif;
font-size: 12px;
color: #FFF;
background-color: transparent;
width: 100px;
height: 22%;
border: 1px solid transparent;
margin: auto;
margin-top: 50%;
margin-bottom: 50%;
margin-left: -15px;
position: center;
transform: rotate(-90deg);
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
}
-o-transform: rotate(-90deg);
`
https://sproutsa.co.za
Thanks much.
I think it would be the best to use ::after or ::before
.mobile-menu-nav li a:after {
content: "";
display: inline-block;
width: 20px;
height: 20px;
background: transparent url('../images/your_image.svg') no-repeat;
background-size: contain;
background-position: center;
}
I have added background size and position, but ofcourse style it as you need it. Using this solution you can manipulate images using background properties.
Second similar solution is:
.mobile-menu-nav li a {
display: flex;
}
.mobile-menu-nav li a::after{
content: url('../images/your_image.svg');
width: 20px;
padding-left: 8px;
}
SVG should contain itself inside after element, like background-size: contain; so it works fine, but it won't work for images (.png, .jpg) and you can't change those. You can only prepare .png image to be final size.
Use ::after or ::before depending on position you want icons to be, right or left.
I have a problem with a border in Chrome. The green border has some grey lines.
Firefox: not visible -> ok!
Chrome: not visible but visible in the dev tools, mobile phone.
Chrome on my phone: visible
Here is a screenshot that shows my problems!
https://abload.de/img/cssiee7s.jpg
1) When you go to http://www.seelenpuls.at/hpneu/m_biografie_leander_de.php
there are two small grey lines
2) When you go to http://www.seelenpuls.at/hpneu/m_neues_de.php there are even more problems.
3) The menu button has an orange border (mobile only) ... and I don't know why as there is no such color in my CSS.
Please help!
Here's the code. The bold part is the border that causes the problems.
* { padding: 0; margin: 0; }
body
{
font-family: sans-serif, Verdana, Arial;
color: #000000;
background-color: #556B2F;
}
#center {
position: relative;
width: 350px;
height: 630px;
box-sizing: border-box;
margin: 5px auto 0px auto;
}
#logo {
position: absolute;
width: 350px;
height: 220px;
background-color: #ffffff;
box-sizing: border-box;
background-image: url("img/m_bg_c.jpg");
background-repeat: no-repeat;
background-size: 350px 220px;
}
#navi
{
position: absolute;
top: 175px;
width: 60px;
height: 40px;
font-size: 16px;
color: #000000;
background-color: #ffffff;
margin-left: 10px;
}
#header
{
position: absolute;
top: 187px;
width: 238px;
height: 30px;
font-size: 16px;
color: #000000;
left: 85px;
}
#content
{
position: absolute;
top: 218px;
width: 350px;
box-sizing: border-box;
color: #000000;
background-color: #ffffff;
font-size: 14px;
overflow: auto;
padding-left: 5px;
padding-right: 5px;
**border-bottom: 5px solid #556B2F**;
}
Ok so there is a couple of things that are going on in your css.
White lines
For your content div, I would use a width of 100% for mobile devices now, as you scale to tablets and desktops you can change to a more fixed or fluid width. I would also remove the border bottom property. This is not fully extending to the width of the content box and I am unsure if it has to do with the border-sizing property you are using. I would also apply the border-sizing this way so it is applied to every element in your html
* {
box-sizing: border-box;
}
Orange border - this is caused by the :focus pseudo css property of the button you are using, you can remove it this way
button:focus {
outline: none;
}
CSS Normalize or CSS Reset - consider using one of these stylesheets in your website. They help you rendering all elements more consistently through all browsers. This will save you the time of remove the :focus property, like I mentioned above in any project moving forward. Most popular CSS frameworks utilize this to normalize basic styles.
Link to Normalize.css
Having an issue I don't understand. The only way I've been able to center a button on my page perfectly across all devices is if I apply a width: 100% to it.
Issue with this however, is it then makes a sprawling button, way too wide. I'd like to cut it down. The problem is, anytime I get rid of the width: 100% in any way, it makes the perfect button position go haywire.
Any thoughts on how I can have my button centered, but also not super wide and sprawled out. Thank you. -Wilson
link to site: http://www.wilsonschlamme.com/test3.html?
CSS:
img {
width:100%;
max-width:500px;
max-height:340px;
box-shadow: 5px 5px 5px grey;
border-style: groove;
border-width: 1px;
position: absolute;
top: 107px;
}
button {
color: #900;
font-weight: bold;
font-size: 150%;
text-transform: uppercase;
width: 100%;
position: relative;
top: 600px;
}
#ShowText{
width: 800px; /* change to your preferences */
overflow:hidden; /* older browsers */
position: absolute;
margin-top: 500px;
text-align: center;
margin-left: -140px;
font-size: 18px;
font-family: vendetta, serif;
line-height: 25px;
}
h1{
position: absolute;
top: 5px;
font-size: 250%;
width: 800px; /* change to your preferences */
overflow:hidden; /* older browsers */
font-family: hobeaux-rococeaux-sherman, sans-serif;
}
#wrapper {
width: 500px;
margin: 0 auto;
}
take a look at this site there's a complete guide to centering a div.
http://www.tipue.com/blog/center-a-div/
I don't know what's your base using absolute positioning for mostly of your element, but to answer your issue, give text-align:center; to #wrapper, then give text-align:left for each of #wrapper children, except the button.
In the following example, I demonstrate the issue where the colors are perfect, except for portions at different %'s results in some or all of the text being obscured.
What I would like to achieve, is to somehow assign the font color to be the difference of the background. I recall seeing something many years ago in DHTML which allowed for this. The result I am looking for is as follows
In the 50% sample, the '5' would be in white, and the '0' would be in black.
In the 75% sample, the '75' would be in white.
In the 20% sample, the '20' would be in black.
I believe there is a way to do this using CSS/CSS3, but I am unable to locate information on it.
The resulting style information should be contained inside the 'p' style in the CSS file. No 'tricks' like splitting data or altering the HTML using JavaScript / etc. The number inside the <p> element should remain whole and in tact.
body {
background: #000000;
}
p {
background: #ffffff;
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAA1BMVEVilQmZw+RvAAAAAXRSTlOF3TSvyQAAAD1JREFUeNrtwQENAAAAwqD3T20PBxQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPBmnQgAAd4aVNwAAAAASUVORK5CYII=");
background-repeat: repeat-y;
background-size: 0% auto;
color: #ffffff;
padding: 5px;
text-align: center;
border: 1px solid #3E8096;
display: block;
}
<p style="background-size: 50% auto !important">50</p>
<p style="background-size: 75% auto !important">75</p>
<p style="background-size: 20% auto !important">20</p>
Note:
I was considering a drop-shadow, however this would result in a funny
looking font when it is a white font. I also considered encapsulating
the text in a border, however the ideal result would be for the font
to adjust based on background.
body { background: navy }
div {
background-color: white;
display: inline-block;
border: 1px solid red;
width: 200px;
font-size: 50px;
text-align: center;
position: relative;
color: red;
}
span {
content: '';
position: absolute;
background: cyan;
width: 50%;
top: 0;
left: 0;
height: 100%;
display: inline-block;
mix-blend-mode: difference;
}
<div>
0000 <span></span>
</div>
body { background: navy }
div {
background-color: white;
display: inline-block;
border: 1px solid red;
width: 200px;
font-size: 50px;
text-align: center;
position: relative;
color: red;
}
div:after {
content: '';
position: absolute;
background: cyan;
width: 50%;
top: 0;
left: 0;
height: 100%;
display: inline-block;
mix-blend-mode: difference;
}
<div>00000</div>
I am having issues viewing my site in Internet Explorer. In the following CSS/HTML the image is supposed to be outlined, curved radius, and scaled to fit. However IE 8 does not scale the image, curve the corners, nor does the outline appear. Here is the jsfiddle: http://jsfiddle.net/pave4/ This page is fine in the newest IE (IE8), however I need to make sure it also works on older versions of IE.
HTML:
<ul>
<li>
<a href="/aboutme/">
<span class="img-outline"><span class="page-img" id="aboutme"></span></span>
<span class="page-title">About Me</span>
</a>
</li>
</ul>
CSS:
.page-title {
text-align: center;
display:block;
text-decoration: none;
}
.img-outline {
height: 100%;
background: rgba(0, 0, 0, .3);
padding: 5px;
display: block;
margin-left: auto;
margin-right: auto;
-webkit-border-radius: 18%;
-moz-border-radius: 18%;
border-radius: 18%;
}
.page-img {
height: 100%;
background: rgba(50, 50, 50, 1);
background-size:115px 115px;
background-repeat:no-repeat;
display: block;
margin-left: auto;
margin-right: auto;
-webkit-border-radius: 15%;
-moz-border-radius: 15%;
border-radius: 15%;
}
li,
li.current,
li.current:visited {
margin-left: 1px;
margin-right: 1px;
width: 118px;
height: 112px;
display: block;
float: left;
position: relative;
opacity: .6;
}
li:hover { opacity: 1; }
li .img-outline {
width: 70px;
height: 70px;
}
li .page-img {
background-size:70px 70px;
}
li #aboutme {
background-color: rgb(36, 112, 245);
background-image: url('http://www.rasnickjewelry.com/images/uploads/900_Animals_300/901_Elephant_Head_Ring_side_R300.jpg');
}
You're using lots of CSS3 attributes that IE8 doesn't support I'm afraid.
As I said in my comment to your original Question, IE up to 8 didn't support rgba colors. Since you don't use the alpha channel, use background-color: #323232; instead.
IE8 also doesn't support the standard opacity property, you need filter: alpha(opacity=60); instead (percantage value sans the %). Related could be that elements in IE require layout to render correctly: There is a bunch of articles covering this topic. A good one is On Having Layout.
To get a feel for what css properties and features are supported use resources such as When Can I Use or Quirksmode
Do not resize images with styles upload them in the exact size, that will save you loading time.
About the other syles like the border radius try to use this tool http://css3pie.com/