position:absolute breaks CSS dropdown - css

I am making something with ace editor. As part of this, I have a dropdown menu that allows theme selection. This is on a bar at the top, (which will eventually have more options). I know that, in order to position the bar at the very top, I need to use position:absolute in the CSS code. However, this breaks the dropdown, and it no longer actually drops down. To see what I mean, here is a fiddle. (To compare, removing position: absolute in the CSS for #navbar makes it work fine, but is not at the very top [most visible in a full window].)
Note: In the fiddle, I have removed everything not related to the navbar, such as the ace code.

Seems to work fine if you remove the max-height from .dropChoices, the bottom and overflow on #navbar
// The function changeTheme() is defined in the full code
function toggle(button) {
var dropList = button.nextElementSibling;
function isDropdown() {
return (" " + dropList.className + " ").indexOf(" dropChoices ") > -1;
}
while (!isDropdown) {
dropList = dropList.nextElementSibling;
}
dropList.classList.toggle("hidden");
window.onclick = function(e) {
if (!e.target.matches('.dropButton') && !e.target.matches('.dropChoices')) {
if (!dropList.classList.contains('hidden')) {
dropList.classList.add('hidden');
}
}
}
}
#navbar {
position: absolute;
top: 0;
left: 0;
right: 0;
background-color: dimgray;
}
.navOption {
font-size: 12px;
color: white;
padding: 1px 13px;
}
.dropButton {
box-sizing: border-box;
cursor: pointer;
font-size: 16px;
border: none;
color: white;
padding: 13px 16px;
background-color: inherit;
}
.navOption:hover, .navOption:active, .navOption:focus {
background-color: gray;
outline: none;
}
.dropChoices {
font-size: 16px;
overflow: auto;
display: block;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
z-index: 5;
max-height: calc(100vh - 50px);
}
.dropChoices p {
color: black;
outline: none;
padding: 12px 16px;
cursor: pointer;
margin: 0;
text-align: left;
}
.dropChoices p:hover, .dropChoices p:focus {
background-color: lightgray;
}
p.dropTitle {
cursor: initial;
}
p.dropTitle:hover {
background-color: #f9f9f9;
}
.hidden {
display: none;
}
<!-- This code is slightly shortened, and only contains the relevant things -->
<div id="navbar">
<button onclick="toggle(this)" class="dropButton navOption">Themes</button>
<div id="themesList" class="dropChoices hidden">
<p class="dropTitle"><b>Light</b></p>
<p tabindex="0" id="chrome" onclick="changeTheme(this.id)">Chrome</p>
<p tabindex="0" id="clouds" onclick="changeTheme(this.id)">Clouds</p>
<p tabindex="0" id="crimson_editor" onclick="changeTheme(this.id)">Crimson Editor</p>
<p tabindex="0" id="dawn" onclick="changeTheme(this.id)">Dawn</p>
<p tabindex="0" id="dreamweaver" onclick="changeTheme(this.id)">Dreamweaver</p>
<p tabindex="0" id="eclipse" onclick="changeTheme(this.id)">Eclipse</p>
<p tabindex="0" id="gitHub" onclick="changeTheme(this.id)">GitHub</p>
<p tabindex="0" id="iplastic" onclick="changeTheme(this.id)">IPlastic</p>
<p tabindex="0" id="solarized_light" onclick="changeTheme(this.id)">Solarized Light</p>
<p tabindex="0" id="textmate" onclick="changeTheme(this.id)">TextMate</p>
<p tabindex="0" id="tomorrow" onclick="changeTheme(this.id)">Tomorrow</p>
<p tabindex="0" id="xcode" onclick="changeTheme(this.id)">XCode</p>
<p tabindex="0" id="kuroir" onclick="changeTheme(this.id)">Kuroir</p>
<p tabindex="0" id="katzenmilch" onclick="changeTheme(this.id)">KatzenMilch</p>
<p tabindex="0" id="sqlserver" onclick="changeTheme(this.id)">SQL Server</p>
<p class="dropTitle"><b>Dark</b></p>
<p tabindex="0" id="ambiance" onclick="changeTheme(this.id)">Ambiance</p>
<p tabindex="0" id="chaos" onclick="changeTheme(this.id)">Chaos</p>
<p tabindex="0" id="clouds_midnight" onclick="changeTheme(this.id)">Clouds Midnight</p>
<p tabindex="0" id="cobalt" onclick="changeTheme(this.id)">Cobalt</p>
<p tabindex="0" id="gruvbox" onclick="changeTheme(this.id)">Gruvbox</p>
<p tabindex="0" id="idle_fingers" onclick="changeTheme(this.id)">idle Fingers</p>
<p tabindex="0" id="kr_theme" onclick="changeTheme(this.id)">krTheme</p>
<p tabindex="0" id="merbivore" onclick="changeTheme(this.id)">Merbivore</p>
<p tabindex="0" id="merbivore_soft" onclick="changeTheme(this.id)">Merbivore Soft</p>
<p tabindex="0" id="mono_industrial" onclick="changeTheme(this.id)">Mono Industrial</p>
<p tabindex="0" id="monokai" onclick="changeTheme(this.id)">Monokai</p>
<p tabindex="0" id="pastel_on_dark" onclick="changeTheme(this.id)">Pastel on dark</p>
<p tabindex="0" id="solarized_dark" onclick="changeTheme(this.id)">Solarized Dark</p>
<p tabindex="0" id="terminal" onclick="changeTheme(this.id)">Terminal</p>
<p tabindex="0" id="tomorrow_night" onclick="changeTheme(this.id)">Tomorrow Night</p>
<p tabindex="0" id="tomorrow_night_blue" onclick="changeTheme(this.id)">Tomorrow Night Blue</p>
<p tabindex="0" id="tomorrow_night_bright" onclick="changeTheme(this.id)">Tomorrow Night Bright</p>
<p tabindex="0" id="tomorrow_night_eighties" onclick="changeTheme(this.id)">Tomorrow Night 80s</p>
<p tabindex="0" id="twilight" onclick="changeTheme(this.id)">Twilight</p>
<p tabindex="0" id="vibrant_ink" onclick="changeTheme(this.id)">Vibrant Ink</p>
</div>
</div>

You have to make the drop down relative to the parent if its going to be in absolute position.
Set the parent position to relative, and then the dropdown will be positioned inside or within the parent tag.
Like Example:
<div style="position:relative;">
<div class="dropdown" style="position:absolute; top:0; left:0;">...</div>
</div>

Related

how to unhide a hidden div with bootstrap

I'm working on a site built on bootstrap and have a column down the right side that contains a search module and some other things. it gets hidden on smaller screens. I'm hoping to restore just the search module (and hide everything else but the footer) when pressing a button that gets displayed in the menu.
It sounded simple, but I can't seem to figure out how to override it being hidden. The visibility is set in the style sheet but I also tried setting the visibility on the div itself with d-none d-lg-block - no go.
With below code, when hitting the button, the main container hides (though sometimes only when pressing it twice) but it doesn't restore the sidebar. Which, based on the different things I've tried appears to be as intended, just not what I'm trying to do with it..
I'm sure it's something simple, but I've been staring at this for far too long and I'm not doing well with googling. Thanks in advance for any help/suggestions.
Update: The comment confirming it was out of the realm of bootstrap helped a lot. Updated code below to use javascript to handle activating the search module and hiding the main content. a simple function only goes one way, so I am also hiding the search button itself on click and displaying a close button that reverses the actions. The next step was to reset everything if the page width changes (as this function is only intended to be for smaller screens/mobile, and if you action any of the buttons and then increase page width things stay hidden that shouldn't) so I added a third function that listens for page width changes and resets the visibility of the impacted divs when the size becomes large enough to properly display. it's working in testing, but I'm open to feedback, tips, etc. to make it better.
My sincere thanks to all who have helped me get here!
```
/* Set gray background color and 100% height */
.sidebar {
padding-bottom: 10px;
background-color: #f1f1f1;
text-align: center;
justify-content: center;
}
/* this adds padding to bottom of main container in order to account for footer image */
.pb-6 {
padding-bottom: 5rem !important;
}
/* hides this div on small size */
#media screen and (max-width: 768px) {
div.sidebar {
display: none;
}
div.footerimage {
display: none;
}
}
#media (min-width: 768px) {
/* hides hamburger on bigger screens */
.navbar-brand{
display: none;
}
.navbar-search{
display: none;
}
.navbar-pressed{
display: none;
}
}
/* Set black background color, white text and some padding */
footer {
background-color: #000;
color: #fff;
padding: 15px;
margin:0;
}
body {
margin: 0px;
}
html {
font-family: "Lucida Sans", sans-serif;
}
/* images scales */
img {
max-width: 100%;
height: auto;
}
h1, h2, h3, h4, h5, h6 {
padding: 0px;
margin: 0px;
}
.header {
background-image: url();
background-size: cover;
background-color: #ffffff;
color: #000000;
padding:0;
margin:0;
text-align: center;
width: auto;
height: 100%;
line-height:0;
}
.navbar-pressed {
display: none;
}
.footerimage {
position: relative;
}
.footerpic {
background-image: url();
background-size: contain;
content: '';
height: 200px;
pointer-events: none;
position: absolute;
left: 50%;
top: 0;
transform: translate(-50%, -50%);
width: 200px;
}
/* change the background color */
.navbar-custom {
background-color: #1e73be;
margin-bottom: 0;
border-radius: 0;
padding: 0;
}
/* change the brand and text color */
.navbar-custom .navbar-brand,
.navbar-custom .navbar-text {
color: #ffffff;
}
/* change the link color */
.navbar-custom .navbar-nav .nav-link {
color: #ffffff;
}
/* change the color of navbar title when collapsed */
.navbar-toggler {
color: #ffffff;
}
/* change the color of active or hovered links */
.navbar-custom .nav-item.active .nav-link,
.navbar-custom .nav-item:focus .nav-link,
.navbar-custom .nav-item:hover .nav-link {
color: #ffffff;
background-color: #035a9e;
}
/* for dropdowns only */
.navbar-custom .navbar-nav .dropdown-menu {
background-color: #1e73be;
}
/* dropdown item text color */
.navbar-custom .navbar-nav .dropdown-item {
color: #ffffff;
}
/* dropdown item hover or focus */
.navbar-custom .navbar-nav .dropdown-item:hover,
.navbar-custom .navbar-nav .dropdown-item:focus {
color: #ffffff;
background-color: #035a9e;
}
.navbar-brand img {
height: 30px;
float: left;
margin-left: 20px;
padding: 0;
}
```
```
<!DOCTYPE html><html lang='en'><head><title>menu test</title><meta charset='utf-8'><meta name='viewport' content='width=device-width, initial-scale=1'><META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=iso-8859-1'>
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css'><link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css'><link rel='preconnect' href='https://fonts.gstatic.com'><link href='https://fonts.googleapis.com/css2?family=Atma:wght#600&display=swap' rel='stylesheet'><script src='https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js'></script><script src='https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js'></script><script src='https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js'></script>
<script>
function myFunction() {
document.getElementById("maincontainer").style.display = 'none';
document.getElementById("sidebar").style.display = 'block';
document.getElementById("sidecontentdiv").style.display = 'none';
document.getElementById("navbar-search").style.display = 'none';
document.getElementById("navbar-pressed").style.display = 'block';
}
</script>
<script>
function myCloseFunction() {
document.getElementById("maincontainer").style.display = 'block';
document.getElementById("sidebar").style.display = 'none';
document.getElementById("sidecontentdiv").style.display = 'block';
document.getElementById("navbar-search").style.display = 'block';
document.getElementById("navbar-pressed").style.display = 'none';
}
</script>
<script>
function doSomething(matches) {
if (matches) {
// media query matches
} else {
// media query does not match
document.getElementById("maincontainer").style.display = "";
document.getElementById("sidebar").style.display = "";
document.getElementById("sidecontentdiv").style.display = "";
document.getElementById("navbar-search").style.display = "";
document.getElementById("navbar-pressed").style.display = "";
}
}
const query = window.matchMedia("(max-width: 767px)");
query.addEventListener("change", ({ matches }) => doSomething(matches));
doSomething(query.matches);
</script>
</head>
<body>
<div class='header'></div>
<nav class='navbar navbar-expand-md navbar-custom sticky-top'><div class='navbar-brand'><a href='https://www.url.com'><img src='/images/menu.png' alt='Logo'></a></div><div id='navbar-pressed' class='navbar-pressed ml-auto'><button class='navbar-toggler' type='button' onclick="myCloseFunction()"><i class='fa fa-circle-xmark fa-flip-horizontal' style='color:#ffffff'></i></button></div><div id='navbar-search' class='navbar-search ml-auto'><button class='navbar-toggler' type='button' onclick="myFunction()"><i class='fa-solid fa-magnifying-glass fa-flip-horizontal' style='color:#ffffff'></i></button></div><button class='navbar-toggler' type='button' data-toggle='collapse' data-target='#navbarCollapse'><span class='ml-auto' role='button'><i class='fa fa-bars' style='color:#ffffff'></i> Menu</span></button><div class='collapse navbar-collapse justify-content-between' id='navbarCollapse'><div class='navbar-nav'>
<div class='nav-item'><a href='index.php' class='nav-link'>Home</a></div>
<div class='nav-item'><a href='index.php' class='nav-link'>Home</a></div>
<div class='nav-item'><a href='index.php' class='nav-link'>Home</a></div></div>
</div></nav>
<div class='container-fluid text-center'>
<div class='row content'>
<div class='col-md-9 text-left pb-6' id='maincontainer'>
main body of page
</div>
<div id='sidebar' class='col-md-3 sidebar'>
<div id='searchdiv'>
<div class='sidebarheader rounded'><h4>Search:</h4></div>
<div class='searchbox rounded'>search module</div>
</div>
<div id='sidecontentdiv'>
<div class='sidebarheader rounded'><h4></h4></div>
<div class='searchbox rounded'>unimportant module</div>
</div></div>
<footer class='container-fluid text-center'>
<div class='row'>footer text</div>
</footer>
</div></div>
</body></html>
```
If it's simply hide/show div, why not use JavaScript / jQuery? Like,
<button onclick="myFunction()">src</button>
<div id="attid"></div>
<script>
function myFunction() {
document.getElementById("attid").style.display = 'none';
// or to show
// document.getElementById("attid").style.display = 'block';
}
</script>
Couldn't comment because lack of reputation :)
I think this will help you! Joe
const opener = document.getElementById('opener');
const sidebar = document.getElementById('sidebar');
const closer = document.getElementById('closer');
opener.onclick = function(){
sidebar.style.marginRight = 0
}
closer.onclick = function(){
sidebar.style.marginRight = 'calc(var(--length) * -1)'
}
body{
overflow:hidden;
}
#sidebar{
--length:280px;
margin-right:calc(var(--length) * -1);
width:var(--length);
transition:all .2s linear;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
<button class="btn btn-primary" id='opener'>opener</button>
<div id = 'sidebar' class="d-flex d-md-none float-end flex-column flex-shrink-0 p-3 bg-light">
<div class="d-flex">
<button class="btn btn-primary" id='closer'>x</button>
<a href="/" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto link-dark text-decoration-none">
<svg class="bi pe-none me-2" width="40" height="32"><use xlink:href="#bootstrap"></use></svg>
<span class="fs-4">Sidebar</span>
</a>
</div>
<hr>
<ul class="nav nav-pills flex-column mb-auto">
<li class="nav-item">
<a href="#" class="nav-link active" aria-current="page">
<svg class="bi pe-none me-2" width="16" height="16"><use xlink:href="#home"></use></svg>
Home
</a>
</li>
<li>
<a href="#" class="nav-link link-dark">
<svg class="bi pe-none me-2" width="16" height="16"><use xlink:href="#speedometer2"></use></svg>
Dashboard
</a>
</li>
<li>
<a href="#" class="nav-link link-dark">
<svg class="bi pe-none me-2" width="16" height="16"><use xlink:href="#table"></use></svg>
Orders
</a>
</li>
<li>
<a href="#" class="nav-link link-dark">
<svg class="bi pe-none me-2" width="16" height="16"><use xlink:href="#grid"></use></svg>
Products
</a>
</li>
<li>
<a href="#" class="nav-link link-dark">
<svg class="bi pe-none me-2" width="16" height="16"><use xlink:href="#people-circle"></use></svg>
Customers
</a>
</li>
</ul>
<hr>
<div class="dropdown">
<a href="#" class="d-flex align-items-center link-dark text-decoration-none dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
<img src="https://github.com/mdo.png" alt="" width="32" height="32" class="rounded-circle me-2">
<strong>mdo</strong>
</a>
<ul class="dropdown-menu text-small shadow">
<li><a class="dropdown-item" href="#">New project...</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Profile</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Sign out</a></li>
</ul>
</div>
</div>

Two child components in parent div (flex row) always at the same height in angular 10

disclaimer: sorry if my answer is somwhere in stackoverflow... Did not find and starting being a little frustrating...
I'm working with Angular 10 and in my app.component.html, have this snippet :
<div class="chats">
<app-friend-chat *ngFor="let friend of friends" [inputFriend]="friend" (close)="closeChat($event)">
</app-friend-chat>
<app-friend-list (friend)="openChat($event)"></app-friend-list>
</div>
The component app-friend-chat is dynamic and at the started time of the site, there is no instances of it so only app-friend-list is display.
Here is the css of app.component.css :
app-friend-chat{
position: relative;
margin: 0 !important;
width: 50vh;
}
.chats{
position: absolute;
bottom: 0;
right: 5px;
z-index: 9999;
display: flex;
flex-direction: row;
}
The thing is app-friend-list's height is moving up to creation of a new app-chat-friend's instance.
When closing all app-chat-friend's instances, app-friend-list get height back to its first value.
I want my app-friend-list keep its height.
Here is app-friench-chat'html :
<div *ngIf="friend">
<div class="chatHead" fxLayout="row" fxLayoutGap="5px">
<p class="friend">{{ friend.name }}</p>
<span fxFlex="auto" (click)="minimize()"></span>
<p class="close" (click)="closeChat(friend.name)">X</p>
</div>
<div *ngIf="!mini">
<div id="messages-box">
<div *ngFor="let message of messages" class="message">
<div [ngClass]="classForParagraphe(message)" class="paragraphe"
[innerHTML]="sanitizer.bypassSecurityTrustHtml(message.message)">
</div>
<div *ngIf="user.name === message.user" class="trash">
<span class="far fa-trash-alt" (click)="deleteMessage(message)"></span>
</div>
</div>
</div>
<emoji-mart class="emoji-mart" *ngIf="isEmojiPickerVisible" (emojiSelect)="addEmoji($event)"></emoji-mart>
<div fxLayout="row" fxLayoutGap="15px">
<div class="container">
<input [(ngModel)]="message" type="text" #input (keyup)="enter($event)" />
<button (click)="isEmojiPickerVisible = !isEmojiPickerVisible;">😀</button>
</div>
<button (click)="sendMessage()">
<svg width="20px" height="20px" viewBox="0 0 24 24">
<path
d="M16.6915026,12.4744748 L3.50612381,13.2599618 C3.19218622,13.2599618 3.03521743,13.4170592 3.03521743,13.5741566 L1.15159189,20.0151496 C0.8376543,20.8006365 0.99,21.89 1.77946707,22.52 C2.41,22.99 3.50612381,23.1 4.13399899,22.8429026 L21.714504,14.0454487 C22.6563168,13.5741566 23.1272231,12.6315722 22.9702544,11.6889879 C22.8132856,11.0605983 22.3423792,10.4322088 21.714504,10.118014 L4.13399899,1.16346272 C3.34915502,0.9 2.40734225,1.00636533 1.77946707,1.4776575 C0.994623095,2.10604706 0.8376543,3.0486314 1.15159189,3.99121575 L3.03521743,10.4322088 C3.03521743,10.5893061 3.34915502,10.7464035 3.50612381,10.7464035 L16.6915026,11.5318905 C16.6915026,11.5318905 17.1624089,11.5318905 17.1624089,12.0031827 C17.1624089,12.4744748 16.6915026,12.4744748 16.6915026,12.4744748 Z">
</path>
</svg>
</button>
</div>
</div>
</div>
And css :
.chatHead {
background: rgb(210, 206, 206);
border-radius: 10px;
height: 5vh;
}
#messages-box {
height: 45vh;
background-color: white;
padding-left: 0;
overflow-y: scroll;
}
app-friend-list'html:
<div *ngIf="user && user.name !== undefined">
<h6 (click)="showList()">Discussions</h6>
<div class="list" *ngIf="show">
<ul *ngFor="let ami of user.amis">
<li (click)="addChat(ami)">{{ ami }}</li>
</ul>
</div>
</div>
app-friend-list'css:
h6{
padding: 10px;
border: solid 1px black;
height: 5.5vh;
}
ul {
padding-right: 20px;
}
li {
list-style: none;
cursor: pointer;
}
I give you only relevant code (according to me).
The other probleme I can't get ride of is that when clicking on chatHead of app-friend-chat for minimize, the component get same size of app-friend-list and so let empty space at the bottom which is very dirty (should get only size of head part)
Feel free to ask me any code I forgot to give you.

Display Div on top of Kendo Grid

I am using Kendo Grid to display Grid view of data. I have a column with button that, when clicked, shows a list of options on top of the page and left to the button.
I am not using Kendo Popup or context menu, but just using ng-template with structural directive logic.
What i look for?
What i get?
This is my Kendo grid column:
<div style="position: relative">
<kendo-grid>
...
<kendo-grid-column title="SAMPLE">
<ng-template kendoGridCellTemplate let-dataItem let-rowIndex="rowIndex">
<div class="context-dropdown-menu" *ngIf="showIndex === rowIndex && showDialog" style="position: absolute;">
<ul>
<li> <i class="fa fa-envelope"></i> Item2.1 </li>
<li> <i class="fa fa-envelope"></i> Item2.2 </li>
<li> <i class="fa fa-envelope"></i> Item2.3 </li>
</ul>
<div>
<button type="button" (click)="clicked(rowIndex)"> Click </button>
</ng-template>
</kendo-grid-column>
...
</kendo-grid>
</div>
Thanks in advance!
Replace below style in your stackblitz example it will work fine.
.context-dropdown-menu {
margin: 0 -10.75rem;
padding: 0px;
width: 170px;
z-index: 999999;
}
.context-dropdown-menu ul {
margin: 0px;
padding: 0px;
list-style: none;
background: #e4e4e4
}
.context-dropdown-menu ul li {
font-size: 13px;
padding: 7px 10px;
border-bottom: 1px solid #efefef;
color: #617189;
cursor: pointer;
}
.context-dropdown-menu ul li:hover {
background: #f5f5f5;
}

css selector for text inside a label and using a before and after

This my first question, so I hope that I ask it correctly.
Matthew Cain has created a great example of a fancy radio button using html and css which can be seen at https://www.templatemonster.com/blog/style-checkboxes-radio-buttons-css/. In it he uses this code:
body {
margin: 0;
padding: 0;
font-family: 'PT Sans', sans-serif;
font-size: 1.3em;
font-weight: bold;
color: #fff;
}
#first {
background-color: #4B4D65;
}
#second {
background-color: #FF8A66;
}
.section {
padding: 100px;
padding-left: 150px;
}
.section input[type="radio"],
.section input[type="checkbox"]{
display: none;
}
.container {
margin-bottom: 10px;
}
.container label {
position: relative;
}
/* Base styles for spans */
.container span::before,
.container span::after {
content: '';
position: absolute;
top: 0;
bottom: 0;
margin: auto;
}
/* Radio buttons */
.container span.radio:hover {
cursor: pointer;
}
.container span.radio::before {
left: -52px;
width: 45px;
height: 25px;
background-color: #A8AAC1;
border-radius: 50px;
}
.container span.radio::after {
left: -49px;
width: 17px;
height: 17px;
border-radius: 10px;
background-color: #6C788A;
transition: left .25s, background-color .25s;
}
input[type="radio"]:checked + label span.radio::after {
left: -27px;
background-color: #EBFF43;
}
<section id="first" class="section">
<div class="container">
<input type="radio" name="group1" id="radio-1">
<label for="radio-1"><span class="radio">Coffee</span></label>
</div>
<div class="container">
<input type="radio" name="group1" id="radio-2">
<label for="radio-2"><span class="radio">Tea</span></label>
</div>
<div class="container">
<input type="radio" name="group1" id="radio-3">
<label for="radio-3"><span class="radio">Cappuccino</span></label>
</div>
</section>
When I debug it in Chrome I see
<span class="radio"> == $0
::before
"Coffee"
::after
</span"
Here is my HTML:
<body class="my_PageBg" data-usepopupcontrols="no">
<div class="my_DesktopContainer my_temp_unselect" style="display: none;">
<div tabindex="1" class="container"
id="radio1" style="transform-origin: center 50%; left: 20px; top: 40px; width: 660px; height: 100px;
overflow: auto; position: absolute; z-index: 1; direction: ltr; transform: inherit; transform-style: preserve-3d;"
contenteditable="false">
<tbody>
<tr>
<td style="padding: 0px; white-space: nowrap;">
<label style="cursor: default;" onkeydown="onTreeLabelKeyDown(event)" for="radio10" name="radio1">
<input name="radio1" tabindex="1" id="radio10" onclick='OnResetDownChainControls("radio1",event)' type="radio" checked="" value="Value1"/>
Val1
</label>
</td>
</tr>
<tr>
<td style="padding: 0px; white-space: nowrap;">
<label style="cursor: default;" onkeydown="onTreeLabelKeyDown(event)" for="radio11" name="radio1">
<input name="radio1" tabindex="1" id="radio11" onclick='OnResetDownChainControls("radio1",event)' type="radio" value="Value2"/>
Val2
</label>
</td>
</tr>
<tr>
<td style="padding: 0px; white-space: nowrap;"><label style="cursor: default;" onkeydown="onTreeLabelKeyDown(event)" for="radio12" name="radio1">
<input name="radio1" tabindex="1" id="radio12" onclick='OnResetDownChainControls("radio1",event)' type="radio" value="Value3"/>
Val3
</label>
</td>
</tr>
</tbody>
I am trying to do the same to the Text "Val1", "Val2", "etc.
Please note that I can not change the html since it is coming from an external call.
What css selector can I use?
::after and ::before pseudo-elements do not apply to replaced-elements or void-elements.
But you can use a <span> to achieve the desired effect. Example:
.my-special-class:before {
content: '[before] ';
}
.my-special-class:after {
content: ' [after]';
}
.my-special-class:before,
.my-special-class:after {
color: red;
}
<span class="my-special-class">Val 1</span>
Obviously, you can name the class to whatever you want and change the selectors accordingly.
Note: if you want to use pseudo-elements as graphics (to give them size, position, background-image, border, background, etc – without actual content) you must still specify content: '' (empty string). Without setting content, the pseudo-element will not render, regardless of display, visibility or opacity.
Most CSS attributes that can be applied to a normal DOM element can be applied to pseudo-elements.
<label>s can have pseudo's, but that would mean the :before gets placed before the <input>, which is included in the <label>. If you want to place the :before after the <input> (which cannot have pseudo's), you have to wrap the text node in a <span>, as in the example.
Also note that, even though the spec defines pseudo elements officially with double colon notation (::pseudo-element), all browsers supporting double colon notation also support the legacy single colon notation, while a few legacy versions (IE pre v9, FF pre v1.5, Opera pre v7) only support the single colon notation. For this reason, most people use the single colon notation (which is, officially, wrong, but technically right, at least for now).

Content from <p> disappears when I return to the page

I'm facing a strange problem. I use a HTML template and it's actually only one page with a box in the middle. The content of the box can change and you navigate to the different version by some buttons at the top of the page.
I have added a paragraph in the landing view and when I move to another view and return back the text disappears.
I can see that the problem isn't that it doesn't show the text, the problem is that it completely disappears and only leaves:
<div id="comment2" class="one-half"></div>
I cannot figure out what causes it though.
Here's my HTML:
<div id="content_wrapper">
<div id="header"><span>Το <b>INTRO HALL</b> είναι το <b>TOP</b>!</span><div id="close"></div></div>
<div id="content">
<div class="scroll-pane">
<div class="content" id="content1">
<div id='subscribe_label'>Η ιστοσελίδα του γυμναστηρίου Intro Hall θα ανοίξει σε:</div>
<div id="counter"></div><div class="clear"></div>
<div class="form_title"><h1>Κέρδισε ένα δώρο!</h1></div>
<div class="column_cont">
<div id="comment2" class="one-half"><p>Συμπλήρωσε τη διπλανή φόρμα για να μπεις στο Club Επικοινωνίας του Intro Hall και κέρδισε ένα δώρο. Απλά γράψε το όνομα και το email σου και κλίκαρε 'Στείλτε το δώρο μου!'.</p></div>
<!-- Begin MailChimp Signup Form -->
<div id="mc_embed_signup" class="one-half" style="float:right;">
<form action="http://topgreekgyms.us6.list-manage2.com/subscribe/post?u=d6acf8949532b107b7b21c9d0&id=e2131451dc" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
<div class="mc-field-group">
<input type="text" value="" name="FNAME" class="required" id="firstname" placeholder="Όνομα">
</div>
<div class="mc-field-group" style="margin-bottom:4px;">
<input type="email" value="" name="EMAIL" class="required email" id="primaryemail" placeholder="Email" style="float:right;">
</div>
<div id="mce-responses" class="clear">
<div class="response" id="mce-error-response" style="display:none"></div>
<div class="response" id="mce-success-response" style="display:none"></div>
</div>
<div class="clear"><input type="submit" value="ΣΤΕΙΛΤΕ ΤΟ ΔΩΡΟ ΜΟΥ!" name="subscribe" id="mc-embedded-subscribe" class="button_link hover_fade large_button red"></div>
</form>
</div>
<!--End mc_embed_signup-->
</div>
</div>
And here's the CSS
#content_wrapper {
position:absolute;
width:506px;
height:506px;
z-index: 1000;
top:0;
left:0;
/* Fallback for web browsers that doesn't support RGBa */
background: rgb(62, 62, 62);
/* RGBa with 0.6 opacity */
background: rgba(0, 0, 0, 0.52);
}
#header {
width:506px;
height:47px;
background: #161616;
}
#header span {
display:block;
margin:auto;
height: 100%;
line-height: 47px;
width:447px;
color: #ffffff;
padding: 0px 29px 0 29px;
background: #ac0003;
text-align:center;
font-family: arial;
font-size: 23px;
text-transform: none;
word-spacing: 5px;
}
#content {
width: 502px;
height: 306px;
border: 2px solid #161616;
border-width: 0 2px 0 2px;
margin-top:-15px;
padding-top:15px;
}
.content {
display:none;
width: 458px;
}
#close {
position: absolute;
top:11px;
right:12px;
background: transparent url(../img/close.png) no-repeat;
width:25px;
height: 25px;
cursor: pointer;
display:none;
}
.column_cont {
margin: 0 -15px 0 0px;
clear:both;
}
.clear {clear:both;}
#comment2 {
color: #fff;
display:block;
font-size: 16px;
text-align: justify;
line-height: 20px;
margin-bottom:10px;
}
.one-half, .one-third, .two-third, .one-fourth, .three-fourth {
margin:0 5px 0 15px;
float:left;
}
.one-half {
width:206px;
}
Also, here's a link to the website.
Thanks in advance for any help or opinions!
In your big_countdown.js file, there is a listener on the close button which contains document.getElementById('comment2').innerHTML = ""; :
$("#close").click(function() {
$('.content').each(
function() {
$(this).fadeOut('fast');
});
$('#content1').stop().fadeIn('fast');
$("#close").css('display','none');
$('#dots div').each(
function() {
$(this).removeClass('dot_active');
});
$("#dot1").addClass('dot_active');
window.setTimeout(function() {
api.reinitialise();
},300);
// Remove this line below
document.getElementById("comment2").innerHTML="";
});
Removing this last line should solve the problem.
Using a good JavaScript debugger can help you figure this out really quickly next time. Firebug, an add-in to Fixfox is one of the best. To get to the same answer as albertxing you can do the following steps:
Load the page
Right click on the element that is disappearing and select "Inspect element with Firebug"
Your element will be highlighted in Firebug's HTML viewer
Right-click on on this element and select "break on element removal"
Toggle the buttons at the bottom of your web page to make the element disappear
Firebug will detect the change and take you immediately to the line of code that caused it to change.
Presto!

Resources