Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Div is sliding after hover using css

Tags:

html

css

I have created the box and when I hover on the box then that box sliding going to the right side that I don't want. I need when the user hovers on the box then display border without sliding.

Would you help me in this?

.wid-30{width: 30%;}
.bg{background-color: red;}
.wid-30:hover{border-left: 10px solid yellow;}
.padding{padding: 10px;}
<div class="wid-30 bg padding">
<h2>Lorem ipsum dolor sit amet</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis ultricies diam a dui auctor commodo. Proin nulla nibh, fermentum eu purus quis, hendrerit posuere arcu</p>
</div>
like image 760
Naren Verma Avatar asked Jun 06 '26 10:06

Naren Verma


2 Answers

You need to add border-left: 10px solid red; inside .bg

.wid-30 {
  width: 30%;
}

.bg {
  background-color: red;
  border-left: 10px solid red;
}

.wid-30:hover {
  border-left: 10px solid yellow;
}

.padding {
  padding: 10px;
}
<div class="wid-30 bg padding">
  <h2>Lorem ipsum dolor sit amet</h2>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis ultricies diam a dui auctor commodo. Proin nulla nibh, fermentum eu purus quis, hendrerit posuere arcu</p>
</div>
like image 131
Rohit Verma Avatar answered Jun 08 '26 00:06

Rohit Verma


You can simply set padding-left: 0 when the element is :hovered-over, so that it does not move. Here's an example:

.wid-30 {
  width: 30%;
}

.bg {
  background-color: red;
}

.wid-30:hover {
  border-left: 10px solid yellow;
  padding-left: 0;
}

.padding {
  padding: 10px;
}
<div class="wid-30 bg padding">
  <h2>Lorem ipsum dolor sit amet</h2>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis ultricies diam a dui auctor commodo. Proin nulla nibh, fermentum eu purus quis, hendrerit posuere arcu</p>
</div>
like image 21
Angelos Chalaris Avatar answered Jun 08 '26 01:06

Angelos Chalaris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!