I'm trying to implement a simple three vertical dot menu, and I'm encountering some rather strange behavior. Even though they all have a determined height and width, the three dots render as non-square, seemingly depending on the grandparent container's dimensions. I've tried using px, rem, em, and percentages to size them, but the issue persists.
I've also tried laying the dots out by setting the parent element's width and height explicitly and making it flexbox, as well as removing all the padding and margin both on the parent and dots, but nothing seems to alleviate the issue. The code looks like this:
.grandparent {
display: flex;
width: 100%;
margin-bottom: 10px;
align-items: center;
}
.item1 {
height: 50px;
width: 50px;
margin-left: 15px;
height: 50px;
width: 50px;
position: relative;
}
.item1 img {
border-radius: 50%;
height: 50px;
}
.item2 {
flex: 1 1;
}
.title {
text-align: left;
margin: 0 0 5px 13px;
font-size: 20px;
font-weight: 400;
}
.subtitle {
text-align: left;
margin-left: 13px;
margin-top: -9px;
font-size: 13px;
color: #808080;
}
.parent {
margin-right: 11px;
padding: 5px 8px;
cursor: pointer;
}
.dot {
width: 6px;
height: 6px;
margin-bottom: 4px;
border-radius: 50%;
background-color: #808080;
}
.no-appearance {
appearance: none;
border: 0;
background: none;
}
<div class="grandparent" style="width: 375px; height: 50px">
<div class="item1"><img src="https://picsum.photos/50/50" /></div>
<div class="item2">
<div class="title">Example text</div>
<div class="subtitle">Example text</div>
</div>
<button class="parent no-appearance">
<div class="dot"></div>
<div class="dot"></div>
<div class="dot"></div>
</button>
</div>
Edit: I added some more code to the snippet to try to reproduce the issue, but unfortunately it does not seem to be reproducible even though it is consistently reproducible in my development environment.
Here's an example of how this renders in Chrome 88.0 when the grandparent is 410x50:
... and here's what it looks like when the grandparent is 375 x 50:
Any idea what might be at play here?
What about html-entitie ⋮?
https://www.w3schools.com/charsets/ref_html_entities_v.asp
.target {
position: relative;
width: 100%;
margin-bottom: 10px;
}
.target::after {
position: absolute;
right: 0;
top: 0;
font-size: 2em;
color: #808080;
content: '\0022EE';
}
.target:hover::after{
cursor: pointer;
}
<div class="target"></div>
Related
I am trying to put text into nested div's and it works for some but not for all. When I try to put the text where its not working it forces the other div elements down a line.I had a previous version of this where I nested them the same way and didn't have this problem. Any idea where I went wrong?
/* my css for the divs */
div.mycard{
background-color: beige;
width: 400px;
height: 35px;
margin-left: 75%;
margin-bottom: 2px;
}
div.cardcost{
background-color: blue;
width: 30px;
height: 35px;
}
div.hscardepic{
background-color: rgb(233, 27, 233);
height: 35px;
width: 5px;
}
div.cardamount{
background-color: black;
width: 30px;
height: 35px;
z-index: 11;
margin-left: 8000%;
}
p.cardname{
z-index: 12;
font-weight: bolder;
margin: 0;
}
<!-- These divs are nested in another div with display: inline-block to put them next to text-->
<div class="mycard">
<div class="cardcost">
<div class="hscardepic">
<div class="cardamount">
<p style="margin-left: 5px;color: white;">×2</p>
</div>
</div>
</div>
</div>
The major issue that's hiding your paragraph is caused by margin-left: 8000%; in div.cardamount which is pushing the div outside the viewport
There is another issue with class cardname is not set on the p element so your CSS rules are not applied
here's a fixed version https://jsfiddle.net/xr271aen/1/
Simple use flex method...
And I slightly changed your html code :)
/* my css for the divs */
div.mycard{
background-color: beige;
width: 100%;
height: 35px;
margin-left: 0%;
margin-bottom: 2px;
display: flex;
}
div.cardcost{
background-color: blue;
width: 30%;
height: 35px;
}
div.hscardepic{
background-color: rgb(233, 27, 233);
height: 35px;
width: 20%;
}
div.cardamount{
background-color: black;
width: 20%;
height: 35px;
z-index: 11;
margin-left: 0;
}
p.cardname{
z-index: 12;
font-weight: bolder;
margin: 0;
}
<!-- These divs are nested in another div with display: inline-block to put them next to text-->
<div class="mycard">
<div class="cardcost">
<p style="margin-left: 5px;color: white;">×1</p>
</div>
<div class="hscardepic">
<p style="margin-left: 5px;color: white;">×2</p>
</div>
<div class="cardamount">
<p style="margin-left: 5px;color: white;">×3</p>
</div>
</div>
I'd like to make a message-alert box in my web app. I created the main style but I have problems on small screen sizes.
Here's the image for the regular 1366x768 computer screen:
And here is for a typical mobile device:
Problems:
The X button has tagled with the message.
The main message wrapper has fixed and wasn't expand when the message came out of the wrapper.
How to fix the two above problems? Do I have to follow another path? I use position: fixed; property-value to keep my message on top.
Here are my HTMl and CSS code:
HTML:
<div class="top-msg">
<div class="top-msg-ico">
!
</div>
<div class="top-msg-inner">
<p>Only letters and nubers are allowed for email. See security for more info.</p>
</div>
<div class="top-msg-close" style=" cursor: pointer;">✕</div>
</div>
CSS:
.top-msg {
width: 100%;
height: 55px;
position: fixed;
background-color: rgba(42,45,50,0.6);
color: rgba(250,251,255,0.95);
font-family: "Lato", sans-serif;
font-size: 18px;
}
.top-msg-close {
float: right;
padding-top: 17px;
padding-right: 30px;
//border: 1px solid white;
//height: 100%;
width: 3%;
}
.top-msg-inner {
top: 15px;
position: absolute;
display: inline-block;
padding-left: 10px;
width: 80%;
//border: 1px solid white;
}
.top-msg-ico {
min-width: 65px;
height: 100%;
background-color: #fff;
display: inline-block;
background-color: rgba(0,0,0,0.7);
text-align: center;
font-size: 45px;
}
FIDDLE:
https://jsfiddle.net/4oLvyajo/
UPDATE -SOLUTION!-
After some help from LGSon answer I manage to finish all the design, so I accepts his answer but the hole solution is in the fiddle below.
FIDDLE:
https://jsfiddle.net/4oLvyajo/4/
Images:
Here is a start for you
.top-msg {
width: 100%;
position: fixed;
background-color: rgba(42,45,50,0.6);
color: rgba(250,251,255,0.95);
font-family: "Lato", sans-serif;
font-size: 18px;
}
.top-msg-close {
float: left;
box-sizing: border-box;
padding-top: 17px;
padding-right: 30px;
width: 45px;
}
.top-msg-inner a {
text-decoration: none;
color: RGBA(0, 0, 0, 0.6);
font-weight: bold;
}
.top-msg-inner a:hover {
color: RGBA(0, 0, 0, 0.5);
}
.top-msg-inner {
float: left;
box-sizing: border-box;
padding: 0 10px;
width: calc(100% - 110px);
}
.top-msg-ico {
float: left;
width: 65px;
height: 57px;
background-color: #fff;
background-color: rgba(0,0,0,0.7);
text-align: center;
font-size: 45px;
}
<div class="top-msg">
<div class="top-msg-ico">
!
</div>
<div class="top-msg-inner">
<p>Only letters and nubers are allowed for email. See security for more info.</p>
</div>
<div class="top-msg-close" style="cursor: pointer;">✕</div>
</div>
replace the width: 80% with margin-right: 40px, and you'll have to play around with the top: 15px as well (at -11 I had it looking right, but you can play around with that)
Here is the updated Fiddle
If you want everything scalable you'll need a completely different approach. First of all, if you place a right floating element under a block element it will float right, but underneath it. You'll need to define the floating close button element first.
Anyway, here's the updated Fiddle
It needs some minor tweaks in the padding and margins, but I think this is very close to what you're looking for
I have a container that usually has a width of 400px. When the screen gets smaller, its width is reduced to 300px. These two values are static and don't change.
I have 3 buttons within this container. At the wider width, I'd like to have 2 side by side and the 3rd one on the line below. All of them are centered.
When the container is compressed, I'd like to have all the buttons stack on top of each other centered.
I can get it at the wide width but can't get it at the narrow width.
HTML:
<div id="varied-width">
<div class="pg-sp2 prompt-gate">Did you find what you were looking for?
<div class="pg-3-buttons">
<button class="prompt-gate-button" onclick="PromptGate_sp2(1)">Yes</button>
<button class="prompt-gate-button" onclick="PromptGate_sp2(0)">No, you suck</button>
</div>
<button class="prompt-gate-button" onclick="PromptGate_sp2(2)">No, I need help.</button>
</div>
</div>
CSS:
body {
width: 400px;
}
.prompt-gate {
margin-top: 25px;
margin-bottom: 15px;
background-color: #fefab1;
border: 1px solid #ffd532;
padding: 10px;
text-align: center;
}
.prompt-gate-button {
background-color: #0E80B4;
color: white;
font-size: 12px;
height: 30px;
width: 72px;
border: none;
margin: 15px 25px;
outline: none;
font-style: normal;
cursor: pointer;
}
.pg-3-buttons {
display: inline-block;
margin-top: 10px;
}
.pg-3-buttons .prompt-gate-button {
float: left;
}
.pg-sp2 button {
margin: 5px 15px;
width: 120px;
padding: 10px 0px;
}
.pg-sp2 > button {
}
.small-width {
width: 300px;
}
Fiddle: http://jsfiddle.net/je821vz9/10/
Used flex layout instead: http://jsfiddle.net/je821vz9/7/
Added this to .prompt-gate style and then cleaned up some of the conflicting HTML and CSS.
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
You could use a media query and have the viewport size decided on how to display the elements.
I added the following css to your body:
body {
max-width:400px;
min-width:300px;
}
We can then add a media query to adjust how the items are laid out:
#media (max-width: 300px) {
div.pg-3-buttons .prompt-gate-button {
display:block;
float:none;
}
}
See an updated version of your example and scale down the width of your browser to see the items pop in to place at 300px.
Somehow figured it out... removed floats and moved around the button HTML so that they were all in the same container.
http://jsfiddle.net/je821vz9/19/
<div id="varied-width">
<div class="pg-sp2 prompt-gate">Did you find what you were looking for?
<div class="pg-3-buttons">
<button class="prompt-gate-button" onclick="PromptGate_sp2(1)">Yes</button>
<button class="prompt-gate-button" onclick="PromptGate_sp2(0)">No, you suck</button>
<button class="prompt-gate-button" onclick="PromptGate_sp2(2)">No, I need help.</button>
</div>
</div>
</div>
<style>
body {
width: 400px;
}
.prompt-gate {
margin-top: 25px;
margin-bottom: 15px;
background-color: #fefab1;
border: 1px solid #ffd532;
padding: 10px;
text-align: center;
}
.prompt-gate-button {
background-color: #0E80B4;
color: white;
font-size: 12px;
height: 30px;
width: 72px;
border: none;
margin: 15px 25px;
outline: none;
font-style: normal;
cursor: pointer;
}
.pg-3-buttons {
margin-top: 10px;
}
.pg-sp2 button {
margin: 5px 15px;
width: 120px;
padding: 10px 0px;
}
</style>
With html (or css) is there a way to have a subscript and superscript in the same location? I tried this
<sup>16</sup><sub>16.00</sub>O
but this will make the superscript 16 to the left of the subscript 16.00, is there a way to make the subscript and superscript one on top of another?
Note that I am not using CSS3.
Note that I tried making this my CSS
.container {}
.sup {
position: relative;
top: 0.5em;
}
.sub {
position: relative;
top: 0.5em;
left: -0.5em;
}
with this as the html
<span class='sup'>3</span><span class='sub'>4</span>
which works but it depends on the length of the digits. This won't look right
<span class='sup'>16</span><span class='sub'>16.000</span>
since the superscript has 2 digits while the subscript has 6 digits. Is there a way to make them right aligned? I tried doing
.container {
text-align: right;
}
but that didn't work.
With a little bit of structuring using div's and floats I was able to replicate the image using <sub> and <sup> elements. My example fits all elements into a 100px by 100px square. If that box needs to be smaller or can be large then some minute adjustments will be needed obviously.
This is all CSS2 spec also, no CSS3 was used so no compatibility issues.
JSFiddle
HTML:
<div class="box">
<div class="superscripts">
<sup class="sup-left">16</sup>
<sup class="sup-right">8</sup>
</div>
<div class="element"><abbr>O</abbr><br /> Oxygen</div>
<div class="subscripts">
<sub class="sub-left">16.00</sub>
<sub class="sub-right">(6)</sub>
</div>
</div>
CSS:
.box {
width: 100px;
height: 100px;
border: 2px solid black;
}
.element {
text-align: center;
clear: both;
height: 60px;
}
.element abbr {
font-size: 28px;
font-weight: bold;
}
.superscripts,
.subscripts {
height: 18px;
}
.superscripts .sup-left {
float: left;
padding: 2px 0 0 2px;
}
.superscripts .sup-right {
text-align: right;
float: right;
padding: 2px 2px 0 0;
}
.subscripts .sub-left {
float: left;
padding: 4px 0 2px 2px;
}
.subscripts .sub-right {
text-align: right;
float: right;
padding: 4px 2px 2px 0;
}
I think it can be a little less complicated and more flexible by using absolute positioning and em instead of px. Here's a JSFiddle.
HTML:
<div class="container">
<div class="edge">
<span class="top left">16</span>
<span class="top right">8</span>
</div>
<div class="element">
<abbr>O</abbr>
<div>Oxygen<div>
</div>
<div class="edge">
<span class="bottom left">16.00</span>
<span class="bottom right">(6)</span>
</div>
</div>
CSS:
.container {
height: 7em;
width: 7em;
border: .2em solid black;
position: relative;
}
.element {
text-align: center;
margin-top: 1.5em;
}
abbr {
font-size: 2em;
font-weight: bold;
}
.edge span {
position: absolute;
padding: .4em;
}
.top { top: 0; }
.bottom { bottom: 0; }
.right { right: 0; }
.left { left: 0; }
I have the following structure:
<div class="wrap">
<div class="menu">
<div class="item">
Menu
<div class="submenu">
<div class="submenuitem">Submenu</div>
</div>
</div>
</div>
</div>
and so far the following CSS:
div.wrap {
background: #eee;
height: 80px;
}
div.menu {
margin-left: 50px;
background: #36e;
}
div.item {
background: #d00;
color: #fff;
line-height: 40px;
padding: 0px 20px;
font-size: 16px;
display: inline-block;
margin-left: 50px;
}
div.item:hover {
background: #b00;
}
div.submenu {
display: none;
background: #0b0;
height: 40px;
position: absolute;
right: 0%;
top: 50%;
min-width: 300px;
}
div.item:hover div.submenu {
display: inline-block;
}
div.submenuitem {
line-height: 40px;
padding: 0px 20px;
background: #b00;
color: #fff;
display: inline-block;
}
JSFiddle
The behaviour I'm after is that the width of submenuitem expands to fit its textual content, but that it can use at most the width of wrap for expanding. It should also be positioned directly under item unless the width of submenuitem will be larger than the distance from its original position to the right end of wrap. Thereafter it should expand to the left until it meets the left edge of wrap.
As you can see this succeeds perfectly when I can know the distance from submenuitem's original position to the right end of wrap by setting right: 0%; min-width: 300px; on submenuitem, but I want to do this in a way that doesn't require knowing that distance.
I have been trying to craft or find a solution to this for the past few days and have not managed to get any closer. Is it even possible with pure CSS to begin with?
Is this something you want? check this one nd let me know.
http://jsfiddle.net/zmcEC/9/
div.wrap {
width: 400px;
background: #eee;
position: relative;
height: 80px;
}
div.submenu {
display: none;
background: #0b0;
height: 40px;
position: absolute;
right: 0;
top: 40px;
left:0;
}