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
Related
I have a Text Messaging Mobile Site App that has the following divisions and CSS
.messageDisplay {
background-color: #ffffff;
position: absolute;
z-index: 99999;
height: 100%;
width: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
overflow-y: hidden;
overflow-x: hidden;
visibility: hidden;
display: flex;
flex-direction: column;
justify-content: space-between;
transform: translateY(100%);
}
.messageDisplayHeader {
display: flex;
padding-top: 0.5em;
padding-bottom: 0.5em;
padding-left: 1em;
padding-right: 1em;
align-items: center;
background-color: #ffffff;
position: relative;
box-shadow: rgba(0, 0, 0, 0.16) 0px 1px 4px;
}
.messageDisplayTextboxArea {
height: 3.5em;
position: relative;
box-shadow: rgb(0 0 0 / 16%) 0px -1px 4px;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
padding-left: 0.5em;
padding-right: 0.5em;
padding-top: 0.2em;
padding-bottom: 0.2em;
background-color: #000000;
}
.messageTextbox {
resize: none;
height: 2.5em;
width: calc(100% - 14%);
background-color: #fef3f1;
border: none;
border-radius: 100px;
padding-left: 1em;
padding-top: 0.5em;
padding-right: 1em;
color: #fc768a;
}
<div class="messageDisplay" id="messageDisplay">
<div class="messageDisplayHeader"></div>
<div class="messageDisplayBody" id="messageDisplayBody">
</div>
<div class="messageDisplayTextboxArea" id="messageDisplayTextboxArea">
<textarea id="messageTextbox" class="messageTextbox" maxlength="300" placeholder="Type a message"></textarea>
<div class="messageSendBtn" id="messageSendBtn">
<i data-feather="chevron-right"></i>
</div>
</div>
</div>
When using an IOS Device to focus in on the textarea the whole page shifts up.
When the textarea is focused out, the page stays shifted upwards.
I tried to solve this by doing the following:
var messageTextBoxEle = document.getElementById('messageTextbox');
messageTextBoxEle.onfocus = function(){
window.scrollTo(0, 0);
document.body.scrollTop = 0;
}
Right now it behaves as such
I also tried setting the page's margin-bottom:0; when the textarea is focused out but it doesnt seem to work.
Anyone have suggestions?
For a project, I'm now changing from non-semantic to semantic HTML, but I have encountered a problem with the figure tag.
When I'm nesting my <img> in <figure>, the picture becomes ridicously small, here you can see the before/after. However, I was told that this tag should not affect the flow of the document, so I don't know if it's normal...
In this case, I don't really know what to do, I tried to adjust the width on figure but it doesn't work.
Here is my code:
img {
max-width: 100%;
height: auto;
}
#accommodation-content {
display: flex;
flex-flow: row wrap;
}
#acccommodation-city {
flex-grow: 2;
background-color: #F2F2F2;
border: 1px solid #F2F2F2;
border-radius: 10px;
padding: 16px 0px px 16px;
margin-right: 16px;
margin-left: 16px;
}
#accommodation-nav {
display: flex;
flex-flow: row wrap;
}
#accommodation-nav>article {
flex-basis: 33%;
}
.accommodation-item {
background-color: white;
border-radius: 10px;
box-shadow: 10px 5px 5px #E0DDDD;
margin-right: 10px;
margin-left: 10px;
margin-bottom: 10px;
width: min-content;
max-width: 180px;
cursor: pointer;
}
.accommodation-item:hover {
background-color: #DEEBFF;
transform: scale(1.03);
}
.accommodation-picture {
border: 3px solid white;
border-radius: 10px 10px 0px 0px;
box-sizing: border-box;
width: 180px;
height: 100px;
object-fit: cover;
}
<section id="accommodation-content">
<article id="acccommodation-city">
<nav id="accommodation-nav">
<article class="accommodation-item">
<figure>
<img class="accommodation-picture" src="https://i.stack.imgur.com/Mbjwm.jpg">
</figure>
<h5>Auberge la Cannebière</h5>
<p>Night starting at <strong>25€</strong></p>
</article>
</nav>
</article>
</section>
You need to cancel the default margin of the figure.
A good CSS Reset would take case of this for you.
figure {
margin:0;
}
img {
max-width: 100%;
height: auto;
}
#accommodation-content {
display: flex;
flex-flow: row wrap;
}
#acccommodation-city {
flex-grow: 2;
background-color: #F2F2F2;
border: 1px solid #F2F2F2;
border-radius: 10px;
padding: 16px 0px px 16px;
margin-right: 16px;
margin-left: 16px;
}
#accommodation-nav {
display: flex;
flex-flow: row wrap;
}
#accommodation-nav>article {
flex-basis: 33%;
}
.accommodation-item {
background-color: white;
border-radius: 10px;
box-shadow: 10px 5px 5px #E0DDDD;
margin-right: 10px;
margin-left: 10px;
margin-bottom: 10px;
width: min-content;
max-width: 180px;
cursor: pointer;
}
.accommodation-item:hover {
background-color: #DEEBFF;
transform: scale(1.03);
}
.accommodation-picture {
border: 3px solid white;
border-radius: 10px 10px 0px 0px;
box-sizing: border-box;
width: 180px;
height: 100px;
object-fit: cover;
}
<section id="accommodation-content">
<article id="acccommodation-city">
<nav id="accommodation-nav">
<article class="accommodation-item">
<figure>
<img class="accommodation-picture" src="https://i.stack.imgur.com/Mbjwm.jpg"
alt="A picture of one of the hotel's room of Auberge la Cannebiere"
title="Hotel room of Auberge la Cannebiere">
</figure>
<h5>Auberge la Cannebière</h5>
<p>Night starting at <strong>25€</strong></p>
</article>
</nav>
</article>
</section>
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.
Any clue about how to create below kind of dashboard? I use angular fontawesome.
I can create simple play button like so:
<a class="btn btn-success" (click)="onPlay()">
<fa-icon [icon]="faPlayCircle" size="4x"></fa-icon>
</a>
But How to do this? I would like to know about how to give the depth on the background like so on the image?
I think you can reach great results only with CSS. Here is a small sample only using HTML and CSS.
.panel {
display: flex;
align-items: center;
padding-left: 20px;
width: 300px;
height: 90px;
background: #3D3D3D;
}
.container-play {
position: relative;
width: 1px;
height: 1px;
background: #f0f;
}
.holder-play {
position: absolute;
top: calc(50% - 37px);
width: 74px;
height: 74px;
border-radius: 50%;
background: linear-gradient(#333333, #686868);
box-shadow: inset 0px 0px 12px rgba(0,0,0,.4);
}
.play {
position: absolute;
top: calc(50% - 30px);
left: 7px;
display: flex;
justify-content: center;
align-items: center;
width: 60px;
height: 60px;
border-radius: 50%;
background: linear-gradient(#41825C, #1B4F2C);
box-shadow: 0px 3px 12px rgba(0,0,0,.6);
cursor: pointer;
}
.play i {
font-size: 26px;
color: #fff;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="panel">
<div class="container-play">
<div class="holder-play">
<div class="play"><i class="fa fa-play"></i></div>
</div>
</div>
</div>
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>