Change button-text based on viewport width
I have a button to close a lightbox on my home page.
This text says "Close" and is right-aligned. However, it can overlap with the heading text when the viewport width is less than 400 pixels.
So, I want to exchange it with "X" using media queries.
I've tried .button:before
which works, but I can't get rid of the original "Close" text this way.
How can I achieve this with CSS only?
+3
source to share
4 answers
Consider your button:
<button>Close</button>
Now replace 'Close' with 'X':
Set below CSS in your media query:
button {
visibility: hidden;
}
button:after {
content:'X';
visibility:visible;
}
Try http://jsfiddle.net/ZBj2m/685/
Hope it works for you.
0
source to share
Try the following:
HTML:
<div id="lightBox">
<h1>Heading Goes Here</h1>
<button id="close">Close</button>
</div>
CSS
#lightBox{
width:100%;
height:100%;
background:grey;
position:relative;
}
#close{
position:absolute;
right:5px;
bottom:5px;
border:none;
padding:5px;
height:25px
}
@media screen and (max-width:360px){
#close{
top:-10px !important;
right:-10px !important;
width:25px;
border-radius:25px;
height:25px;
text-indent:-99px;
background-color:red;
}
#close:before{
content:'X';
text-indent: -14px;
color: white;
float: right;
}
}
Demo Fiddle
0
source to share