CSS Interview Questions: 40 Practice Questions with Answers and Code Examples

Here are 40 CSS interview questions with answers and code samples to help you better prepare for CSS interviews.

  1. How to center an element?
.element {
    
    
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

  1. How to make an element hidden?
.element {
    
    
  display: none;
}

  1. How to make an element invisible but take up space?
.element {
    
    
  visibility: hidden;
}

  1. How to clear the float?
.parent::after {
    
    
  content: "";
  display: table;
  clear: both;
}

  1. How to set the font?
.element {
    
    
  font-family: Arial, sans-serif;
}

  1. How to set font size?
.element {
    
    
  font-size: 16px;
}

  1. How to set font bold?
.element {
    
    
  font-weight: bold;
}

  1. How to set font color?
.element {
    
    
  color: #000000;
}

  1. How to set background color?
.element {
    
    
  background-color: #ffffff;
}

  1. How to set background image?
.element {
    
    
  background-image: url("image.jpg");
}

  1. How to set background repeat?
.element {
    
    
  background-repeat: repeat-x;
}

  1. How to set background size?
.element {
    
    
  background-size: cover;
}

  1. How to set the border?
.element {
    
    
  border: 1px solid #000000;
}

  1. How to set border radius?
.element {
    
    
  border-radius: 5px;
}

  1. How to set border shadow?
.element {
    
    
  box-shadow: 1px 1px 5px #000000;
}

  1. How to set the text to center?
.element {
    
    
  text-align: center;
}

  1. How to set text wrapping?
.element {
    
    
  word-wrap: break-word;
}

  1. How to style the list?
.element {
    
    
  list-style: none;
}

  1. How to set hyperlink style?
a {
    
    
  text-decoration: none;
  color: #000000;
}
a:hover {
    
    
  text-decoration: underline;
}

  1. How to set clear default style?
* {
    
    
  margin: 0;
  padding: 0;
}

  1. How to set browser compatibility?
.element {
    
    
  -webkit-box-shadow: 1px 1px 5px #000000;
  box-shadow: 1px 1px 5px #000000;
}

  1. How to set the center alignment of elements?
.parent {
    
    
  display: flex;
  justify-content: center;
  align-items: center;
}

  1. How to set text overflow ellipsis?
.element {
    
    
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

  1. How to set element positioning?
.element {
    
    
  position: absolute;
  top: 0;
  left: 0;
}

  1. How to set element width?
.element {
    
    
  width: 100%;
}

  1. How to set element height?
.element {
    
    
  height: 100px;
}

  1. How to set element minimum width?
.element {
    
    
  min-width: 500px;
}

  1. How to set element minimum height?
.element {
    
    
  min-height: 200px;
}

  1. How to set element max width?
.element {
    
    
  max-width: 1000px;
}

  1. How to set element max height?
.element {
    
    
  max-height: 500px;
}

  1. How to set element transparency?
.element {
    
    
  opacity: 0.5;
}

  1. How to animate elements?
.element {
    
    
  animation: myanimation 1s infinite;
}
@keyframes myanimation {
    
    
  0% {
    
    
    transform: rotate(0deg);
  }
  100% {
    
    
    transform: rotate(360deg);
  }
}

  1. How to set element transition?
.element {
    
    
  transition: all 1s ease-in-out;
}

  1. How to set element rotation?
.element {
    
    
  transform: rotate(45deg);
}

  1. How to set element scaling?
.element {
    
    
  transform: scale(2);
}

  1. How to set element tilt?
.element {
    
    
  transform: skewX(30deg);
}

  1. How to set the element to move?
.element {
    
    
  transform: translateX(50px);
}

  1. How to set element hierarchy?
.element {
    
    
  z-index: 1;
}

  1. How to set element floating?
.element {
    
    
  float: left;
}

  1. How to set element fixed positioning?
.element {
    
    
  position: fixed;
  top: 0;
  left: 0;
}
}

Guess you like

Origin blog.csdn.net/qq_27244301/article/details/130645907