This question already has answers here:
Two divs side by side - Fluid display [duplicate]
(9 answers)
In CSS Flexbox, why are there no "justify-items" and "justify-self" properties?
(6 answers)
Closed 1 year ago.
Just a simple css question. Trying to move the price next to the "Quick Shop" text. Basically trying to mirror this design:
.quick_shop_container{
width:100%;
}
.quick_shop{
background-color:white;
display:inline-block;
}
.quick_shop_text{
float:left;
}
.product-item-price{
float:left;
}
<div class="quick_shop_container" data-price-wrapper="">
<button class="quick_shop">
<span class="quick_shop_text">Quick Shop</span>
<div data-price-wrapper="">
<div class="product-item-price price" data-product-price="">| £51.95</div>
</div>
</button>
</div>
How do I move it?
Although flexbox is always better for 1D design. You can make your div inline-block so items it is inline.
Target it using > div, since you do not have a class. And add float : right to it.
.quick_shop_container{
width:40%;
}
.quick_shop{
background-color:white;
width: 100%;
}
.quick_shop > div{
display:inline-block;
float:right;
}
.quick_shop_text{
float:left;
}
<div class="quick_shop_container" data-price-wrapper="">
<button class="quick_shop">
<span class="quick_shop_text">Quick Shop</span>
<div data-price-wrapper="">
<div class="product-item-price price" data-product-price="">| £51.95</div>
</div>
</button>
</div>
I am not sure if you are supposed to use float, because of Browser Compatibility etc.. but if not, I guess this would be the solution.
.quick_shop_container{
width:100%;
}
.quick_shop{
background-color:white;
display:inline-block;
display: flex;
}
<div class="quick_shop_container" data-price-wrapper="">
<button class="quick_shop">
<span class="quick_shop_text">Quick Shop</span>
<div data-price-wrapper="">
<div class="product-item-price price" data-product-price="">| £51.95</div>
</div>
</button>
</div>
Add display:flex to the .quick_shop class
https://jsfiddle.net/k7jr4cwv/
Until you style it differently, a <div> is always a block-level element.
This leads an unstyled <div> to occupy its own vertical space within the document flow, beneath what has gone before.
In this case, we want to override that standard behaviour - so we can tell the <div> elements to display as if they are inline elements:
div[data-price-wrapper],
div[data-product-price] {
display: inline;
}
Working Example:
div[data-price-wrapper],
div[data-product-price] {
display: inline;
}
<div class="quick_shop_container" data-price-wrapper="">
<button class="quick_shop">
<span class="quick_shop_text">Quick Shop</span>
<div data-price-wrapper="">
<div class="product-item-price price" data-product-price="">| £51.95</div>
</div>
</button>
</div>
You can do it using flexbox.
.quick_shop {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
width: 500px;
padding: 20px;
background-color: white;
border: 2px solid #ccc;
font-size: 30px;
font-family: sans-serif;
}
.product-item-price {
border-left: 2px solid #ccc;
padding-left: 20px;
}
<button class="quick_shop">
<span class="quick_shop_text">Quick Shop</span>
<span class="product-item-price price">£51.95</span>
</button>
Try this. This will give you the same design without using the "|" character insertion.
.quick_shop_container{
width:200px; // this is container width
}
.quick_shop{
background-color:white;
display:inline-block;
width: 100%;
padding: 0.5rem;
border: solid 0.15rem #ccc;
}
.quick_shop_text{
float:left;
font-weight: bold;
float: left;
}
.product-item-price-wrapper {
}
.product-item-price {
padding-left: 0.5rem;
border-left: solid 0.15rem #ccc;
}
.product-item-price{
float: right;
font-weight: bold;
}
<div class="quick_shop_container" data-price-wrapper="">
<button class="quick_shop">
<span class="quick_shop_text">Quick Shop</span>
<div data-price-wrapper="" class="product-item-price-wrapper">
<div class="product-item-price price" data-product-price="">£51.95</div>
</div>
</button>
</div>
Related
I am currently working on a forum project, and had some problems with the CSS styling.
I am trying to position text into a HTML button, I managed to position one part of the text correctly, but the other part can't be positioned as the first, even if the CSS and HTML code is the same.
I tried wrapping the elements in a div, and somehow, I never manage to get them displayed into the button, even with margin-bottom.
Here the HTML Code:
<button>
<div class="forum-list-header">
<div class="forum-list-border"><i class="fa-solid fa-laptop-code fa-2xl"></i></div>
<h2>Tech, Informatique et autres</h2>
</div>
<div class="forum-list-info">
<h3>5.1k</h3><h3>50.3k</h3>
<p>Posts</p><p>Messages</p>
</div>
</button>
Here is the CSS code:
.forum-container { /* This is wrapped around the button elements */
position:absolute;
left:18%;
margin-top:42em;
font-family: Poppins-SemiBold, FontAwesome;
}
.forum-list-container { /* This is wrapped around the button elements */
margin-top:3em;
}
.forum-list button {
background-color: #172129;
border: 2px solid #212e38;
border-radius: 10px;
padding: 10px 40px;
width:80em;
height: 10em;
font-family: Poppins-SemiBold, FontAwesome;
color:white;
margin-right: 1em;
display:block;
margin-bottom: 2em;
}
.forum-list-header { /* Text aligned left, perfectly placed, won't work with the other text */
display:flex;
align-items:center;
}
.forum-list h2 {
margin-left:2em;
}
.forum-list .forum-list.btn {
margin-bottom:2em;
}
.forum-list-info {
/* Here should be the code to position it. */
}
.forum-list-info {
display: flex;
align-items: center;
justify-content: space-around;
}
//add this style to your css
<button>
<div class="forum-list-header">
<div class="forum-list-border"><i class="fa-solid fa-laptop-code fa-2xl"></i></div>
<h2>Tech, Informatique et autres</h2>
</div>
<div class="forum-list-info">
<div>
<h3>5.1k</h3>
<p>Posts</p>
</div>
<div>
<h3>50.3k</h3>
<p>Messages</p>
</div>
</div>
</button>
//and replace this html code. you can get what you want.
Should make each of those its own div, then style that div.
<button>
<div class="forum-list-header">
<div class="forum-list-border"><i class="fa-solid fa-laptop-code fa-2xl"></i></div>
<h2>Tech, Informatique et autres</h2>
</div>
<div class="forum-list-info">
<div><h3>5.1k</h3><p>Posts</p></div>
<div><h3>50.3k</h3><p>Messages</p></div>
</div>
</button>
Fix for this:
I edited my CSS classes to:
.forum-list-info {
grid-column-start: 2;
grid-column-end: 3;
margin-left: 17em;
}
.forum-list-info-numbers {
display:flex;
align-items:center;
}
.forum-list-info-text {
display:flex;
align-items:center;
}
.forum-list-info-numbers h3 {
margin-right:6.3em;
font-size:1.2em;
}
.forum-list-info-text p {
margin-right:5em;
font-size:1.2em;
color:#a6afb6;
}
And my HTML:
<button>
<div class="forum-list-header">
<div class="forum-list-border"><i class="fa-solid fa-rocket fa-2xl"></i></div>
<h2>Account Boost</h2>
</div>
<div class="forum-list-info">
<div class="forum-list-info-numbers"><h3>5.1k</h3><h3>50.3k</h3></div>
<div class="forum-list-info-text"><p>Posts</p><p>Messages</p></div>
</div>
</button>
I am wondering how can I make some buttons to stack vertically and not horizontally in css.
So, the html would be like:
<button>Test<button>
<button>Test<button>
<button>Test<button>
And those buttons will by default stack horizontally, what I want is to make them stack vertically (so everyone's on top of the next button).
Define the buttons as block-level elements. Also, note the use of the correct closing tag (</button>):
button {
display: block;
}
<button>Test</button>
<button>Test</button>
<button>Test</button>
<buttons> are inline-block elements by default. You can change that by styling the display to block instead:
button {
display: block;
}
<button>Test</button>
<button>Test</button>
<button>Test</button>
as they have explained above, buttons element come with inline display property by default. you need to make display: block; to achieve your desired result:
p{
font-family: arial;
font-weight: bold;
}
.button{
background-color: #2a609a;
width: 130px;
height: 60px;
color: white;
outline: none;
font-size: 16px;
border: none;
cursor: pointer;
}
.block-display button{
margin-bottom:5px;
display:block;
}
.button:hover{
background-color: #32CD32;
font-size: 20px;
transition: 0.5s;
}
<div class="default-display">
<p> buttons with defualt display: </p>
</br>
<button class="button">Button 1 </button>
<button class="button">Button 2 </button>
<button class="button">Button 3 </button>
</div>
</br>
<div class="block-display">
<p> buttons with block display: </p>
</br>
<button class="button">Button 1 </button>
<button class="button">Button 2 </button>
<button class="button">Button 3 </button>
</div>
You can do this with your css
button {
display: block;
}
I'm making a menu selection bar, and I'm running into a problem when I mouse over. The icon's corners should all be curved, but only the left hand side ones are.
Here's a demo of the code: https://jsfiddle.net/gfqgcwq5/
From what I can tell, it seems like inline-block is the culprit here:
.wrapper{
display:inline-block;
margin:10px;
}
I just don't know how to accomplish the inline array without it. I'm not great at css, so if someone could lend me a hand, I'd appreciate it.
try this one:
.icon{
border-radius:8px;
padding-top:15px;
padding-bottom:5px;
transition:.1s;
font-size:60px;
display: inline-table;
}
.icon:hover{
cursor:pointer;
background-color: #00B1EB;
color:#fff;
}
span#picture > span {
padding-right:9px;
padding-left:10px;
padding-top:7px;
padding-bottom:10px;
}
.text{
text-align:center;
}
.wrapper{
display:inline-block;margin:10px;
}
DEMO HERE
Used to this
Define your .icon display inline-block
as like this
.icon{display:inline-block;line-height:60px;}
or you can used to
.icon{display:block;}
Demo
Remember that the border-radius is a property (in this case) of the .icon class, if you use the inspector you will see that the wrapper has the proper size and shapewraper
So as the other says the issue is on the display of the .icon class, If your idea is to have more than one .icon elements inside of the wrapper and inline, you should use display: inline-block;, if your call is to have just one per wrapper use display: block;.
Hope this helps you.
You gotta give icon block display: inline-block property in order to work !!
.icon {
border-radius: 8px;
padding: 15px;
padding-bottom: 5px;
transition: .5s all ease;
font-size: 60px;
display: inline-block;
}
.icon:hover {
cursor: pointer;
background-color: #00B1EB;
color: #fff;
}
span#picture > span {
padding-right: 9px;
padding-left: 10px;
padding-top: 7px;
padding-bottom: 10px;
}
.text {
text-align: center;
}
.wrapper {
display: inline-block;
margin: 10px;
}
<link href="https://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="wrapper">
<span id="picture" class="icon"><span class="glyphicon glyphicon-picture"></span></span>
<div class="text">PICTURES</div>
</div>
<div class="wrapper">
<span id="picture" class="icon"><span class="glyphicon glyphicon-picture"></span></span>
<div class="text">PICTURES</div>
</div>
<div class="wrapper">
<span id="picture" class="icon"><span class="glyphicon glyphicon-picture"></span></span>
<div class="text">PICTURES</div>
</div>
<div class="wrapper">
<span id="picture" class="icon"><span class="glyphicon glyphicon-picture"></span></span>
<div class="text">PICTURES</div>
</div>
Apply padding for the text div to allow the entire curve to visible.
.text{
text-align:center;
padding:0px 7px;
}
DEMO
I have this page http://myrender.altervista.org/show2.html
I moved the 5 buttons to the right corner with the float:right instruction and then the hover in those buttons stopped to work suddently (before the float:right it worked).
There is the HTML:
<div class="container">
<div class="imgcontainer">
<div class="latest">Ultimi Caricamenti</div>
<img class="imgslide" src="" />
</div>
<div class="buttondiv">
<div class="button" onclick="change(0); clearInterval(t);" id="p0"></div>
<div class="button" onclick="change(1); clearInterval(t);" id="p1"></div>
<div class="button" onclick="change(2); clearInterval(t);" id="p2"></div>
<div class="button" onclick="change(3); clearInterval(t);" id="p3"></div>
<div class="button" onclick="change(4); clearInterval(t);" id="p4"></div>
</div>
</div>
and there are the CSS classes (only the needed):
.button
{
display:inline-block;
height:10px;
width:10px;
background:#eee;
border-radius:50%;
cursor: pointer;
opacity: 0.6;
}
.button:hover
{
opacity:1.0;
}
.buttondiv
{
margin-top: -17px;
padding-right: 5px;
float:right;
}
.buttonactive
{
background:#1390cd;
opacity:0.8;
}
.container
{
width:592px;
height:183px;
}
Thanks in advance :D
Just add position: relative; to .buttondiv or to .button
I have a collection of divs as rows that can be variable width as they are inside a resizable container. The div contains text that I want to have a hanging indent. This works fine except in this example the first line is pushed underneath the red label when the width is too low.
When .wrapper is 450px everything is displayed properly. When it's 250px you can see how things break. I always want the longtextthatwraps span to be on the same line as the red label.
Here's a live example/fiddle and the source is as follows:
HMTL (there is no whitespace between .prefix and .part but for readability...):
<div class="wrapper">
<div class="padded excludes">
<div class="parts first">
<span class="prefix">Quisques: </span>
<span class="segment level-0">
<span class="part text">longtextthatwraps incorrectly (0000-0000)</span>
</span>
</div>
<div class="parts">
<span class="segment level-0">
<span class="part text">consectetur adipiscing (0000-0000)</span>
</span>
</div>
<div class="parts">
<span class="segment level-0">
<span class="part text">quisque non mauris sed:</span>
</span>
</div>
<div class="parts">
<span class="segment level-1">
<span class="part list-item">hendrerit (0000-0000)</span>
</span>
</div>
<div class="parts">
<span class="segment level-1">
<span class="part list-item">non mauris sed (0000-0000)</span>
</span>
</div>
<div class="parts">
<span class="segment level-1">
<span class="part list-item">lorem ipsum dolor (0000-0000)</span>
</span>
</div>
</div>
</div>
CSS:
.wrapper {
width: 250px;
background: #c3dff5;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
}
.padded {
padding-left: 20px;
}
.parts {
padding-left: 80px;
}
.parts.first {
padding-left: 0;
}
.prefix {
color: #D12;
font-weight: bold;
min-width: 80px;
display: inline-block;
}
.level-0,.level-1 {
display: inline-block;
padding-left: 5px;
text-indent: -5px;
outline: 1px dotted #f0f;
}
.level-1 {
padding-left: 20px;
}
Help appreciated
Hmmm, I believe I have a CSS solution to your problem, though I'm sure there are other ways out there to get the behaviour you're looking for.
For .prefix, I gave the style:
.prefix {
display: table-cell;
}
And then I added another definition:
.parts.first .level-0 {
display:table-cell;
}
I hope this is what you're looking for! Here's the updated JSFiddle to show you what it results in. If this isn't your objective, please let me know and I'll be happy to help you further!
What if you remove the first class, move the span.prefix out of div.parts and add a position: absolute to it?
JsFiddle
Update (css only)
For a css-only solution remove the first class, give a position: absolute to span.prefix and specify left position, for example left: 25px. This seems to work in IE7, too.
Updated JsFiddle
Use position:absolute; and margin-left.
.first > .prefix{
position: absolute;
left:10px;
}
.first > .level-0{
margin-left:80px;
}
Lines 17-24 of this fiddle
I created a simplified version that will float each section, one to right and section to left and gives them a percent unit. Try to add your indent levels.
<div class="wrapper">
<div class="left">
<span class="red">Quisques: </span>
</div>
<div class="right">
<span class="level">consectetur adipiscing (0000-0000)</span>
<span class="level">quisque non mauris sed:</span>
<span class="level">consectetur adipiscing (0000-0000)</span>
</div>
</div>
CSS
.wrapper {
width: 250px;
background: #C3DFF5;
overflow: hidden;
padding: 12px;
}
.red {
color: red;
font-weight: bold;
}
.left {
float: left;
width: 30%;
}
.right {
float: right;
width: 70%;
}
.level {
display: block;
outline: 1px dotted #FF00FF;
}
Live demo http://jsbin.com/apaqop/1/
Please see this Demo
You have to add in CSS like
.wrapper {
width: auto;
background: #c3dff5;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
min-width:250px;
float:left;
}