How to set width of element to its absolute nested element? - html

I want the main div, .secondNavLinksInSmall, to be of width as of the .secondNavLinksDisplayInSmall element. How can I do it? Note that the last is an element with position: absolute. Also, I wish to do it without setting any fixed width to the code.
Here is the HTML:
<div class="secondNavLinksInSmall">
<button id="secondNavLinksButtonInSmall" class="secondNavLinksButtonInSmall" type="button">
<svg id="secondNavLinksButtonInSmallSVG" class="secondNavLinksButtonInSmall__svg" viewBox="0 0 213.333 213.333">
<polygon points="0,53.333 106.667,160 213.333,53.333"/>
</svg>
<span><?php echo $buttonTextInsmall; ?></span>
</button>
<div id="secondNavLinksDisplayInSmall" class="secondNavLinksDisplayInSmall">
<a class="secondNavLinkInSmall" href="/">דילים חדשים</a>
<a class="secondNavLinkInSmall" href="hotdeals.php">דילים חמים</a>
<a class="secondNavLinkInSmall" href="forum.php">פורום</a>
</div>
</div>
Here is the SCSS code:
.secondNavLinksInSmall {
margin-right: 10px;
position: relative;
height: 100%;
display: none;
background-color: transparent;
}
.secondNavLinksButtonInSmall {
cursor: pointer;
height: 100%;
width: 100%;
padding: 0 12px;
display: flex;
justify-content: center;
align-items: center;
background-color: transparent;
color: white;
font-size: 20px;
text-align: center;
white-space: nowrap;
&:hover {
background-color: map-get($webColors, 'main-dark');
}
&__svg {
height: 12px;
fill: white;
margin-left: 10px;
transition: transform .4s;
}
}
.secondNavLinksDisplayInSmall {
background-color: white;
z-index: 2;
display: none;
flex-direction: column;
position: absolute;
top: 48px;
left: 0;
width: min-content;
border: 1px solid black;
}
.secondNavLinkInSmall {
border-bottom: 1px solid map-get($webColors, 'main-dark');
white-space: nowrap;
text-align: center;
font-size: 20px;
text-decoration: none;
color: black;
padding: 5px;
&:last-child {
border-bottom: none;
}
&:hover {
background-color: map-get($webColors, 'dark-white');
}
}

The short answer is no, it can't be done using only CSS. If you want a parent element to inherit the dimensions of a child element that is position absolutely the only solution is using javascript.

Related

Why won't the scrolling container display in my popup window, but works outside of it?

I have a popup window (within the same page) which I'm attempting to put a container which scrolls horizontally into, yet it distorts the popup window and does not display anything other than the scrollbar. I'm honestly at a loss, can anyone help me here? I've looked around for solutions but I can't find anything that I can see applies to my problem.
If anyone can help, or point me in the right direction, I'd be really grateful. The scrollbar works perfectly fine when isolated, but inside the window shows like this:
Standalone:
My HTML (popup window with scrollbar inside)
<div id="formula-popup" class="popup-window">
<div>
<a onclick="closeFormulaWindow()" title="Close" class="close">X</a>
<span id="ftitle" class="title1"></span>
<form method="post" id="formulaform" name="edit">
<span>Current Formula</span>
<p id="current-formula" class="formula">Existing formula</p>
<input id="id-passer" type="hidden" name="formula-id" value="">
<!--sort out horizontal scrollbar from bookmarks here later-->
<input onclick="refreshWindow()" name="edit-formula" type="submit" value="Confirm">
</form>
<div class="h-scrollbar">
<section class="h-scrollbar-container">
<div class="outer-wrapper">
<div class="inner-wrapper">
<div class="pseudo-item"></div>
<div class="pseudo-item"></div>
<div class="pseudo-item"></div>
<div class="pseudo-item"></div>
<div class="pseudo-item"></div>
<div class="pseudo-item"></div>
</div>
</div>
<div class="pseudo-track"></div>
</section>
</div>
</div>
My CSS:
.scrollbar-container {
display: flex;
flex-direction: row;
}
.h-scrollbar {
display: flex;
max-width: 30vw;
padding: 0px 10px;
height: 20vh;
align-items: center;
justify-content: center;
overflow: hidden;
flex-shrink: 0;
}
.h-scrollbar-container {
width: 100%;
}
.outer-wrapper {
max-width: 100vw;
overflow-x: scroll;
position: relative;
scrollbar-color: #d5ac68 #f1db9d;
scrollbar-width: thin;
-ms-overflow-style: none;
}
.pseudo-track {
background-color: #f1db9d;
height: 2px;
width: 100%;
position: relative;
top: -3px;
z-index: -10;
}
.outer-wrapper::-webkit-scrollbar {
height: 5px;
}
.outer-wrapper::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 0px rgba(0, 0, 0, 0);
}
.outer-wrapper::-webkit-scrollbar-thumb {
height: 5px;
background-color: #d5ac68;
}
.outer-wrapper::-webkit-scrollbar-thumb:hover {
background-color: #f1db9d;
}
.outer-wrapper::-webkit-scrollbar:vertical {
display: none;
}
.inner-wrapper {
display: flex;
padding-bottom: 10px;
}
.pseudo-item {
height: 30px;
width: 80px;
margin-right: 15px;
flex-shrink: 0;
background-color: gray;
}
.pseudo-item:nth-of-type(2n) {
background-color: lightgray;
}
.popup-window {
position: fixed;
font-family: Arial, sans-serif;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(0, 0, 0, 0.8);
z-index: 9999;
display: none;
}
.popup-window div {
width: 40vw;
height: 30vw;
position: relative;
margin: 10% auto 30%;
border-radius: 10px;
background: #213B54;
padding-top: 2vh;
padding-left: 1vw;
padding-right: 1vw;
padding-bottom: 2vh;
display: flex;
flex-direction: column;
}
.close {
font: Arial, sans-serif;
background: #067A9F;
color: #B5E5E7;
line-height: 25px;
position: absolute;
right: -12px;
text-align: center;
top: -10px;
width: 24px;
text-decoration: none;
font-weight: bold;
border-radius: 12px;
box-shadow: 1px 1px 3px #000;
cursor: pointer;
}
.popup-window div .title1 {
font-family: Arial, sans-serif;
font-weight: normal;
font-size: 36px;
color: #EE6802;
align-self: center;
}
.popup-window form input[type=submit]:hover {
opacity: 0.8;
}
.popup-window form span {
color: #EE6802;
font-size: 22px;
}
.popup-window form {
display: flex;
flex-direction: column;
font-family: Arial, sans-serif;
}
.popup-window form span, input {
width: 100%;
}
.popup-window form input[type=submit] {
width: 20%;
background-color: #067A9F;
color: #213B54;
padding: 14px 0;
cursor: pointer;
border: none;
}
I found the solution, it was that I forgot to select an element inside the window properly and instead it was selecting all divs and so overriding the CSS properties.

How do I get rid of this phantom element in my button

The phantom whitespace
<button onClick={onDropdownClick} className="menu-trigger">
<img
className="google-profile-photo"
src={currentUser.photoURL}
alt="User Avatar"
/>
<span>
<ArrowDown />
</span>
</button>
I want the img tag and the span to be next to each other with no space in between. I cannot get rid of this whitespace in the middle. Does anyone know how?
.menu-trigger {
display: flex;
width:auto;
min-height: 5rem;
position: relative;
background: white;
border-radius: 0.3rem;
cursor: pointer;
display: flex;
justify-content: space-between;
align-items: center;
padding: 4px 6px;
box-shadow: 8px 16px 5rem #eeeeee;
vertical-align: middle;
transition: box-shadow 0.4s ease;
margin-top: 1rem;
border: none;
}
.google-profile-photo {
border-radius: 50%;
margin: 2%;
width: 50%;
height: 100%;
}
You'll need to give the image element flex: 1 so it can fill up that space. Here's a somewhat minimized example...
.menu-trigger {
display: flex;
min-height: 3rem;
position: relative;
background: white;
cursor: pointer;
align-items: center;
padding: 4px 6px;
border: 1px solid black;
width: auto;
}
.google-profile-photo {
margin: 2%;
border-radius: 50%;
flex: 1;
height: 100%;
}
<button class="menu-trigger">
<img
class="google-profile-photo"
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAgMAAAAOFJJnAAAADFBMVEXU3ej///8AAAATExOMrozEAAAAdElEQVR4XpXPsQ2DMBRF0StX4D1c4IYRmAJkeQKPwRL0NJGQp6OK0hG9L5wqRXKbf6RXfX4qrvhDCDtDXoVCWBAS4SlML8KlaTyJDa4K/9QZHPhqQT+r5Rt8g/tgu8FDyMAgJMBrK9zbLsRttneg5gMLu603mI0q2s7nekMAAAAASUVORK5CYII="
alt="User Avatar"
/>
<span>
↓
</span>
</button>
use this:
justify-content: center;
and this for your second question :
background-size: cover

How to make line between two circles which touching to the both circle?

I want to make a line between two circles, for that, I have used the below code by using pseudo-element CSS. I would like to make the line between these two circles responsive, now it's intersecting with circle in some other devices like mobile, etc. How to make it responsive or any other solution that does the same design? Please help.
.cart_header_tab {
display: flex;
margin-top: 35px;
}
.cart_header_tab > div {
text-align: center;
margin-right: 100px;
cursor: pointer;
}
.cart_header_tab h6 {
color:#02b5f9;
font-weight: 400;
}
.cart_header_tab div:last-child h6 {
color:#ccc
}
span.circle_one::after {
content: "";
width: 152px;
height: 1px;
background: #eee;
position: absolute;
top: 6px;
left: 14px;
}
.cart_header_tab span.circle_one {
border: 1px solid #2fe4ba;
}
.cart_header_tab span {
display: inline-block;
width: 16px;
height: 16px;
border: 1px solid #ccc;
border-radius: 100%;
position: relative;
}
<div class="cart_header_tab">
<div>
<span class="circle_one"></span>
<h6>Order Details</h6>
</div>
<div>
<span class="circle_two"></span>
<h6>Freight Options</h6>
</div>
</div>
You can start tweaking the code something like this:
Be aware that if you wanted to change the size or width of the circle you have to tweak the other property in the css, hope that is not an issue here.
#cart_header_tab {
position: relative;
display: inline-block;
}
#cart_header_tab::after {
content: "";
position: absolute;
width: 50%;
z-index: -1;
top: 20%;
left: 25%;
border: 1px solid gray;
/* line between circles */
}
#cart_header_tab div {
display: inline-block;
font-size: 12px;
text-align: center;
min-width: 150px;
}
#cart_header_tab span {
color: white;
background: white;
display: block;
height: 15px;
margin: 0 auto 10px;
padding-top: 20px;
width: 30px;
border-radius: 50%;
border: 1px solid #22A7F2;
}
<div id="cart_header_tab">
<div><span class="circle_one"></span>
<h6>Order Details</h6>
</div>
<div><span class="circle_two"></span>
<h6>Freight Options</h6>
</div>
</div>
Using flex i insert that line between circle as separator itself is a child of flex and hen using margin adjust that according to circles
.cart_header_tab {
display: flex;
margin-top: 35px;
}
.cart_header_tab>div {
text-align: center;
cursor: pointer;
}
.cart_header_tab h6 {
color: #02b5f9;
font-weight: 400;
}
.cart_header_tab div:last-child h6 {
color: #ccc
}
.cart_header_tab {
position: relative
}
.sep {
width: 100%;
height: 1px;
background: #eee;
margin: 9px -21px 0;
}
.cart_header_tab span.circle_one {
border: 1px solid #2fe4ba;
background: #fff;
z-index: 1;
}
.circle_two {
background: #fff;
z-index: 1;
}
.cart_header_tab span {
display: inline-block;
width: 16px;
height: 16px;
border: 1px solid #ccc;
border-radius: 100%;
position: relative;
}
<div class="cart_header_tab">
<div>
<span class="circle_one"></span>
<h6>Order Details</h6>
</div>
<div class="sep"></div>
<div>
<span class="circle_two"></span>
<h6>Freight Options</h6>
</div>
</div>

If i have an image within a button, and the button's width increases on hover, how do I keep the image's position fixed where it was initially?

When I hover over the button it changes as desired in terms of width, however the image is shifted towards the center. I want to keep it fixed on the left so that it doesn't shift over when the width of the button changes. Here is my code. I am building with React:
<div>
<button
className={
this.state.activecut === true
? "designstudiobuttonleftopactive"
: "designstudiobuttonlefttop"
}
onClick={this.cutActiveHandler}
>
<img src={shirtlogo} id="cutlogo" alt="" />
</button>
</div>
.designstudiobuttonlefttop {
width: 60px;
height: 60px;
margin-top: 150px;
display: block;
border: 1px solid #574904;
border-radius: 50%;
background-color: white;
color: #574904;
text-align: center;
margin-left: 50px;
}
.designstudiobuttonlefttop:hover {
background-color: #f2f2f2;
color: #574904 !important;
text-decoration: underline;
transition-delay: 100ms !important;
cursor: pointer !important;
width: 200px;
border-radius: 50px 50px 50px 50px;
}
#cutlogo {
width: 50px;
height: 50px;
padding-right: 5px;
}
.designstudiobuttonleftopactive {
color: #574904 !important;
border: none;
background-color: white;
text-align: center;
text-decoration: underline;
cursor: pointer;
margin-top: 100px;
display: block;
margin-left: 50px;
}
Try changing text-align: center; to text-align: left; (for both classes)
i am not familiar with react syntax but it can be achieved by putting button inside an additional div within same block.
yet there are many more ways to achieve it , also without using another div.
see an example
http://jsfiddle.net/wa2vht71/4/
Use float: left to keep it on the left side of the button.
.designstudiobuttonlefttop {
width: 60px;
height: 60px;
margin-top: 150px;
display: block;
border: 1px solid #574904;
border-radius: 50%;
background-color: white;
color: #574904;
text-align: center;
margin-left: 50px;
}
.designstudiobuttonlefttop:hover {
background-color: #f2f2f2;
color: #574904 !important;
text-decoration: underline;
transition-delay: 100ms !important;
cursor: pointer !important;
width: 200px;
border-radius: 50px 50px 50px 50px;
}
#cutlogo {
width: 50px;
height: 50px;
padding-right: 5px;
}
.designstudiobuttonleftopactive {
color: #574904 !important;
border: none;
background-color: white;
text-align: center;
text-decoration: underline;
cursor: pointer;
margin-top: 100px;
display: block;
margin-left: 50px;
}
<div>
<button
class="designstudiobuttonlefttop"
onClick={this.cutActiveHandler}
>
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT6vxI3cA6w8ocAr3KWNHdMmq5gkkhYSuacNYaFCrQxZmeBUo2m" id="cutlogo" alt="" width="40" height="40" style="float: left;"/>
</button>
</div>
Use flexbox, the following code sample keeps your image to the left regardless of your button width:
<div class="button">
<div class="imageContainer">
<img src="path/to/your/image" />
</div>
</div>
<style type="text/css">
.button {
display: flex;
justify-content: flex-start;
width: 100px;
}
.button:hover {
width: 200px;
}
.button .imageContainer {
height: 50px;
width: 50px;
align-self: center;
}
.imageContainer img {
height: auto;
width: 100%;
}
</style>

Place an object on top of border, aligned to the center

I basically want something like this:
The oval is a button called specific, its size depends on the text. The border belongs to a div called player. The button should always align to the center of the top border no matter what the sizes they are. Thanks.
#specific
{
display: inline-block;
padding: 5px 15px;
font-size: 15px;
cursor: pointer;
text-align: center;
text-decoration: none;
outline: none;
color: #fff;
border: none;
border-radius: 20px;
}
.player
{
width: 560px;
padding: 20px;
border-style: solid;
<?php echo $border.$border_color[0] ?>;
border-radius: 20px;
margin: 0;
text-align: center;
}
HTML code, if it is relevant:
<input type="button" id="specific" value="<?php echo $id; ?>" onclick='window.open("<?php echo $specific; ?>")'>
<div class="player">
<script type="text/javascript" src="<?php echo $url;?>"></script>
</div>
Put #specific inside the player div and position it absolutely.
Then it can be managed into place using position values and a transform.
body {
text-align: center;
}
#specific
{
display: inline-block;
padding: 5px 15px;
font-size: 15px;
cursor: pointer;
text-align: center;
text-decoration: none;
outline: none;
color: #fff;
border: none;
border-radius: 20px;
position: absolute;
top: 0;
left: 50%;
transform:translate(-50%, -50%);
background: lightblue;
border:inherit;
}
.player
{
width: 560px;
padding: 20px;
display: inline-block;
margin: 2em;
border-style: solid;
border-color:blue;
border-radius: 20px;
text-align: center;
position: relative;
}
<div class="player">
<div id="specific">Specific</div>
</div>
I would recommend to add position: relative to .player, and wrap your button with a div (let's call it .buttonWrap), which has the following css attached:
.buttonWrap {
position: absolute;
left: 0;
top: -20px; /* the number of pixels here should be calculated like (buttonHeight / 2) */
width: 100%;
text-align: center;
}
#specific
{
display: inline-block;
padding: 5px 15px;
font-size: 15px;
cursor: pointer;
text-align: center;
text-decoration: none;
outline: none;
color: #fff;
border: none;
border-radius: 20px;
}
.player
{
width: 560px;
padding: 20px;
margin: auto;
border-style: solid;
<?php echo $border.$border_color[0] ?>;
border-radius: 20px;
margin: 0;
text-align: center;
position: absolute;
}
.button{
width: 560px;
margin: auto;
text-align: center;
position: relative;
margin-bottom: -1em;
z-index: 10;
}
<div class="button">
<input type="button" id="specific" value="Play" onclick='window.open("<?php echo $specific; ?>")'>
</div>
<div class="player">
<script type="text/javascript" src="<?php echo $url;?>"></script>
</div>
here is the Demo
.container-lg {
border: 4px solid rgba(50, 150, 255, 1);
border-radius: 50px;
width: 400px;
height: 400px;
margin-top: 50px;
}
button.container-sm {
background-color: rgba(100, 175, 255, 1);
border: 2px solid rgba(50, 150, 255, 1);
border-radius: 40px;
width: 150px;
height: 40px;
display: block;
margin: auto;
margin-top: -22px;
}
<div class="container-lg">
<button class="container-sm"></button>
</div>