I need to place a picture in a box on the right of the sidebar. div-box has certain size and border.
If i set the style to a picture, it enlarges to the size of the box, when i need it to be 100%.
If i set the style to a box, the box' borders expand to a sidebar.
Please advise.
.sidebar {
background: white;
height: 240px;
width: 240px;
float: left;
padding: 40px 46px 46px 46px;
}
.sidebar-button{
display: block;
height: 28px;
width: 240px;
border-top: #c8c8c8 1px solid;
border-right: #c8c8c8 1px solid;
border-left: #c8c8c8 1px solid;
padding-left: 20px;
text-decoration: none;
font-size: 15px;
color: gray;
padding-top: 12px;
}
.auto {
border-bottom: #c8c8c8 1px solid;
}
.sidebar-button:hover{
background-color: #f9f9f9;
color: black;
padding-left: 40px;
width: 220px;
}
.bike-picture {
border: #c8c8c8 1px solid;
margin: 40px 46px 46px 26px;
width: auto;
height: 400px;
padding-top: 40px;
text-align: center;
}
<div class="sidebar">
<a class="sidebar-button" href="#">Ноутбуки</a>
<a class="sidebar-button" href="#">Планшеты</a>
<a class="sidebar-button" href="#">Телефоны</a>
<a class="sidebar-button" href="#">Телевизоры</a>
<a class="sidebar-button" href="#">Бытовая техника</a>
<a class="sidebar-button auto" href="#">Автотовары</a>
</div>
<div class="bike-picture">
<img src="img/bike.png" alt="Bike">
</div>
enter image description here
check this one:
.container{
display: -webkit-flex;
display: flex;
-webkit-flex-flow: row nowrap; /* Safari 6.1+ */
flex-flow: row nowrap;
-webkit-align-items: flex-start; /* Safari 7.0+ */
align-items: flex-start;
padding: 40px 0 46px 0;
background-color: white;
}
.sidebar {
height: 240px;
flex-basis: 240px;
padding: 0 46px 0 46px;
}
.sidebar-button{
display: block;
height: 28px;
width: 240px;
border-top: #c8c8c8 1px solid;
border-right: #c8c8c8 1px solid;
border-left: #c8c8c8 1px solid;
padding-left: 20px;
text-decoration: none;
font-size: 15px;
color: gray;
padding-top: 12px;
}
.auto {
border-bottom: #c8c8c8 1px solid;
}
.sidebar-button:hover{
background-color: #f9f9f9;
color: black;
padding-left: 40px;
width: 220px;
}
.bike-picture {
border: #c8c8c8 1px solid;
flex-grow: 1;
text-align: center;
}
.bike-picture img{
max-width: 100%;
}
<div class="container">
<div class="sidebar">
<a class="sidebar-button" href="#">Ноутбуки</a>
<a class="sidebar-button" href="#">Планшеты</a>
<a class="sidebar-button" href="#">Телефоны</a>
<a class="sidebar-button" href="#">Телевизоры</a>
<a class="sidebar-button" href="#">Бытовая техника</a>
<a class="sidebar-button auto" href="#">Автотовары</a>
</div>
<div class="bike-picture">
<img src="http://s12.postimg.org/fpyql332l/felt_bicycles_q26_194648_1.jpg" alt="Bike">
</div>
</div>
Related
I'm trying to make something apppear from the right side in a div when I'm click on it.
It's a Div (dish) that have 2 Div in it (infoDish) and (validation).
infoDish have a width of 100%, validation have a width of 20% but is hidden unless I click on Dish.
I can make validation appear and disappear but the thing is it's instantaneus and I want to create an animation that take 1 or 2 seconds to make it appear from the right side (like you open the window from the right to the left).
.plat {
border: 1px solid black;
height: 70px;
width: 95%;
display: flex;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
border-radius: 20px;
background-color: white;
margin-bottom: 20px;
margin-left: 3%;
cursor: pointer;
}
.plat:hover .divValid {
border: 1px solid purple;
background-color: #99E2D0;
border-radius: 0 20px 20px 0;
justify-content: center;
align-items: center;
height: 100%;
width: 20%;
}
.partRouge {
border: 1px solid red;
height: 100%;
width: 100%;
}
.divTitlePlat {
border: 1px solid orangered;
height: 50%;
width: 100%;
padding-left: 2%;
}
.divTitlePlat h3 {
font-size: 20px;
margin-top: 0;
}
.divInfoPlat {
border: 1px solid blue;
height: 50%;
width: 100%;
display: flex;
justify-content: space-between;
}
.divDescPlat {
border: 1px solid green;
height: 100%;
width: 80%;
padding-left: 2%;
}
.divPricePlat {
border: 1px solid yellow;
height: 100%;
width: 20%;
}/*# sourceMappingURL=menuresto.css.map */
<div class="plat">
<div class="partRouge">
<div class="divTitlePlat">
<h3>Tartare de poulpe acidulé</h3>
</div>
<div class="divInfoPlat">
<div class="divDescPlat">
<span>Aux zests d'orange</span>
</div>
<div class="divPricePlat">
<span class="price">25€</span>
</div>
</div>
</div>
<div class="divValid">
<!--<i class="fa-solid fa-circle-check"></i>-->
</div>
</div>
I don't know if I understood what you really want to do...
But if you want to add a little delay, not to change instantly you can add the CSS property transition in the class with the hover. You can even precise for each property you want a delay and the delay. To do this, you have to write:
transition: 1s;
To have more informations about this property, you can read:
https://www.w3schools.com/css/css3_transitions.asp
With your code, it's not perfect but if it's what you were searching for, the changement on the hover is now not instantly, but with a delay of 1 second.
.plat {
border: 1px solid black;
height: 70px;
width: 95%;
display: flex;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
border-radius: 20px;
background-color: white;
margin-bottom: 20px;
margin-left: 3%;
cursor: pointer;
}
.plat:hover .divValid {
border: 1px solid purple;
background-color: #99E2D0;
border-radius: 0 20px 20px 0;
justify-content: center;
align-items: center;
height: 100%;
width: 20%;
transition: 1s;
}
.partRouge {
border: 1px solid red;
height: 100%;
width: 100%;
}
.divTitlePlat {
border: 1px solid orangered;
height: 50%;
width: 100%;
padding-left: 2%;
}
.divTitlePlat h3 {
font-size: 20px;
margin-top: 0;
}
.divInfoPlat {
border: 1px solid blue;
height: 50%;
width: 100%;
display: flex;
justify-content: space-between;
}
.divDescPlat {
border: 1px solid green;
height: 100%;
width: 80%;
padding-left: 2%;
}
.divPricePlat {
border: 1px solid yellow;
height: 100%;
width: 20%;
}/*# sourceMappingURL=menuresto.css.map */
<div class="plat">
<div class="partRouge">
<div class="divTitlePlat">
<h3>Tartare de poulpe acidulé</h3>
</div>
<div class="divInfoPlat">
<div class="divDescPlat">
<span>Aux zests d'orange</span>
</div>
<div class="divPricePlat">
<span class="price">25€</span>
</div>
</div>
</div>
<div class="divValid">
<!--<i class="fa-solid fa-circle-check"></i>-->
</div>
</div>
The question is confusing but I just want to put the 'signIn' css selector inside the 'headerRightPanel' selector and have it span that width. That is grow and shrink within it. now headerRightPanel is sitting next to headerLeftPanel which has the Float: left property. and for some reason the sign in div is expanding the whole entirety of the header which i dont want.
how can I just keep sign in inside headerRightPanel and have it expand the whole section?
html{
height: 900px;
border: 2px solid black;
margin: 5px;
}
body{
height: 885px;
border: 2px solid black;
margin: 5px;
}
.MAINPAGE{
border: 2px solid black;
height: 870px;
margin: 5px;
}
.HEADER{
border: 2px solid black;
height: 175px;
margin: 5px;
}
.headerLeftPanel{
border: 2px solid black;
height: 160px;
margin: 5px;
float: left;
width: 75%;
}
.headerRightPanel{
border: 2px solid black;
height: 160px;
margin: 5px;
}
.signIn{
border: 2px solid black;
height: 30px;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="MAINPAGE">
<div class="HEADER">
<div class="headerLeftPanel">
</div>
<div class="headerRightPanel">
<div class="signIn">
</div>
</div>
</div>
</div>
</body>
</html>
Try below things
give .headerRightPanel float: right; position: relative:
set .signIn maxWidth: 100%;
I'd try to solve it with flex:
html {
height: 900px;
border: 2px solid black;
margin: 5px;
}
body {
height: 885px;
border: 2px solid black;
margin: 5px;
}
.MAINPAGE {
border: 2px solid black;
height: 870px;
margin: 5px;
}
.HEADER {
border: 2px solid black;
height: 175px;
margin: 5px;
/* All children shall flex */
display: flex;
}
.headerLeftPanel {
border: 2px solid black;
height: 160px;
margin: 5px;
width: 75%;
}
.headerRightPanel {
border: 2px solid black;
height: 160px;
margin: 5px;
/* This item shall fill remaining space */
flex-grow: 1;
}
.signIn {
border: 2px solid black;
height: 30px;
}
<div class="MAINPAGE">
<div class="HEADER">
<div class="headerLeftPanel">
</div>
<div class="headerRightPanel">
<div class="signIn">
</div>
</div>
</div>
</div>
Use display: grid; in your .HEADER with grid-template-column: 75% auto; - says first column (first child-element of .HEADER) is width of 75% (of its parent-element's width) and auto to set the second column (second child-element of .HEADER) fill the rest of parents element's width.
html{
height: 900px;
border: 2px solid black;
margin: 5px;
}
body{
height: 885px;
border: 2px solid black;
margin: 5px;
}
.MAINPAGE{
border: 2px solid black;
height: 870px;
margin: 5px;
}
.HEADER{
border: 2px solid black;
height: 175px;
display: grid;
grid-template-columns: 75% auto;
grid-gap: 5px;
margin: 5px;
}
.headerLeftPanel{
border: 2px solid black;
height: 160px;
margin: 5px;
}
.headerRightPanel{
border: 2px solid black;
margin: 5px;
}
.signIn{
border: 2px solid black;
height: 30px;
}
<div class="MAINPAGE">
<div class="HEADER">
<div class="headerLeftPanel">
</div>
<div class="headerRightPanel">
<div class="signIn">
</div>
</div>
</div>
</div>
I started learning HTML/CSS recently and I'm trying to design the first page of a site by using these 2! I want to have 3 parts including logo, search box and signup button (from right to left) in the header part but I have a problem in it. The signup part doesn't stay in a row which other parts are. What's the problem with my code?
Here's my code:
body {
background: #ffffff;
padding: 0;
margin: 0;
}
.Header {
height: 93px;
width: 100%;
display: flex;
flex-direction: row;
}
.Logo {
display: block;
background: url('images/logo.png') no-repeat right center;
height: 77px;
width: 319px;
float: right;
margin: auto;
}
.Search {
height: 93px;
width: 220px;
float: left;
border-right: 1px solid #d1d5dc;
border-left: 1px solid #d1d5dc;
}
.Search input[type=text] {
border: none;
direction: rtl;
font-family: Tahoma;
font-size: 16px;
background: url('images/srch.png') no-repeat right center;
padding: 5px 25px 5px 5px;
margin: 25px 10px 0 0;
}
.Sign_up input[type=button] {
float: left;
height: 93px;
width: 100px;
border-right: 1px solid #d1d5dc;
border-left: 1px solid #d1d5dc;
border-bottom: 8px solid #c00000;
direction: rtl;
font-family: Tahoma;
font-size: 16px;
background: url('images/sign_up.png') no-repeat right center;
}
<div class="Header">
<a href="." class="Logo">
</a>
<div class="Search">
<input type="text" placeholder="search" />
</div>
<div class="Sign_up">
<input type="button" id="SignUpButton" onclick="SignUpPage()" value="sign up" />
</div>
<div class="clear"></div>
</div>
Remove float: right and replace margin into margin-left from class .Logo.
body {
background: #ffffff;
padding: 0;
margin: 0;
}
.Header {
height: 93px;
width: 100%;
display: flex;
flex-direction: row;
}
.Logo {
display: block;
background: url('images/logo.png') no-repeat right center;
height: 77px;
width: 319px;
margin-left: auto;
text-align: center;
background: #d1e3e6;
}
.Search {
height: 93px;
width: 220px;
float: left;
border-right: 1px solid #d1d5dc;
border-left: 1px solid #d1d5dc;
}
.Search input[type=text] {
border: none;
direction: rtl;
font-family: Tahoma;
font-size: 16px;
background: url('images/srch.png') no-repeat right center;
padding: 5px 25px 5px 5px;
margin: 25px 10px 0 0;
}
.Sign_up input[type=button] {
float: left;
height: 93px;
width: 100px;
border-right: 1px solid #d1d5dc;
border-left: 1px solid #d1d5dc;
border-bottom: 8px solid #c00000;
direction: rtl;
font-family: Tahoma;
font-size: 16px;
background: url('images/sign_up.png') no-repeat right center;
}
<div class="Header">
<a href="." class="Logo">
All Set
</a>
<div class="Search">
<input type="text" placeholder="search" />
</div>
<div class="Sign_up">
<input type="button" id="SignUpButton" onclick="SignUpPage()" value="sign up" />
</div>
<div class="clear"></div>
</div>
Add
display: inline;
to each of their css
eg
.Search {
display: inline;
height: 93px;
width: 220px;
float: left;
border-right: 1px solid #d1d5dc;
border-left: 1px solid #d1d5dc;
}
.Search input[type=text] {
display: inline;
border: none;
direction: rtl;
font-family: Tahoma;
font-size: 16px;
background: url('images/srch.png') no-repeat right center;
padding: 5px 25px 5px 5px;
margin: 25px 10px 0 0;
}
.Sign_up input[type=button] {
display: inline;
float: left;
height: 93px;
width: 100px;
border-right: 1px solid #d1d5dc;
border-left: 1px solid #d1d5dc;
border-bottom: 8px solid #c00000;
direction: rtl;
font-family: Tahoma;
font-size: 16px;
background: url('images/sign_up.png') no-repeat right center;
}
<div class="Header">
<div>
<a href="." class="Logo">
Logo Goes Here
</a>
</div>
<div class="Search">
<input type="text" placeholder="search" />
</div>
<div class="Sign_up">
<input type="button" id="SignUpButton" onclick="SignUpPage()" value="sign up" />
</div>
</div>
Css
.header{
width: 100%;
div{
display: inline-block;
width: 33.3%;
background: yellow;
}
div:nth-child(1), div:nth-child(3){
background:red;
}
Your header class is a flex container and then you use floats for the flex items in the container. So you are mixing these two concepts, but in my experience it is better to keep it with one of them. Anything you want to achieve, you can do with flex OR with floats.
As flex is the more modern (and simple) approach, I would stick with that one. Here is a very good article about aligning items in a flex container:
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Aligning_Items_in_a_Flex_Container
Just remove the floating property because when you're using flexbox method to align the column no need to use float to align the column.
For further assistance comment for more information.
* {
box-sizing: border-box;
position: relative;
}
body {
background: #ffffff;
padding: 0;
margin: 0;
}
.Header {
height: 93px;
width: 100%;
display: flex;
flex-direction: row;
}
.Logo {
display: block;
background: url('https://via.placeholder.com/200') no-repeat right center;
height: 93px;
width: 300px;
margin-left: auto;
}
.Search {
height: 93px;
width: 220px;
border-right: 1px solid #d1d5dc;
border-left: 1px solid #d1d5dc;
}
.Search input[type=text] {
border: none;
direction: rtl;
font-family: Tahoma;
font-size: 16px;
background: url('images/srch.png') no-repeat right center;
padding: 5px 25px 5px 5px;
margin: 25px 10px 0 0;
}
.Sign_up input[type=button] {
height: 93px;
width: 100px;
border-right: 1px solid #d1d5dc;
border-left: 1px solid #d1d5dc;
border-bottom: 8px solid #c00000;
direction: rtl;
font-family: Tahoma;
font-size: 16px;
background: url('images/sign_up.png') no-repeat right center;
}
<div class="Header">
<div class="Search">
<input type="text" placeholder="search" />
</div>
<div class="Sign_up">
<input type="button" id="SignUpButton" onclick="SignUpPage()" value="sign up" />
</div>
<div class="clear"></div>
</div>
I've the below HTML Code in my document.
<div class="panel-body chat-box-main">
<div class="chat-box-left">Hello, Welcome!. You can ask me
questions on Compliance Policy ..</div>
<div class="chat-box-name-left">
<img src="compiler-bot-static.gif" alt="bootstrap Chat box user image"
class="img-circle"> - Bot
</div>
<hr class="hr-clas">
<div class="chat-box-right" id="chatbox">Hi</div>
<div class="chat-box-name-right">
<img src="smiley.jpg" alt="bootstrap Chat box user image"
class="img-circle">
</div>
<div class="chat-box-left">Hello</div>
<div class="chat-box-name-left">
<img src="compiler-bot-static.gif" alt="bootstrap Chat box user image"
class="img-circle">- Bot
</div>
</div>
And my CSS is as below.
.hr-clas {
border-top: 1px solid #A12EB3;
}
.chat-box-main {
height: 400px;
overflow-y: auto;
}
.chat-box-div {
border: 2px solid #A12EB3;
border-bottom: 2px solid #A12EB3;
}
.chat-box-head {
padding: 10px 15px;
border-bottom: 2px solid #A12EB3;
background-color: #B25AE5;
color: #fff;
text-align: center;
}
.chat-box-left {
width: 100%;
height: auto;
padding: 15px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
position: relative;
border: 1px solid #C5C5C5;
font-size: 12px;
border: 2px solid #73AD21;
border-radius: 25px;
}
.chat-box-left:after {
top: 100%;
left: 10%;
border: solid transparent;
content: " ";
position: absolute;
border-top-color: #C5C5C5;
border-width: 15px;
margin-left: -15px;
}
.chat-box-name-left {
margin-top: 30px;
margin-left: 60px;
text-align: left;
color: #049E64;
}
.chat-box-name-left img {
max-width: 40px;
border: 2px solid #049E64;
}
.chat-box-right {
width: 100%;
height: auto;
padding: 15px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
position: relative;
border: 1px solid #C5C5C5;
font-size: 12px;
}
.chat-box-right:after {
top: 100%;
right: 10%;
border: solid transparent;
content: " ";
position: absolute;
border-top-color: #C5C5C5;
border-width: 15px;
margin-left: -15px;
}
.chat-box-name-right {
color: #354EA0;
margin-top: 30px;
margin-right: 60px;
text-align: right;
}
.chat-box-name-right img {
max-width: 40px;
border: 2px solid #354EA0;
}
.chat-box-footer {
background-color: #D8D8D8;
padding: 10px;
}
Here my requirement is to automatically set the width of each box(div) as per the content entered and float them accordingly to left/right.
Currently my output is as below.
Here as seen in the above screenshot, though there is only one word in the div, it is taking the entire width. Please let me know on how can I limit this to the text width.
Thanks
try this https://plnkr.co/edit/KXF1jkOd7G9JB8j7DIGC
I have changed the div to span. Hope this helps !
<span class="chat-box-left">Hello, Welcome!. You can ask me
questions on Compliance Policy ..</span>
Are you looking some thing like this, Try this add display: inline-block; to div
.hr-clas {
border-top: 1px solid #A12EB3;
}
.chat-box-main {
height: 400px;
overflow-y: auto;
}
.chat-box-div {
border: 2px solid #A12EB3;
border-bottom: 2px solid #A12EB3;
}
.chat-box-head {
padding: 10px 15px;
border-bottom: 2px solid #A12EB3;
background-color: #B25AE5;
color: #fff;
text-align: center;
}
.chat-box-left {
width:auto;
height: auto;
padding: 35px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
position: relative;
border: 1px solid #C5C5C5;
font-size: 12px;
border: 2px solid #73AD21;
border-radius: 25px;
display: inline-block;
}
.chat-box-left:after {
top: auto;
left: 10%;
border: solid transparent;
content: " ";
position: absolute;
border-top-color: #C5C5C5;
border-width: 15px;
margin-left: -15px;
}
.chat-box-name-left {
margin-top: 30px;
margin-left: 60px;
text-align: left;
color: #049E64;
}
.chat-box-name-left img {
max-width: 40px;
border: 2px solid #049E64;
}
.chat-box-right {
width:auto;
height: auto;
padding: 35px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
position: relative;
border: 1px solid #C5C5C5;
font-size: 12px;
display: inline-block;
}
.chat-box-right:after {
top: 100%;
display: inline-block; right: 10%;
border: solid transparent;
content: " ";
position: absolute;
border-top-color: #C5C5C5;
border-width: 15px;
margin-left: -15px;
}
.chat-box-name-right {
color: #354EA0;
margin-top: 30px;
margin-right: 60px;
text-align: right;
}
.chat-box-name-right img {
max-width: 40px;
border: 2px solid #354EA0;
}
.chat-box-footer {
background-color: #D8D8D8;
padding: 10px;
}
<div class="panel-body chat-box-main">
<div class="chat-box-left">Hello, Welcome!. You can ask me
questions on Compliance Policy ..</div>
<div class="chat-box-name-left">
<img src="compiler-bot-static.gif" alt="bootstrap Chat box user image"
class="img-circle"> - Bot
</div>
<hr class="hr-clas">
<div class="chat-box-right" id="chatbox">Hi</div>
<div class="chat-box-name-right">
<img src="smiley.jpg" alt="bootstrap Chat box user image"
class="img-circle">
</div>
<div class="chat-box-left">Hello</div>
<div class="chat-box-name-left">
<img src="compiler-bot-static.gif" alt="bootstrap Chat box user image"
class="img-circle">- Bot
</div>
</div>
While scaling down in browser menu has broken - flows on next line. What is wrong in code? Div width changing while scaling though it hardcoded 198px.
Without borders all is ok, but I have to use borders.
#horizontal-multilevel-menu {
border-right: 1px solid #769510;
border-left: 1px solid #cde67b;
}
#horizontal-multilevel-menu {
margin: 0;
padding: 0;
background: #a0bf38;
min-height: 52px;
width: 100%;
list-style: none;
font-size: 18px;
margin-left: auto;
margin-right: auto;
width: 1000px;
}
#horizontal-multilevel-menu a {
display: block;
padding: 5px 10px;
text-decoration: none;
text-align: center;
padding: 15px 40px !important;
}
#horizontal-multilevel-menu div {
float: left;
border-left: 1px solid #769510;
border-right: 1px solid #cde67b;
width: 198px;
}
<div id="horizontal-multilevel-menu">
<div>1
</div>
<div>2
</div>
<div>3
</div>
<div>4
</div>
<div>5
</div>
</div>
May be you need box-sizing to correct this issue.
* {
box-sizing: border-box;
}
#horizontal-multilevel-menu {
border-right: 1px solid #769510;
border-left: 1px solid #cde67b;
}
#horizontal-multilevel-menu {
margin: 0;
padding: 0;
background: #a0bf38;
min-height: 52px;
width: 100%;
list-style: none;
font-size: 18px;
margin-left: auto;
margin-right: auto;
width: 1000px;
}
#horizontal-multilevel-menu a {
display: block;
padding: 5px 10px;
text-decoration: none;
text-align: center;
padding: 15px 40px !important;
}
#horizontal-multilevel-menu div {
float: left;
border-left: 1px solid #769510;
border-right: 1px solid #cde67b;
width: 199px;
}
<div id="horizontal-multilevel-menu">
<div>1
</div>
<div>2
</div>
<div>3
</div>
<div>4
</div>
<div>5
</div>
</div>